Skip to content

Commit 1fcc064

Browse files
Guillaume Naultummakynes
authored andcommitted
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 8bcfd09 ("ipv4: add missing initialization for flowi4_uid"), which fixed the rp_filter sysctl. Fixes: 622ec2c ("net: core: add UID to flows, rules, and routes") Signed-off-by: Guillaume Nault <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 1ca6952 commit 1fcc064

File tree

4 files changed

+5
-0
lines changed

4 files changed

+5
-0
lines changed

net/ipv4/netfilter/ipt_rpfilter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static bool rpfilter_mt(const struct sk_buff *skb, struct xt_action_param *par)
7878
flow.flowi4_tos = iph->tos & IPTOS_RT_MASK;
7979
flow.flowi4_scope = RT_SCOPE_UNIVERSE;
8080
flow.flowi4_l3mdev = l3mdev_master_ifindex_rcu(xt_in(par));
81+
flow.flowi4_uid = sock_net_uid(xt_net(par), NULL);
8182

8283
return rpfilter_lookup_reverse(xt_net(par), &flow, xt_in(par), info->flags) ^ invert;
8384
}

net/ipv4/netfilter/nft_fib_ipv4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void nft_fib4_eval(const struct nft_expr *expr, struct nft_regs *regs,
6565
struct flowi4 fl4 = {
6666
.flowi4_scope = RT_SCOPE_UNIVERSE,
6767
.flowi4_iif = LOOPBACK_IFINDEX,
68+
.flowi4_uid = sock_net_uid(nft_net(pkt), NULL),
6869
};
6970
const struct net_device *oif;
7071
const struct net_device *found;

net/ipv6/netfilter/ip6t_rpfilter.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ static bool rpfilter_lookup_reverse6(struct net *net, const struct sk_buff *skb,
4040
.flowi6_l3mdev = l3mdev_master_ifindex_rcu(dev),
4141
.flowlabel = (* (__be32 *) iph) & IPV6_FLOWINFO_MASK,
4242
.flowi6_proto = iph->nexthdr,
43+
.flowi6_uid = sock_net_uid(net, NULL),
4344
.daddr = iph->saddr,
4445
};
4546
int lookup_flags;

net/ipv6/netfilter/nft_fib_ipv6.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ static u32 __nft_fib6_eval_type(const struct nft_fib *priv,
6666
struct flowi6 fl6 = {
6767
.flowi6_iif = LOOPBACK_IFINDEX,
6868
.flowi6_proto = pkt->tprot,
69+
.flowi6_uid = sock_net_uid(nft_net(pkt), NULL),
6970
};
7071
u32 ret = 0;
7172

@@ -163,6 +164,7 @@ void nft_fib6_eval(const struct nft_expr *expr, struct nft_regs *regs,
163164
struct flowi6 fl6 = {
164165
.flowi6_iif = LOOPBACK_IFINDEX,
165166
.flowi6_proto = pkt->tprot,
167+
.flowi6_uid = sock_net_uid(nft_net(pkt), NULL),
166168
};
167169
struct rt6_info *rt;
168170
int lookup_flags;

0 commit comments

Comments
 (0)