nbd: fix circular lock dependency between tx_lock and sk_lock#1018
Open
blktests-ci[bot] wants to merge 1 commit into
Open
nbd: fix circular lock dependency between tx_lock and sk_lock#1018blktests-ci[bot] wants to merge 1 commit into
blktests-ci[bot] wants to merge 1 commit into
Conversation
Author
|
Upstream branch: 4edcdef |
4cc45a3 to
90ffd56
Compare
Author
|
Upstream branch: dc59e4f |
Move kernel_sock_shutdown() out of the tx_lock critical section to break the circular lock dependency: tx_lock -> sk_lock (via inet_shutdown) vs the reverse order in the block I/O submission path. The lockdep splat shows: sk_lock-AF_INET6 --> &cmd->lock --> &nsock->tx_lock When recv_work() detects a connection failure, it calls nbd_mark_nsock_dead() under tx_lock, which calls kernel_sock_shutdown() -> inet_shutdown() -> lock_sock(), creating the tx_lock -> sk_lock dependency that conflicts with the reverse order in the I/O path. Fix this by introducing a deferred shutdown mechanism: nbd_mark_nsock_dead() records the socket needing shutdown in nsock->shutdown_sock (with an extra file reference to prevent use-after-free from the reconnect path), and the actual kernel_sock_shutdown() is performed by nbd_nsock_deferred_shutdown() after tx_lock is released at each call site. The helper uses xchg() to guarantee the shutdown is executed exactly once even when multiple paths race to consume it. Fixes: f373324 ("nbd: handle single path failures gracefully") Reported-by: syzbot+576095eed5658cbd9b63@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=576095eed5658cbd9b63 Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
1e4c4be to
575931b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request for series with
subject: nbd: fix circular lock dependency between tx_lock and sk_lock
version: 1
url: https://patchwork.kernel.org/project/linux-block/list/?series=1117816