mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guilherme Giacomo Simoes <trintaeoitogc@gmail.com>
To: hdanton@sina.com
Cc: bvanassche@acm.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, nbd@other.debian.org,
	syzbot+d7d72f3d467710442af0@syzkaller.appspotmail.com,
	trintaeoitogc@gmail.com
Subject: Re: [PATCH] nbd: fix circular lock dependency
Date: Thu, 12 Nov 2026 08:11:28 -0300	[thread overview]
Message-ID: <20261112111128.261395-1-trintaeoitogc@gmail.com> (raw)
In-Reply-To: <20261112001319.463-1-hdanton@sina.com>

Hillf Danton <hdanton@sina.com> wrote:
> FYI reclassifying sockets is also corrupting memory [11], so can you fix
> the corrupter before reclassifying again?
> 
> [11] Subject: [syzbot] BUG: spinlock already unlocked in corrupted
> https://lore.kernel.org/lkml/6aec63fd.5f5735a5.290c1c.0003.GAE@google.com/
Important thing to do.

I'm not a nbd/net specialist, I only get the "fix possible circular dependency"
bug to resolve because this appears in mm subsystem syzbot.
But, I read this bug and see that is a race condition between inet_shutdown()
and sock_allow_reclassification().

How IA analysis say:
"""
- Thread 1 (runner/shutdown) calls inet_shutdown() -> release_sock(sk). Inside
 release_sock(), Thread 1 acquires spin_lock_bh(&sk->sk_lock.slock).

- Thread 2 (reclassifier) enters nbd_add_socket() ->
 nbd_reclassify_socket(sock). Right before Thread 1 acquired the lock,
 sock_allow_reclassification(sk) returned true. Thread 2 calls
 sock_lock_init_class_and_name(), which invokes
 spin_lock_init(&sk->sk_lock.slock) while Thread 1 is holding slock.

- spin_lock_init() zeroes the spinlock and marks it unlocked
 (SPINLOCK_OWNER_INIT).

- Thread 1 finishes processing in release_sock() and calls
 spin_unlock_bh(&sk->sk_lock.slock).
 ... 
"""

What lead me think that when Thread 1 try acquire lock this would must be
blocked to acquire this lock, so a spin_lock(&sk->sk_lock.slock) inside
nbd_reclassify_socker right bellow sock_allow_reclassification(sk) fix this
bug?

```
static void nbd_reclassify_socket(struct socket *sock)
{
	struct sock *sk = sock->sk;

	if (!sock_allow_reclassification(sk))
		return;

	spin_lock(&sk->sk_lock.slock);

    ...
```

thanks,
guilherme

  reply	other threads:[~2026-11-12 11:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 21:57 Guilherme Giacomo Simoes
2026-11-11  0:40 ` Bart Van Assche
2026-11-11 10:19   ` Guilherme Giacomo Simoes
2026-11-11 11:29     ` Timo Joannin
2026-11-11 12:25       ` Guilherme Giacomo Simoes
2026-11-11 11:38     ` Guilherme Giacomo Simoes
2026-11-11 17:13       ` Bart Van Assche
2026-11-12  0:13         ` Hillf Danton
2026-11-12 11:11           ` Guilherme Giacomo Simoes [this message]
2026-11-12 11:03         ` Guilherme Giacomo Simoes
2026-11-11 12:24     ` Guilherme Giacomo Simoes

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261112111128.261395-1-trintaeoitogc@gmail.com \
    --to=trintaeoitogc@gmail.com \
    --cc=bvanassche@acm.org \
    --cc=hdanton@sina.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nbd@other.debian.org \
    --cc=syzbot+d7d72f3d467710442af0@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®