From: Eric Dumazet Date: Sun, 12 Feb 2017 22:03:52 +0000 (-0800) Subject: net/llc: avoid BUG_ON() in skb_orphan() X-Git-Tag: v3.12.71~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c112a93ae0bf3906150d3c7badd8ccc2708ad031;p=thirdparty%2Fkernel%2Fstable.git net/llc: avoid BUG_ON() in skb_orphan() [ Upstream commit 8b74d439e1697110c5e5c600643e823eb1dd0762 ] It seems nobody used LLC since linux-3.12. Fortunately fuzzers like syzkaller still know how to run this code, otherwise it would be no fun. Setting skb->sk without skb->destructor leads to all kinds of bugs, we now prefer to be very strict about it. Ideally here we would use skb_set_owner() but this helper does not exist yet, only CAN seems to have a private helper for that. [js] take sock_efree from 62bccb8cdb6905 Fixes: 376c7311bdb6 ("net: add a temporary sanity check in skb_orphan()") Signed-off-by: Eric Dumazet Reported-by: Andrey Konovalov Signed-off-by: David S. Miller Signed-off-by: Jiri Slaby --- diff --git a/include/net/sock.h b/include/net/sock.h index 238e934dd3c33..467d2f810fb35 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -1554,6 +1554,7 @@ extern struct sk_buff *sock_rmalloc(struct sock *sk, extern void sock_wfree(struct sk_buff *skb); extern void skb_orphan_partial(struct sk_buff *skb); extern void sock_rfree(struct sk_buff *skb); +void sock_efree(struct sk_buff *skb); extern void sock_edemux(struct sk_buff *skb); extern int sock_setsockopt(struct socket *sock, int level, diff --git a/net/core/sock.c b/net/core/sock.c index 7fa427ed41bce..d765d6411a5b1 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -1656,6 +1656,12 @@ void sock_rfree(struct sk_buff *skb) } EXPORT_SYMBOL(sock_rfree); +void sock_efree(struct sk_buff *skb) +{ + sock_put(skb->sk); +} +EXPORT_SYMBOL(sock_efree); + void sock_edemux(struct sk_buff *skb) { struct sock *sk = skb->sk; diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c index cd8724177965c..6d36b3241b988 100644 --- a/net/llc/llc_conn.c +++ b/net/llc/llc_conn.c @@ -821,7 +821,10 @@ void llc_conn_handler(struct llc_sap *sap, struct sk_buff *skb) * another trick required to cope with how the PROCOM state * machine works. -acme */ + skb_orphan(skb); + sock_hold(sk); skb->sk = sk; + skb->destructor = sock_efree; } if (!sock_owned_by_user(sk)) llc_conn_rcv(sk, skb); diff --git a/net/llc/llc_sap.c b/net/llc/llc_sap.c index e5850699098ef..4ee1e1142e8ed 100644 --- a/net/llc/llc_sap.c +++ b/net/llc/llc_sap.c @@ -290,7 +290,10 @@ static void llc_sap_rcv(struct llc_sap *sap, struct sk_buff *skb, ev->type = LLC_SAP_EV_TYPE_PDU; ev->reason = 0; + skb_orphan(skb); + sock_hold(sk); skb->sk = sk; + skb->destructor = sock_efree; llc_sap_state_process(sap, skb); }