LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: John Stultz <john.stultz@linaro.org>
To: linux-kernel@vger.kernel.org
Cc: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Thomas Gleixner <tglx@linutronix.de>,
	John Stultz <john.stultz@linaro.org>
Subject: [PATCH 1/4] RTC: Prevents a division by zero in kernel code.
Date: Wed,  2 Feb 2011 18:14:40 -0800	[thread overview]
Message-ID: <1296699283-6784-2-git-send-email-john.stultz@linaro.org> (raw)
In-Reply-To: <1296699283-6784-1-git-send-email-john.stultz@linaro.org>

From: Marcelo Roberto Jimenez <mroberto@cpti.cetuc.puc-rio.br>

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>
---
 drivers/rtc/class.c     |    1 +
 drivers/rtc/interface.c |    3 +++
 2 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 9583cbc..c404b61 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -143,6 +143,7 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
 	rtc->id = id;
 	rtc->ops = ops;
 	rtc->owner = owner;
+	rtc->irq_freq = 1;
 	rtc->max_user_freq = 64;
 	rtc->dev.parent = dev;
 	rtc->dev.class = rtc_class;
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.2.146.gca209


  reply	other threads:[~2011-02-03  2:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-03  2:14 [PATCH 0/4] RTC regression fixups John Stultz
2011-02-03  2:14 ` John Stultz [this message]
2011-02-03  2:14 ` [PATCH 2/4] RTC: Fix rtc driver ioctl specific shortcutting John Stultz
2011-02-03  8:43   ` Wolfram Sang
2011-02-03 19:01     ` John Stultz
2011-02-03  2:14 ` [PATCH 3/4] RTC: Convert rtc drivers to use the alarm_irq_enable method John Stultz
2011-02-03  2:14 ` [PATCH 4/4] RTC: Fix minor compile warning John Stultz
2011-02-03 17:30 ` [PATCH 0/4] RTC regression fixups Marcelo Roberto Jimenez
2011-02-03 19:16   ` John Stultz
2011-02-03 20:31     ` Marcelo Roberto Jimenez
2011-02-03 21:37       ` John Stultz
2011-02-03 22:27         ` john stultz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296699283-6784-2-git-send-email-john.stultz@linaro.org \
    --to=john.stultz@linaro.org \
    --cc=a.zummo@towertech.it \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mroberto@cpti.cetuc.puc-rio.br \
    --cc=tglx@linutronix.de \
    --subject='Re: [PATCH 1/4] RTC: Prevents a division by zero in kernel code.' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).