Skip to content

Commit

Permalink
flow_dissector: lookup netns by skb->sk if skb->dev is NULL
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
wdebruij authored and borkmann committed Sep 25, 2018
1 parent 7ea3c40 commit d0e13a1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions net/core/flow_dissector.c
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
struct flow_dissector_key_vlan *key_vlan;
enum flow_dissect_ret fdret;
enum flow_dissector_key_id dissector_vlan = FLOW_DISSECTOR_KEY_MAX;
struct bpf_prog *attached;
struct bpf_prog *attached = NULL;
int num_hdrs = 0;
u8 ip_proto = 0;
bool ret;
Expand Down Expand Up @@ -755,8 +755,14 @@ bool __skb_flow_dissect(const struct sk_buff *skb,
target_container);

rcu_read_lock();
attached = skb ? rcu_dereference(dev_net(skb->dev)->flow_dissector_prog)
: NULL;
if (skb) {
if (skb->dev)
attached = rcu_dereference(dev_net(skb->dev)->flow_dissector_prog);
else if (skb->sk)
attached = rcu_dereference(sock_net(skb->sk)->flow_dissector_prog);
else
WARN_ON_ONCE(1);
}
if (attached) {
/* Note that even though the const qualifier is discarded
* throughout the execution of the BPF program, all changes(the
Expand Down

0 comments on commit d0e13a1

Please sign in to comment.