From: David Howells <dhowells@xxxxxxxxxx> commit 96a4d8912b28451cd62825fd7caa0e66e091d938 upstream. The pipe ring size must always be a power of 2 as the head and tail pointers are masked off by AND'ing with the size of the ring - 1. watch_queue_set_size(), however, lets you specify any number of notes between 1 and 511. This number is passed through to pipe_resize_ring() without checking/forcing its alignment. Fix this by rounding the number of slots required up to the nearest power of two. The request is meant to guarantee that at least that many notifications can be generated before the queue is full, so rounding down isn't an option, but, alternatively, it may be better to give an error if we aren't allowed to allocate that much ring space. Fixes: c73be61cede5 ("pipe: Add general notification queue support") Reported-by: Jann Horn <jannh@xxxxxxxxxx> Signed-off-by: David Howells <dhowells@xxxxxxxxxx> Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- kernel/watch_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/kernel/watch_queue.c +++ b/kernel/watch_queue.c @@ -244,7 +244,7 @@ long watch_queue_set_size(struct pipe_in goto error; } - ret = pipe_resize_ring(pipe, nr_notes); + ret = pipe_resize_ring(pipe, roundup_pow_of_two(nr_notes)); if (ret < 0) goto error; Patches currently in stable-queue which might be from dhowells@xxxxxxxxxx are queue-5.16/watch_queue-fix-lack-of-barrier-sync-lock-between-post-and-read.patch queue-5.16/watch_queue-pipe-free-watchqueue-state-after-clearing-pipe-ring.patch queue-5.16/watch_queue-make-comment-about-setting-defunct-more-accurate.patch queue-5.16/watch_queue-fix-the-alloc-bitmap-size-to-reflect-notes-allocated.patch queue-5.16/watch_queue-free-the-alloc-bitmap-when-the-watch_queue-is-torn-down.patch queue-5.16/watch_queue-fix-to-always-request-a-pow-of-2-pipe-ring-size.patch queue-5.16/watch_queue-fix-filter-limit-check.patch queue-5.16/watch_queue-fix-to-release-page-in-release.patch