]> www.infradead.org Git - users/dwmw2/linux.git/commit
watchqueue: make sure to serialize 'wqueue->defunct' properly
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 19 Jul 2022 18:09:01 +0000 (11:09 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 29 Jul 2022 15:19:27 +0000 (17:19 +0200)
commit0adf21eec59040b31af113e626efd85eb153c728
treeec78f96d313aa1f4ed3d0f9706ed91a9ed14bbed
parentc0a3a9eb262a5e86a36fd5fc4f9fc38470713f13
watchqueue: make sure to serialize 'wqueue->defunct' properly

commit 353f7988dd8413c47718f7ca79c030b6fb62cfe5 upstream.

When the pipe is closed, we mark the associated watchqueue defunct by
calling watch_queue_clear().  However, while that is protected by the
watchqueue lock, new watchqueue entries aren't actually added under that
lock at all: they use the pipe->rd_wait.lock instead, and looking up
that pipe happens without any locking.

The watchqueue code uses the RCU read-side section to make sure that the
wqueue entry itself hasn't disappeared, but that does not protect the
pipe_info in any way.

So make sure to actually hold the wqueue lock when posting watch events,
properly serializing against the pipe being torn down.

Reported-by: Noam Rathaus <noamr@ssd-disclosure.com>
Cc: Greg KH <gregkh@linuxfoundation.org>
Cc: David Howells <dhowells@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
kernel/watch_queue.c