Skip to content

Commit

Permalink
llc: set SOCK_RCU_FREE in llc_sap_add_socket()
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Cong Wang authored and David S. Miller committed Oct 16, 2018
1 parent d0f068e commit 5a8e7ae
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions net/llc/llc_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,7 @@ void llc_sap_add_socket(struct llc_sap *sap, struct sock *sk)
llc_sk(sk)->sap = sap;

spin_lock_bh(&sap->sk_lock);
sock_set_flag(sk, SOCK_RCU_FREE);
sap->sk_count++;
sk_nulls_add_node_rcu(sk, laddr_hb);
hlist_add_head(&llc->dev_hash_node, dev_hb);
Expand Down

0 comments on commit 5a8e7ae

Please sign in to comment.