commit 5c49056ad9f3c786f7716da2dd47e4488fc6bd25 upstream.
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.
Explicit alignment of ts needed to ensure consistent padding
on all architectures (particularly x86_32 with it's 4 byte alignment
of s64)
Fixes: e4a70e3e7d
("iio: humidity: add support to hts221 rh/temp combo device")
Reported-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Lorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
56 lines
1 KiB
C
56 lines
1 KiB
C
/*
|
|
* STMicroelectronics hts221 sensor driver
|
|
*
|
|
* Copyright 2016 STMicroelectronics Inc.
|
|
*
|
|
* Lorenzo Bianconi <lorenzo.bianconi@st.com>
|
|
*
|
|
* Licensed under the GPL-2.
|
|
*/
|
|
|
|
#ifndef HTS221_H
|
|
#define HTS221_H
|
|
|
|
#define HTS221_DEV_NAME "hts221"
|
|
|
|
#include <linux/iio/iio.h>
|
|
|
|
enum hts221_sensor_type {
|
|
HTS221_SENSOR_H,
|
|
HTS221_SENSOR_T,
|
|
HTS221_SENSOR_MAX,
|
|
};
|
|
|
|
struct hts221_sensor {
|
|
u8 cur_avg_idx;
|
|
int slope, b_gen;
|
|
};
|
|
|
|
struct hts221_hw {
|
|
const char *name;
|
|
struct device *dev;
|
|
struct regmap *regmap;
|
|
|
|
struct iio_trigger *trig;
|
|
int irq;
|
|
|
|
struct hts221_sensor sensors[HTS221_SENSOR_MAX];
|
|
|
|
bool enabled;
|
|
u8 odr;
|
|
/* Ensure natural alignment of timestamp */
|
|
struct {
|
|
__le16 channels[2];
|
|
s64 ts __aligned(8);
|
|
} scan;
|
|
};
|
|
|
|
extern const struct dev_pm_ops hts221_pm_ops;
|
|
|
|
int hts221_probe(struct device *dev, int irq, const char *name,
|
|
struct regmap *regmap);
|
|
int hts221_set_enable(struct hts221_hw *hw, bool enable);
|
|
int hts221_allocate_buffers(struct hts221_hw *hw);
|
|
int hts221_allocate_trigger(struct hts221_hw *hw);
|
|
|
|
#endif /* HTS221_H */
|