• Jonathan Cameron's avatar
    iio:magnetometer:ak8975 Fix alignment and data leak issues. · 02ad21ce
    Jonathan Cameron authored
    One of a class of bugs pointed out by Lars in a recent review.
    iio_push_to_buffers_with_timestamp assumes the buffer used is aligned
    to the size of the timestamp (8 bytes).  This is not guaranteed in
    this driver which uses an array of smaller elements on the stack.
    As Lars also noted this anti pattern can involve a leak of data to
    userspace and that indeed can happen here.  We close both issues by
    moving to a suitable structure in the iio_priv() data.
    
    This data is allocated with kzalloc so no data can leak apart from
    previous readings.
    
    The explicit alignment of ts is not necessary in this case as by
    coincidence the padding will end up the same, however I consider
    it to make the code less fragile and have included it.
    
    Fixes: bc11ca4a ("iio:magnetometer:ak8975: triggered buffer support")
    Reported-by: default avatarLars-Peter Clausen <lars@metafoo.de>
    Cc: Gregor Boirie <gregor.boirie@parrot.com>
    Cc: Linus Walleij <linus.walleij@linaro.org>
    Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
    Reviewed-by: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
    Cc: <Stable@vger.kernel.org>
    02ad21ce
ak8975.c 26.4 KB