* [PATCH] alarmtimers: verify the alarmtimer_type value from clock2alarm()
@ 2014-07-08 8:49 Hyogi Gim
2014-07-08 9:50 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Hyogi Gim @ 2014-07-08 8:49 UTC (permalink / raw)
To: John Stultz, KOSAKI Motohiro; +Cc: Thomas Gleixner, linux-kernel, Hyogi Gim
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(-)
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);
--
1.8.3.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] alarmtimers: verify the alarmtimer_type value from clock2alarm()
2014-07-08 8:49 [PATCH] alarmtimers: verify the alarmtimer_type value from clock2alarm() Hyogi Gim
@ 2014-07-08 9:50 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2014-07-08 9:50 UTC (permalink / raw)
To: Hyogi Gim; +Cc: John Stultz, KOSAKI Motohiro, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-07-08 9:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-08 8:49 [PATCH] alarmtimers: verify the alarmtimer_type value from clock2alarm() Hyogi Gim
2014-07-08 9:50 ` Thomas Gleixner
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.