• David Howells's avatar
    watch_queue: Fix to always request a pow-of-2 pipe ring size · 96a4d891
    David Howells authored
    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: c73be61c ("pipe: Add general notification queue support")
    Reported-by: default avatarJann Horn <jannh@google.com>
    Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    96a4d891
watch_queue.c 16.4 KB