[net] llc: set SOCK_RCU_FREE in llc_sap_add_socket()

Message ID 20181011181513.20203-1-xiyou.wangcong@gmail.com
State Under Review
Delegated to: David Miller
Headers show
  • [net] llc: set SOCK_RCU_FREE in llc_sap_add_socket()
Related show

Commit Message

Cong Wang Oct. 11, 2018, 6:15 p.m.
WHen an llc sock is added into the sk_laddr_hash of an llc_sap,
it is not marked with SOCK_RCU_FREE.

This causes that the sock could be freed while it is still being
read by __llc_lookup_established() with RCU read lock. sock is
refcounted, but with RCU read lock, nothing prevents the readers
getting a zero refcnt.

Fix it by setting SOCK_RCU_FREE in llc_sap_add_socket().

Reported-by: syzbot+11e05f04c15e03be5254@syzkaller.appspotmail.com
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
 net/llc/llc_conn.c | 1 +
 1 file changed, 1 insertion(+)


diff --git a/net/llc/llc_conn.c b/net/llc/llc_conn.c
index c0ac522b48a1..4ff89cb7c86f 100644
--- a/net/llc/llc_conn.c
+++ b/net/llc/llc_conn.c
@@ -734,6 +734,7 @@  void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
 	llc_sk(sk)->sap = sap;
+	sock_set_flag(sk, SOCK_RCU_FREE);
 	sk_nulls_add_node_rcu(sk, laddr_hb);
 	hlist_add_head(&llc->dev_hash_node, dev_hb);