diff mbox

alarmtimers: verify the alarmtimer_type value from clock2alarm()

Message ID 1404809367-30207-1-git-send-email-hyogi.gim@lge.com
State New
Headers show

Commit Message

Hyogi Gim July 8, 2014, 8:49 a.m. UTC
clock2alarm() can return a minus value. so, we cannot use this
returned value for a index of an array. but, some functions use
this value directly as a index of an array:
 - alarm_clock_getres()
 - alarm_clock_get()
 - alarm_timer_create()
 - alarm_timer_nsleep()

add the verification code for the returned alarmtimer_type from
clock2alarm().

Signed-off-by: Hyogi Gim <hyogi.gim@lge.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/time/alarmtimer.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

Comments

Thomas Gleixner July 8, 2014, 9:50 a.m. UTC | #1
On Tue, 8 Jul 2014, Hyogi Gim wrote:

> clock2alarm() can return a minus value. so, we cannot use this
> returned value for a index of an array. but, some functions use
> this value directly as a index of an array:
>  - alarm_clock_getres()
>  - alarm_clock_get()
>  - alarm_timer_create()
>  - alarm_timer_nsleep()
> 
> add the verification code for the returned alarmtimer_type from
> clock2alarm().

That's really pointless.

These functions are called from the core posix timer code if user
space requests CLOCK_REALTIME_ALARM or CLOCK_BOOTTIME_ALARM. So the
argument is already validated.

Thanks,

	tglx

 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
diff mbox

Patch

diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
index 88c9c65..0b117c6 100644
--- a/kernel/time/alarmtimer.c
+++ b/kernel/time/alarmtimer.c
@@ -487,7 +487,14 @@  static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
  */
 static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
 {
-	clockid_t baseid = alarm_bases[clock2alarm(which_clock)].base_clockid;
+	enum alarmtimer_type type;
+	clockid_t baseid;
+
+	type = clock2alarm(which_clock);
+	if (type < 0)
+		return -EINVAL;
+
+	baseid = alarm_bases[type].base_clockid;
 
 	if (!alarmtimer_get_rtcdev())
 		return -EINVAL;
@@ -504,7 +511,14 @@  static int alarm_clock_getres(const clockid_t which_clock, struct timespec *tp)
  */
 static int alarm_clock_get(clockid_t which_clock, struct timespec *tp)
 {
-	struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
+	enum alarmtimer_type type;
+	struct alarm_base *base;
+
+	type = clock2alarm(which_clock);
+	if (type < 0)
+		return -EINVAL;
+
+	base = &alarm_bases[type];
 
 	if (!alarmtimer_get_rtcdev())
 		return -EINVAL;
@@ -531,6 +545,9 @@  static int alarm_timer_create(struct k_itimer *new_timer)
 		return -EPERM;
 
 	type = clock2alarm(new_timer->it_clock);
+	if (type < 0)
+		return -EINVAL;
+
 	base = &alarm_bases[type];
 	alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer);
 	return 0;
@@ -721,7 +738,7 @@  out:
 static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
 		     struct timespec *tsreq, struct timespec __user *rmtp)
 {
-	enum  alarmtimer_type type = clock2alarm(which_clock);
+	enum alarmtimer_type type;
 	struct alarm alarm;
 	ktime_t exp;
 	int ret = 0;
@@ -733,6 +750,10 @@  static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
 	if (!capable(CAP_WAKE_ALARM))
 		return -EPERM;
 
+	type = clock2alarm(which_clock);
+	if (type < 0)
+		return -EINVAL;
+
 	alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
 
 	exp = timespec_to_ktime(*tsreq);