aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/netfilter/ipt_rpfilter.c
diff options
context:
space:
mode:
authorGuillaume Nault <gnault@redhat.com>2022-10-13 16:37:47 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2022-10-19 08:46:48 +0200
commit1fcc064b305a1aadeff0d4bff961094d27660acd (patch)
tree8dcb7515e4d412cc7787785dcdcb1339f0f2d7c7 /net/ipv4/netfilter/ipt_rpfilter.c
parent1ca695207ed2271ecbf8ee6c641970f621c157cc (diff)
downloadlinux-1fcc064b305a1aadeff0d4bff961094d27660acd.tar.gz
netfilter: rpfilter/fib: Set ->flowic_uid correctly for user namespaces.
Currently netfilter's rpfilter and fib modules implicitely initialise ->flowic_uid with 0. This is normally the root UID. However, this isn't the case in user namespaces, where user ID 0 is mapped to a different kernel UID. By initialising ->flowic_uid with sock_net_uid(), we get the root UID of the user namespace, thus keeping the same behaviour whether or not we're running in a user namepspace. Note, this is similar to commit 8bcfd0925ef1 ("ipv4: add missing initialization for flowi4_uid"), which fixed the rp_filter sysctl. Fixes: 622ec2c9d524 ("net: core: add UID to flows, rules, and routes") Signed-off-by: Guillaume Nault <gnault@redhat.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'net/ipv4/netfilter/ipt_rpfilter.c')
-rw-r--r--net/ipv4/netfilter/ipt_rpfilter.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/net/ipv4/netfilter/ipt_rpfilter.c b/net/ipv4/netfilter/ipt_rpfilter.c
index ff85db52b2e56..ded5bef02f771 100644
--- a/net/ipv4/netfilter/ipt_rpfilter.c
+++ b/net/ipv4/netfilter/ipt_rpfilter.c
@@ -78,6 +78,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
flow.flowi4_tos = iph->tos & IPTOS_RT_MASK;
flow.flowi4_scope = RT_SCOPE_UNIVERSE;
flow.flowi4_l3mdev = l3mdev_master_ifindex_rcu(xt_in(par));
+ flow.flowi4_uid = sock_net_uid(xt_net(par), NULL);
return rpfilter_lookup_reverse(xt_net(par), &flow, xt_in(par), info->flags) ^ invert;
}