Commit ed13998c319b050fc9abdb73915859dfdbe1fb38

Authored by Nicolas Dichtel
Committed by David S. Miller
1 parent 92bb73ea2c

sock_diag: fix filter code sent to userspace

Filters need to be translated to real BPF code for userland, like SO_GETFILTER.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

Showing 3 changed files with 9 additions and 3 deletions Side-by-side Diff

include/linux/filter.h
... ... @@ -46,6 +46,7 @@
46 46 extern int sk_detach_filter(struct sock *sk);
47 47 extern int sk_chk_filter(struct sock_filter *filter, unsigned int flen);
48 48 extern int sk_get_filter(struct sock *sk, struct sock_filter __user *filter, unsigned len);
  49 +extern void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to);
49 50  
50 51 #ifdef CONFIG_BPF_JIT
51 52 #include <stdarg.h>
... ... @@ -778,7 +778,7 @@
778 778 }
779 779 EXPORT_SYMBOL_GPL(sk_detach_filter);
780 780  
781   -static void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
  781 +void sk_decode_filter(struct sock_filter *filt, struct sock_filter *to)
782 782 {
783 783 static const u16 decodes[] = {
784 784 [BPF_S_ALU_ADD_K] = BPF_ALU|BPF_ADD|BPF_K,
net/core/sock_diag.c
... ... @@ -73,8 +73,13 @@
73 73 goto out;
74 74 }
75 75  
76   - if (filter)
77   - memcpy(nla_data(attr), filter->insns, len);
  76 + if (filter) {
  77 + struct sock_filter *fb = (struct sock_filter *)nla_data(attr);
  78 + int i;
  79 +
  80 + for (i = 0; i < filter->len; i++, fb++)
  81 + sk_decode_filter(&filter->insns[i], fb);
  82 + }
78 83  
79 84 out:
80 85 rcu_read_unlock();