netfilter: rpfilter/fib: Set ->flowic_uid correctly for user namespaces.
Subsystems (2)
PATCH 1/1 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.
--- net/ipv4/netfilter/ipt_rpfilter.c | 1 + net/ipv4/netfilter/nft_fib_ipv4.c | 1 + net/ipv6/netfilter/ip6t_rpfilter.c | 1 + net/ipv6/netfilter/nft_fib_ipv6.c | 2 ++ 4 files changed, 5 insertions(+)
net/ipv4/netfilter/ipt_rpfilter.c +1 -0
@@ -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; }
net/ipv4/netfilter/nft_fib_ipv4.c +1 -0
@@ -65,6 +65,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,struct flowi4 fl4 = { .flowi4_scope =RT_SCOPE_UNIVERSE , .flowi4_iif =LOOPBACK_IFINDEX , + .flowi4_uid =sock_net_uid (nft_net (pkt),NULL ), };const struct net_device *oif;const struct net_device *found;
net/ipv6/netfilter/ip6t_rpfilter.c +1 -0
@@ -40,6 +40,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb, .flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev), .flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK, .flowi6_proto = iph->nexthdr, + .flowi6_uid = sock_net_uid(net, NULL), .daddr = iph->saddr, };int lookup_flags;
net/ipv6/netfilter/nft_fib_ipv6.c +2 -0
@@ -66,6 +66,7 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,struct flowi6 fl6 = { .flowi6_iif =LOOPBACK_IFINDEX , .flowi6_proto = pkt->tprot, + .flowi6_uid =sock_net_uid (nft_net (pkt),NULL ), };u32 ret =0 ;
@@ -163,6 +164,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,struct flowi6 fl6 = { .flowi6_iif =LOOPBACK_IFINDEX , .flowi6_proto = pkt->tprot, + .flowi6_uid =sock_net_uid (nft_net (pkt),NULL ), };struct rt6_info *rt;int lookup_flags;
Signature · 1 line
2.21.3
Quoted 9 lines · Guillaume Nault
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 forflowi4_uid"), which fixed therp_filtersysctl.
Applied, thanks