From: Yu Gao lapb_unregister() sleeps in usleep_range() under write_lock_bh(&lapb_list_lock) while waiting for other users of the control block, and then takes lapb->lock under that lock, which adds lapb_list_lock --> &lapb->lock to the cycle syzbot reports in lapb_connect_request(). Unlink the block and drop lapb_list_lock before waiting. Once the block is unlinked, nothing can look it up and take a new reference. Found by code inspection. With this patch alone, the syzbot reproducers still report a cycle; the transmit change later in this series removes it. Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module") Suggested-by: Willem de Bruijn Acked-by: Martin Schiller Signed-off-by: Yu Gao --- net/lapb/lapb_iface.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c index 670e085..1af36fd 100644 --- a/net/lapb/lapb_iface.c +++ b/net/lapb/lapb_iface.c @@ -179,9 +179,11 @@ int lapb_unregister(struct net_device *dev) if (!lapb) goto out; lapb_put(lapb); + __lapb_remove_cb(lapb); + write_unlock_bh(&lapb_list_lock); /* Wait for other refs to "lapb" to drop */ - while (refcount_read(&lapb->refcnt) > 2) + while (refcount_read(&lapb->refcnt) > 1) usleep_range(1, 10); spin_lock_bh(&lapb->lock); @@ -197,10 +199,8 @@ int lapb_unregister(struct net_device *dev) timer_delete_sync(&lapb->t1timer); timer_delete_sync(&lapb->t2timer); - __lapb_remove_cb(lapb); - lapb_put(lapb); - rc = LAPB_OK; + return LAPB_OK; out: write_unlock_bh(&lapb_list_lock); return rc; -- Git-157)