From: Daniel Borkmann Date: Wed, 2 Sep 2015 12:00:36 +0000 (+0200) Subject: sock, diag: fix panic in sock_diag_put_filterinfo X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b382c0865600;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git 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: 89aa075832b0 ("net: sock: allow eBPF programs to be attached to sockets") Signed-off-by: Daniel Borkmann Acked-by: Nicolas Dichtel Acked-by: Alexei Starovoitov Signed-off-by: David S. Miller --- diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c index d79866c5f8bc..817622f3dbb7 100644 --- a/net/core/sock_diag.c +++ b/net/core/sock_diag.c @@ -90,6 +90,9 @@ int sock_diag_put_filterinfo(bool may_report_filterinfo, struct sock *sk, goto out; fprog = filter->prog->orig_prog; + if (!fprog) + goto out; + flen = bpf_classic_proglen(fprog); attr = nla_reserve(skb, attrtype, flen);