Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1670894
| From | Thomas Gleixner <tglx@linutronix.de> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [patch 2/2] posix-cpu-timers: Make timespec to nsec conversion safe |
| Date | 2017-06-20 17:50 +0200 |
| Message-ID | <tUtzJ-238-35@gated-at.bofh.it> (permalink) |
| References | <tUtzH-238-7@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
The expiry time of a posix cpu timer is supplied through sys_timer_set() via a struct timespec. The timespec is validated for correctness. In the actual set timer implementation the timespec is converted to a scalar nanoseconds value. If the tv_sec part of the time spec is large enough the conversion to nanoseconds (sec * NSEC_PER_SEC) overflows 64bit. Mitigate that by using the timespec_to_ktime() conversion function, which checks the tv_sec part for a potential mult overflow and clamps the result to KTIME_MAX, which is about 292 years. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> --- kernel/time/posix-cpu-timers.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -572,7 +572,11 @@ static int posix_cpu_timer_set(struct k_ WARN_ON_ONCE(p == NULL); - new_expires = timespec64_to_ns(&new->it_value); + /* + * Use the to_ktime conversion because that clamps the maximum + * value to KTIME_MAX and avoid multiplication overflows. + */ + new_expires = ktime_to_ns(timespec64_to_ktime(new->it_value)); /* * Protect against sighand release/switch in exit/exec and p->cpu_timers
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[patch 0/2] timers: Prevent multiplication overflow in timespec/val conversions Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
[patch 1/2] itimer: Make timeval to nsec conversion range limited Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
[tip:timers/core] itimer: Make timeval to nsec conversion range limited tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2017-06-20 21:50 +0200
[patch 2/2] posix-cpu-timers: Make timespec to nsec conversion safe Thomas Gleixner <tglx@linutronix.de> - 2017-06-20 17:50 +0200
[tip:timers/core] posix-cpu-timers: Make timespec to nsec conversion safe tip-bot for Thomas Gleixner <tipbot@zytor.com> - 2017-06-20 21:50 +0200
csiph-web