Skip to content

Commit 055ca83

Browse files
thejhbrauner
authored andcommitted
fs/pipe: Fix lockdep false-positive in watchqueue pipe_write()
When you try to splice between a normal pipe and a notification pipe, get_pipe_info(..., true) fails, so splice() falls back to treating the notification pipe like a normal pipe - so we end up in iter_file_splice_write(), which first locks the input pipe, then calls vfs_iter_write(), which locks the output pipe. Lockdep complains about that, because we're taking a pipe lock while already holding another pipe lock. I think this probably (?) can't actually lead to deadlocks, since you'd need another way to nest locking a normal pipe into locking a watch_queue pipe, but the lockdep annotations don't make that clear. Bail out earlier in pipe_write() for notification pipes, before taking the pipe lock. Reported-and-tested-by: <syzbot+011e4ea1da6692cf881c@syzkaller.appspotmail.com> Closes: https://syzkaller.appspot.com/bug?extid=011e4ea1da6692cf881c Fixes: c73be61 ("pipe: Add general notification queue support") Signed-off-by: Jann Horn <jannh@google.com> Link: https://lore.kernel.org/r/20231124150822.2121798-1-jannh@google.com Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 12c1b63 commit 055ca83

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fs/pipe.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,18 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
446446
bool was_empty = false;
447447
bool wake_next_writer = false;
448448

449+
/*
450+
* Reject writing to watch queue pipes before the point where we lock
451+
* the pipe.
452+
* Otherwise, lockdep would be unhappy if the caller already has another
453+
* pipe locked.
454+
* If we had to support locking a normal pipe and a notification pipe at
455+
* the same time, we could set up lockdep annotations for that, but
456+
* since we don't actually need that, it's simpler to just bail here.
457+
*/
458+
if (pipe_has_watch_queue(pipe))
459+
return -EXDEV;
460+
449461
/* Null write succeeds. */
450462
if (unlikely(total_len == 0))
451463
return 0;
@@ -458,11 +470,6 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
458470
goto out;
459471
}
460472

461-
if (pipe_has_watch_queue(pipe)) {
462-
ret = -EXDEV;
463-
goto out;
464-
}
465-
466473
/*
467474
* If it wasn't empty we try to merge new data into
468475
* the last buffer.

0 commit comments

Comments
 (0)