]> git.baikalelectronics.ru Git - kernel.git/commit
watch_queue: Fix missing locking in add_watch_to_object()
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Jul 2022 09:31:12 +0000 (10:31 +0100)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Jul 2022 17:06:49 +0000 (10:06 -0700)
commit0686b3daa5694bf6fdcb20c1ddf1a27da0229c79
tree6207812d3aa830b193c472afc934424f8a45dd08
parent45ebef626c9d270c118de7809f57b700ea38d18d
watch_queue: Fix missing locking in add_watch_to_object()

If a watch is being added to a queue, it needs to guard against
interference from addition of a new watch, manual removal of a watch and
removal of a watch due to some other queue being destroyed.

KEYCTL_WATCH_KEY guards against this for the same {key,queue} pair by
holding the key->sem writelocked and by holding refs on both the key and
the queue - but that doesn't prevent interaction from other {key,queue}
pairs.

While add_watch_to_object() does take the spinlock on the event queue,
it doesn't take the lock on the source's watch list.  The assumption was
that the caller would prevent that (say by taking key->sem) - but that
doesn't prevent interference from the destruction of another queue.

Fix this by locking the watcher list in add_watch_to_object().

Fixes: 175295c8c9fa ("pipe: Add general notification queue support")
Reported-by: syzbot+03d7b43290037d1f87ca@syzkaller.appspotmail.com
Signed-off-by: David Howells <dhowells@redhat.com>
cc: keyrings@vger.kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
kernel/watch_queue.c