Re: [PATCH] nbd: reclassify u->iolock of AF_UNIX sockets

From: Christian Borntraeger

Date: Thu Jul 16 2026 - 09:57:42 EST




Am 14.07.26 um 18:19 schrieb Christian Borntraeger:
Am 13.07.26 um 20:14 schrieb Christian Borntraeger:

I just realized I had my kernel.org address in from.
question is, is this the right fix and shall I do a proper patch wit correct from and signoff.

[..]

diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 8f10762e90ef..a811e431b47a 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -32,6 +32,7 @@
  #include <linux/err.h>
  #include <linux/kernel.h>
  #include <linux/slab.h>
+#include <net/af_unix.h>
  #include <net/sock.h>
  #include <linux/net.h>
  #include <linux/kthread.h>
@@ -1241,6 +1242,7 @@ static struct socket *nbd_get_socket(struct nbd_device *nbd, unsigned long fd,
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  static struct lock_class_key nbd_key[3];
  static struct lock_class_key nbd_slock_key[3];
+static struct lock_class_key nbd_unix_iolock_key;
  static void nbd_reclassify_socket(struct socket *sock)
  {
@@ -1267,6 +1269,17 @@ static void nbd_reclassify_socket(struct socket *sock)
                            &nbd_slock_key[2],
                            "sk_lock-AF_UNIX-NBD",
                            &nbd_key[2]);
+        /*
+         * The AF_UNIX stream recvmsg/sendmsg paths serialize on
+         * u->iolock, not sk_lock, so it must be reclassified as
+         * well.  A held mutex cannot be reclassified; skip it in
+         * that case, as sock_allow_reclassification() does for
+         * sk_lock.
+         */
+        if (!mutex_is_locked(&unix_sk(sk)->iolock))
+            lockdep_set_class_and_name(&unix_sk(sk)->iolock,
+                           &nbd_unix_iolock_key,
+                           "&u->iolock-NBD");
          break;
      }
  }


And when you are at it, maybe also do the reclassification for NBD_CMD_RECONFIGURE

@@ -1371,6 +1371,7 @@ static int nbd_reconnect_socket(struct nbd_device *nbd, unsigned long arg)
sock = nbd_get_socket(nbd, arg, &err);
if (!sock)
return err;
+ nbd_reclassify_socket(sock);
args = kzalloc_obj(*args);
if (!args) {