Skip to content

Commit 83a06bf

Browse files
Marcelo Roberto Jimenezjohnstultz-work
authored andcommitted
RTC: Prevents a division by zero in kernel code.
This patch prevents a user space program from calling the RTC_IRQP_SET ioctl with a negative value of frequency. Also, if this call is make with a zero value of frequency, there would be a division by zero in the kernel code. [jstultz: Also initialize irq_freq to 1 to catch other divbyzero issues] CC: Alessandro Zummo <a.zummo@towertech.it> CC: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br> Signed-off-by: John Stultz <john.stultz@linaro.org>
1 parent 9118626 commit 83a06bf

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

‎drivers/rtc/class.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
143143
rtc->id = id;
144144
rtc->ops = ops;
145145
rtc->owner = owner;
146+
rtc->irq_freq = 1;
146147
rtc->max_user_freq = 64;
147148
rtc->dev.parent = dev;
148149
rtc->dev.class = rtc_class;

‎drivers/rtc/interface.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
464464
int err = 0;
465465
unsigned long flags;
466466

467+
if (freq <= 0)
468+
return -EINVAL;
469+
467470
spin_lock_irqsave(&rtc->irq_task_lock, flags);
468471
if (rtc->irq_task != NULL && task == NULL)
469472
err = -EBUSY;

0 commit comments

Comments
 (0)