Skip to content

Commit b382c08

Browse files
borkmanndavem330
authored andcommitted
sock, diag: fix panic in sock_diag_put_filterinfo
diag socket's sock_diag_put_filterinfo() dumps classic BPF programs upon request to user space (ss -0 -b). However, native eBPF programs attached to sockets (SO_ATTACH_BPF) cannot be dumped with this method: Their orig_prog is always NULL. However, sock_diag_put_filterinfo() unconditionally tries to access its filter length resp. wants to copy the filter insns from there. Internal cBPF to eBPF transformations attached to sockets don't have this issue, as orig_prog state is kept. It's currently only used by packet sockets. If we would want to add native eBPF support in the future, this needs to be done through a different attribute than PACKET_DIAG_FILTER to not confuse possible user space disassemblers that work on diag data. Fixes: 89aa075 ("net: sock: allow eBPF programs to be attached to sockets") Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Nicolas Dichtel <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 20a17bf commit b382c08

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/core/sock_diag.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk,
9090
goto out;
9191

9292
fprog = filter->prog->orig_prog;
93+
if (!fprog)
94+
goto out;
95+
9396
flen = bpf_classic_proglen(fprog);
9497

9598
attr = nla_reserve(skb, attrtype, flen);

0 commit comments

Comments
 (0)