• Lars-Peter Clausen's avatar
    iio:kfifo: Protect against concurrent access from userspace · 0894d80d
    Lars-Peter Clausen authored
    It is possible for userspace to concurrently access the buffer from multiple
    threads or processes. To avoid corruption of the internal state of the buffer we
    need to add proper locking. It is possible for multiple processes to try to read
    from the buffer concurrently and it is also possible that one process causes a
    buffer re-allocation while a different process still access the buffer. Both can
    be fixed by protecting the calls to kfifo_to_user() and kfifo_alloc() by the
    same mutex. In iio_read_first_n_kfifo() we also use kfifo_recsize() instead of
    the buffers bytes_per_datum to avoid a race that can happen if bytes_per_datum
    has been changed, but the buffer has not been reallocated yet.
    
    Note that all access to the buffer from within the kernel is already properly
    synchronized, so there is no need for extra locking in iio_store_to_kfifo().
    Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
    Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
    0894d80d
kfifo_buf.c 4.06 KB