Skip to content

Commit d0e13a1

Browse files
wdebruijborkmann
authored andcommitted
flow_dissector: lookup netns by skb->sk if skb->dev is NULL
BPF flow dissectors are configured per network namespace. __skb_flow_dissect looks up the netns through dev_net(skb->dev). In some dissector paths skb->dev is NULL, such as for Unix sockets. In these cases fall back to looking up the netns by socket. Analyzing the codepaths leading to __skb_flow_dissect I did not find a case where both skb->dev and skb->sk are NULL. Warn and fall back to standard flow dissector if one is found. Fixes: d58e468 ("flow_dissector: implements flow dissector BPF hook") Reported-by: Eric Dumazet <[email protected]> Signed-off-by: Willem de Bruijn <[email protected]> Acked-by: Song Liu <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 7ea3c40 commit d0e13a1

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/core/flow_dissector.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
714714
struct flow_dissector_key_vlan *key_vlan;
715715
enum flow_dissect_ret fdret;
716716
enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX;
717-
struct bpf_prog *attached;
717+
struct bpf_prog *attached = NULL;
718718
int num_hdrs = 0;
719719
u8 ip_proto = 0;
720720
bool ret;
@@ -755,8 +755,14 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
755755
target_container);
756756

757757
rcu_read_lock();
758-
attached = skb ? rcu_dereference(dev_net(skb->dev)->flow_dissector_prog)
759-
: NULL;
758+
if (skb) {
759+
if (skb->dev)
760+
attached = rcu_dereference(dev_net(skb->dev)->flow_dissector_prog);
761+
else if (skb->sk)
762+
attached = rcu_dereference(sock_net(skb->sk)->flow_dissector_prog);
763+
else
764+
WARN_ON_ONCE(1);
765+
}
760766
if (attached) {
761767
/* Note that even though the const qualifier is discarded
762768
* throughout the execution of the BPF program, all changes(the

0 commit comments

Comments
 (0)