• Lars-Peter Clausen's avatar
    iio: adis_buffer: Fix out-of-bounds memory access · 3e77cb85
    Lars-Peter Clausen authored
    [ Upstream commit d590faf9 ]
    
    The SPI tx and rx buffers are both supposed to be scan_bytes amount of
    bytes large and a common allocation is used to allocate both buffers. This
    puts the beginning of the tx buffer scan_bytes bytes after the rx buffer.
    The initialization of the tx buffer pointer is done adding scan_bytes to
    the beginning of the rx buffer, but since the rx buffer is of type __be16
    this will actually add two times as much and the tx buffer ends up pointing
    after the allocated buffer.
    
    Fix this by using scan_count, which is scan_bytes / 2, instead of
    scan_bytes when initializing the tx buffer pointer.
    
    Fixes: aacff892 ("staging:iio:adis: Preallocate transfer message")
    Signed-off-by: default avatarLars-Peter Clausen <lars@metafoo.de>
    Cc: <Stable@vger.kernel.org>
    Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
    Signed-off-by: default avatarSasha Levin <sasha.levin@oracle.com>
    3e77cb85
adis_buffer.c 4.24 KB