diff options
author | Willem de Bruijn <willemb@google.com> | 2017-04-11 14:08:08 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2017-04-11 14:54:19 -0400 |
commit | 8f917bba0042f1e3b7693743fbe9782709e936e7 (patch) | |
tree | 5adc788308ed37a25a9911c42149638052f24b47 /net/core | |
parent | cb6bf9cfdb5e26dfb7eb9b955b2f24d82703e27d (diff) | |
download | linux-8f917bba0042f1e3b7693743fbe9782709e936e7.tar.bz2 |
bpf: pass sk to helper functions
BPF helper functions access socket fields through skb->sk. This is not
set in ingress cgroup and socket filters. The association is only made
in skb_set_owner_r once the filter has accepted the packet. Sk is
available as socket lookup has taken place.
Temporarily set skb->sk to sk in these cases.
Signed-off-by: Willem de Bruijn <willemb@google.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/filter.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index bbe0cf415105..ce2a19da8aa4 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -92,8 +92,13 @@ int sk_filter_trim_cap(struct sock *sk, struct sk_buff *skb, unsigned int cap) rcu_read_lock(); filter = rcu_dereference(sk->sk_filter); if (filter) { - unsigned int pkt_len = bpf_prog_run_save_cb(filter->prog, skb); + struct sock *save_sk = skb->sk; + unsigned int pkt_len; + + skb->sk = sk; + pkt_len = bpf_prog_run_save_cb(filter->prog, skb); err = pkt_len ? pskb_trim(skb, max(cap, pkt_len)) : -EPERM; + skb->sk = save_sk; } rcu_read_unlock(); |