ad7779_set_sampling_frequency() computes freq_khz = sampling_freq / HZ_PER_KHZ and then divides AD7779_HIGHPOWER_DIV by freq_khz. Only upper bounds are validated; there is no lower bound. Writing a sampling_frequency between 0 and 999 to the IIO sysfs attribute therefore makes freq_khz 0 and the following division raises a divide error in the kernel: dec = div / freq_khz; frac = div % freq_khz; iio_write_channel_info() passes the parsed integer straight to write_raw(), so an unprivileged writer of the attribute can trigger this. The hardware cannot sample below 1 kHz anyway, so reject anything smaller than HZ_PER_KHZ up front. Fixes: c9a3f8c7bfcb ("drivers: iio: adc: add support for ad777x family") Cc: stable@vger.kernel.org Signed-off-by: Shirong Zhao --- drivers/iio/adc/ad7779.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/iio/adc/ad7779.c b/drivers/iio/adc/ad7779.c index 79fb38d..537c281 100644 --- a/drivers/iio/adc/ad7779.c +++ b/drivers/iio/adc/ad7779.c @@ -278,6 +278,10 @@ static int ad7779_set_sampling_frequency(struct ad7779_state *st, if (sampling_freq > AD7779_SPIMODE_MAX_SAMP_FREQ) return -EINVAL; + /* freq_khz is a divisor below; it is zero for sampling_freq < 1 kHz */ + if (sampling_freq < HZ_PER_KHZ) + return -EINVAL; + div = AD7779_HIGHPOWER_DIV; freq_khz = sampling_freq / HZ_PER_KHZ; -- 2.53.0