diff options
author | Lukasz Pawelczyk <l.pawelczyk@samsung.com> | 2019-05-10 13:46:22 +0200 |
---|---|---|
committer | Seung-Woo Kim <sw0312.kim@samsung.com> | 2019-07-05 15:20:26 +0900 |
commit | 8413c52116d57850c75e7ef04f4a37cab878cc6f (patch) | |
tree | e4dbf21aa544b7d4fa01dc1875c6ec0648a25325 /net | |
parent | 6cf88d59f6ba79dec0ab78d12ab2c95404204aec (diff) | |
download | linux-artik7-8413c52116d57850c75e7ef04f4a37cab878cc6f.tar.gz linux-artik7-8413c52116d57850c75e7ef04f4a37cab878cc6f.tar.bz2 linux-artik7-8413c52116d57850c75e7ef04f4a37cab878cc6f.zip |
netfilter: xt_owner: Add supplementary groups option
The XT_OWNER_SUPPL_GROUPS flag causes GIDs specified with XT_OWNER_GID
to be also checked in the supplementary groups of a process.
f_cred->group_info cannot be modified during its lifetime and f_cred
holds a reference to it so it's safe to use.
Signed-off-by: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
[sw0312.kim: backport from mainline to apply supplementary groups on netfilter]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I30739d09c47d0623d0638de685905d3ac2ca131a
Diffstat (limited to 'net')
-rw-r--r-- | net/netfilter/xt_owner.c | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/net/netfilter/xt_owner.c b/net/netfilter/xt_owner.c index 1302b475abcb..6423e48c88b1 100644 --- a/net/netfilter/xt_owner.c +++ b/net/netfilter/xt_owner.c @@ -60,11 +60,28 @@ owner_mt(const struct sk_buff *skb, struct xt_action_param *par) } if (info->match & XT_OWNER_GID) { + unsigned int i, match = false; kgid_t gid_min = make_kgid(&init_user_ns, info->gid_min); kgid_t gid_max = make_kgid(&init_user_ns, info->gid_max); - if ((gid_gte(filp->f_cred->fsgid, gid_min) && - gid_lte(filp->f_cred->fsgid, gid_max)) ^ - !(info->invert & XT_OWNER_GID)) + struct group_info *gi = filp->f_cred->group_info; + + if (gid_gte(filp->f_cred->fsgid, gid_min) && + gid_lte(filp->f_cred->fsgid, gid_max)) + match = true; + + if (!match && (info->match & XT_OWNER_SUPPL_GROUPS) && gi) { + for (i = 0; i < gi->ngroups; ++i) { + kgid_t group = gi->gid[i]; + + if (gid_gte(group, gid_min) && + gid_lte(group, gid_max)) { + match = true; + break; + } + } + } + + if (match ^ !(info->invert & XT_OWNER_GID)) return false; } |