Skip to content

Commit 35d848e

Browse files
warthog618Bartosz Golaszewski
authored andcommitted
gpiolib: cdev: Add INIT_KFIFO() for linereq events
The initialisation of the linereq events kfifo relies on the struct being zeroed and a subsequent call to kfifo_alloc(). The call to kfifo_alloc() is deferred until edge detection is first enabled for the linereq. If the kfifo is inadvertently accessed before the call to kfifo_alloc(), as was the case in a recently discovered bug, it behaves as a FIFO of size 1 with an element size of 0, so writes and reads to the kfifo appear successful but copy no actual data. As a defensive measure, initialise the kfifo with INIT_KFIFO() when the events kfifo is constructed. This initialises the kfifo element size and zeroes its data pointer, so any inadvertant access prior to the kfifo_alloc() call will trigger an oops. Signed-off-by: Kent Gibson <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
1 parent 9a73e03 commit 35d848e

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

drivers/gpio/gpiolib-cdev.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,7 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip)
17741774

17751775
mutex_init(&lr->config_mutex);
17761776
init_waitqueue_head(&lr->wait);
1777+
INIT_KFIFO(lr->events);
17771778
lr->event_buffer_size = ulr.event_buffer_size;
17781779
if (lr->event_buffer_size == 0)
17791780
lr->event_buffer_size = ulr.num_lines * 16;

0 commit comments

Comments
 (0)