time: tip/timers/urgent: Validate potential mult overflows
Subsystems (2)
v2 cover time: tip/timers/urgent: Validate potential mult overflows
Hey Ingo, Thomas,
Here are two mult overflow validation fixes from Sasha for
tip/timers/urgent that I didn't manage to send out before the holidays.
For v2 I've added the mili->micro fix Andy noticed.
Let me know if you have any objections.
thanks
-john
If you want, they can be pulled via:
The following changes since commit b2776bf7149bddd1f4161f14f79520f17fc1d71d:
Linux 3.18 (2014-12-07 14:21:05 -0800)
are available in the git repository at:
https://git.linaro.org/people/john.stultz/linux.git fortglx/3.19-stable/time
for you to fetch changes up to 5e5aeb4367b450a28f447f6d5ab57d8f2ab16a5f:
time: adjtimex: Validate the ADJ_FREQUENCY values (2015-01-07 09:50:32 -0800)
----------------------------------------------------------------
Sasha Levin (2):
time: settimeofday: Validate the values of tv from user
time: adjtimex: Validate the ADJ_FREQUENCY values
include/linux/time.h | 13 +++++++++++++ kernel/time/ntp.c | 7 +++++++ kernel/time/time.c | 4 ++++ 3 files changed, 24 insertions(+)
Signature · 1 line
1.9.1
PATCH v2 1/2 time: settimeofday: Validate the values of tv from user
From: Sasha Levin <[email protected]>
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour.
[jstultz: include trivial milisecond->microsecond correction noticed by Andy]
--- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+)
include/linux/time.h +13 -0
@@ -99,6 +99,19 @@ static inline bool timespec_valid_strict(const struct timespec *ts)return true; } +static inline bool timeval_valid (const struct timeval *tv) +{ +/* Dates before 1970 are bogus */ +if (tv->tv_sec <0 ) +return false; + +/* Can't have more microseconds then a second */ +if (tv->tv_usec <0 || tv->tv_usec >=USEC_PER_SEC ) +return false; + +return true; +} +extern struct timespec timespec_trunc (struct timespec t,unsigned gran);#define CURRENT_TIME (current_kernel_time())
kernel/time/time.c +4 -0
@@ -196,6 +196,10 @@ SYSCALL_DEFINE2(settimeofday, struct timeval __user *, tv,if (tv) {if (copy_from_user (&user_tv, tv,sizeof (*tv)))return -EFAULT ; + +if (!timeval_valid (&user_tv)) +return -EINVAL ; + new_ts.tv_sec = user_tv.tv_sec; new_ts.tv_nsec = user_tv.tv_usec *NSEC_PER_USEC ; }
Signature · 1 line
1.9.1
Re: [PATCH 1/2] time: settimeofday: Validate the values of tv from user
Quoted 11 lines · John Stultz
From: Sasha Levin <[email protected]>
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour.
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc stable <[email protected]>Cc Andy Lutomirski <[email protected]>Signed-off-by Sasha Levin <[email protected]>
Quoted 7 lines
[jstultz: include trivial
milisecond->microsecondcorrection noticed by Andy]Signed-off-by John Stultz <[email protected]>--- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.
</formletter>
Re: [PATCH 1/2] time: settimeofday: Validate the values of tv from user
Quoted 20 lines · Greg KH
Quoted 11 lines · John Stultz
From: Sasha Levin <[email protected]>
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour.
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc stable <[email protected]>Cc Andy Lutomirski <[email protected]>Signed-off-by Sasha Levin <[email protected]>Quoted 7 lines
[jstultz: include trivial
milisecond->microsecondcorrection noticed by Andy]Signed-off-by John Stultz <[email protected]>--- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+)
Quoted 7 lines
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read
Documentation/stable_kernel_rules.txtfor how to do this properly.</formletter>
Hrm. I'm not quite sure which rule I'm running afoul here.
Does this seem too much like a theoretical issue and not like enough of a "oh, that's not good" issue?
thanks
-john
Re: [PATCH 1/2] time: settimeofday: Validate the values of tv from user
Quoted 27 lines · John Stultz
Quoted 26 lines · Greg KH
Quoted 11 lines · John Stultz
From: Sasha Levin <[email protected]>
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour.
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc stable <[email protected]>Cc Andy Lutomirski <[email protected]>Signed-off-by Sasha Levin <[email protected]>Quoted 7 lines
[jstultz: include trivial
milisecond->microsecondcorrection noticed by Andy]Signed-off-by John Stultz <[email protected]>--- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+)<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read
Documentation/stable_kernel_rules.txtfor how to do this properly.
Quoted 6 lines
Quoted 1 line
</formletter>
Hrm. I'm not quite sure which rule I'm running afoul here.
Does this seem too much like a theoretical issue and not like enough of a "oh, that's not good" issue?
I suspect it's something more like "Cc: stable <[email protected]>" vs "Cc: [email protected]", but not really sure.
Thanks,
Sasha
Re: [PATCH 1/2] time: settimeofday: Validate the values of tv from user
In reply to John StultzQuoted 27 lines · John Stultz
Quoted 26 lines · Greg KH
Quoted 11 lines · John Stultz
From: Sasha Levin <[email protected]>
An unvalidated user input is multiplied by a constant, which can result in an undefined behaviour for large values. While this is validated later, we should avoid triggering undefined behaviour.
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc stable <[email protected]>Cc Andy Lutomirski <[email protected]>Signed-off-by Sasha Levin <[email protected]>Quoted 7 lines
[jstultz: include trivial
milisecond->microsecondcorrection noticed by Andy]Signed-off-by John Stultz <[email protected]>--- include/linux/time.h | 13 +++++++++++++ kernel/time/time.c | 4 ++++ 2 files changed, 17 insertions(+)<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read
Documentation/stable_kernel_rules.txtfor how to do this properly.
Quoted 6 lines
Quoted 1 line
</formletter>
Hrm. I'm not quite sure which rule I'm running afoul here.
Does this seem too much like a theoretical issue and not like enough of a "oh, that's not good" issue?
No, crap, my fault, I messed up on these, you are doing this just fine, I'm not awake this morning...
/me goes off to get more coffee.
greg k-h
PATCH v2 2/2 time: adjtimex: Validate the ADJ_FREQUENCY values
In reply to John StultzFrom: Sasha Levin <[email protected]>
Verify that the frequency value from userspace is valid and makes sense.
Unverified values can cause overflows later on.
--- kernel/time/ntp.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/time/ntp.c +7 -0
@@ -633,6 +633,13 @@ int ntp_validate_timex(struct timex *txc)if ((txc->modes &ADJ_SETOFFSET ) && (!capable (CAP_SYS_TIME )))return -EPERM ; +if (txc->modes &ADJ_FREQUENCY ) { +if (LONG_MIN /PPM_SCALE > txc->freq) +return -EINVAL ; +if (LONG_MAX /PPM_SCALE < txc->freq) +return -EINVAL ; + } +return 0 ; }
Signature · 1 line
1.9.1
Greg KH
maintainerRe: [PATCH 2/2] time: adjtimex: Validate the ADJ_FREQUENCY values
Quoted 13 lines · John Stultz
From: Sasha Levin <[email protected]>
Verify that the frequency value from userspace is valid and makes sense.
Unverified values can cause overflows later on.
Cc Thomas Gleixner <[email protected]>Cc Ingo Molnar <[email protected]>Cc stable <[email protected]>Cc Andy Lutomirski <[email protected]>Signed-off-by Sasha Levin <[email protected]>[jstultz: Fix up bug for negative values and drop redunent cap check]Signed-off-by John Stultz <[email protected]>
Quoted 3 lines
--- kernel/time/ntp.c | 7 +++++++ 1 file changed, 7 insertions(+)
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.
</formletter>
Quoted 8 lines · John Stultz
Hey Ingo, Thomas,
Here are two mult overflow validation fixes from Sasha for
tip/timers/urgent that I didn't manage to send out before the holidays.For v2 I've added the
mili->microfix Andy noticed.Let me know if you have any objections.
Thomas, Ingo,
Just wanted to ping you here, since I've not seen any feedback here.
thanks
-john
Quoted 3 lines · John Stultz
On Wed, Jan 7, 2015 at 10:12 AM, John Stultz <[email protected]> wrote:
Thomas, Ingo,
Just wanted to ping you here, since I've not seen any feedback here.
Got caught in my huge backlog. Processing right now.
Thanks,
tglx