Skip to content

nbd: Fix deadlock during fs reclaim under lock_sock().

Kuniyuki Iwashima linux-block llvm netdev oe-kbuild-all 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest5 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5nbd: Remove redundant sock->ops->shutdown() check in nbd_get_socket().drivers/block/nbd.c+0 -70 replies
2/5nbd: Reject unconnected sockets in nbd_get_socket().drivers/block/nbd.c+7 -00 replies
3/5net: Introduce lock_sock_try().include/net/sock.h+31 -00 replies
4/5inet: Add inet_shutdown_locked().include/net/inet_common.h net/ipv4/af_inet.c+33 -110 replies
5/5nbd: Use lock_sock_try() for TCP sendmsg() and shutdown().drivers/block/nbd.c+36 -21 reply

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [PATCH 0/5] nbd: Fix deadlock during fs reclaim under lock_sock().

Recently, syzbot has reported 100+ possible deadlock splats involving NBD, typically following this pattern:

lock_sock(sk)
-> GFP_KERNEL memory allocation

     -> fs reclaim
        -> lock_sock(sk) at NBD

Instead of spreading memalloc_noio_{save,restore} over the networking code, we want to fix it in the NBD layer.

This series introduces a try-lock version of lock_sock() and use it in NBD to fix the deadlock.

The try-lock variant should not fail in practice because while the socket remain exposed to userspace even after being handed over to NBD, the socket should not be touched by userspace.

The series can be applied cleanly on block-7.0 and net.git.

Kuniyuki Iwashima (5):
nbd: Remove redundant sock->ops->shutdown() check in nbd_get_socket().
nbd: Reject unconnected sockets in nbd_get_socket().
net: Introduce lock_sock_try().
inet: Add inet_shutdown_locked().
nbd: Use lock_sock_try() for TCP sendmsg() and shutdown().

 drivers/block/nbd.c       | 44 ++++++++++++++++++++++++++++++++++-----
 include/net/inet_common.h |  1 +
 include/net/sock.h        | 31 +++++++++++++++++++++++++++
 net/ipv4/af_inet.c        | 43 ++++++++++++++++++++++++++++----------
 4 files changed, 103 insertions(+), 16 deletions(-)
Signature · 1 line
2.53.0.1018.g2bb0e51243-goog