public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RTC: Prevents a division by zero in kernel code.
@ 2011-02-02 18:04 Marcelo Roberto Jimenez
  2011-02-02 20:34 ` John Stultz
  0 siblings, 1 reply; 2+ messages in thread
From: Marcelo Roberto Jimenez @ 2011-02-02 18:04 UTC (permalink / raw)
  To: mroberto, a.zummo, john.stultz; +Cc: rtc-linux, linux-kernel

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.

Signed-off-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>
---
 drivers/rtc/interface.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 925006d..a0c0196 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -464,6 +464,9 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
 	int err = 0;
 	unsigned long flags;
 
+	if (freq <= 0)
+		return -EINVAL;
+
 	spin_lock_irqsave(&rtc->irq_task_lock, flags);
 	if (rtc->irq_task != NULL && task == NULL)
 		err = -EBUSY;
-- 
1.7.3.4


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] RTC: Prevents a division by zero in kernel code.
  2011-02-02 18:04 [PATCH] RTC: Prevents a division by zero in kernel code Marcelo Roberto Jimenez
@ 2011-02-02 20:34 ` John Stultz
  0 siblings, 0 replies; 2+ messages in thread
From: John Stultz @ 2011-02-02 20:34 UTC (permalink / raw)
  To: Marcelo Roberto Jimenez, Thomas Gleixner; +Cc: a.zummo, rtc-linux, linux-kernel

On Wed, 2011-02-02 at 16:04 -0200, Marcelo Roberto Jimenez wrote:
> 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.
> 
> Signed-off-by: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>

Probably need to also initialize irq_freq to 1 on rtc_device_register so
we don't trip over the divbyzero on rtc devices that don't initialize
that value.

I'll add that and fwd on your patch!

Great catch!

thanks
-john

> ---
>  drivers/rtc/interface.c |    3 +++
>  1 files changed, 3 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
> index 925006d..a0c0196 100644
> --- a/drivers/rtc/interface.c
> +++ b/drivers/rtc/interface.c
> @@ -464,6 +464,9 @@ int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
>  	int err = 0;
>  	unsigned long flags;
> 
> +	if (freq <= 0)
> +		return -EINVAL;
> +
>  	spin_lock_irqsave(&rtc->irq_task_lock, flags);
>  	if (rtc->irq_task != NULL && task == NULL)
>  		err = -EBUSY;



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-02-02 20:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-02-02 18:04 [PATCH] RTC: Prevents a division by zero in kernel code Marcelo Roberto Jimenez
2011-02-02 20:34 ` John Stultz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox