From: Andy Lutomirski <luto@amacapital.net>
To: John Stultz <john.stultz@linaro.org>,
lkml <linux-kernel@vger.kernel.org>
Cc: Sasha Levin <sasha.levin@oracle.com>,
Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, stable <stable@vger.kernel.org>
Subject: Re: [PATCH 1/2] time: settimeofday: Validate the values of tv from user
Date: Fri, 02 Jan 2015 20:06:54 -0800 [thread overview]
Message-ID: <54A76ADE.5070305@amacapital.net> (raw)
In-Reply-To: <1420228268-2161-2-git-send-email-john.stultz@linaro.org>
On 01/02/2015 11:51 AM, John Stultz wrote:
> From: Sasha Levin <sasha.levin@oracle.com>
>
> 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 <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: stable <stable@vger.kernel.org>
> Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
> Signed-off-by: John Stultz <john.stultz@linaro.org>
> ---
> include/linux/time.h | 13 +++++++++++++
> kernel/time/time.c | 4 ++++
> 2 files changed, 17 insertions(+)
>
> diff --git a/include/linux/time.h b/include/linux/time.h
> index 8c42cf8..7a10ec1 100644
> --- a/include/linux/time.h
> +++ b/include/linux/time.h
> @@ -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 miliseconds then a second */
Trivial nit: that should be "microseconds".
--Andy
> + 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())
> diff --git a/kernel/time/time.c b/kernel/time/time.c
> index a9ae20f..22d5d3b 100644
> --- a/kernel/time/time.c
> +++ b/kernel/time/time.c
> @@ -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;
> }
>
next prev parent reply other threads:[~2015-01-03 4:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-02 19:51 [PATCH 0/2] time: tip/timers/urgent: Validate potential mult overflows John Stultz
2015-01-02 19:51 ` [PATCH 1/2] time: settimeofday: Validate the values of tv from user John Stultz
2015-01-03 4:06 ` Andy Lutomirski [this message]
2015-01-02 19:51 ` [PATCH 2/2] time: adjtimex: Validate the ADJ_FREQUENCY values John Stultz
-- strict thread matches above, loose matches on Subject: below --
2015-01-07 18:12 [PATCH v2 0/2] time: tip/timers/urgent: Validate potential mult overflows John Stultz
2015-01-07 18:12 ` [PATCH 1/2] time: settimeofday: Validate the values of tv from user John Stultz
2015-01-07 18:28 ` Greg KH
2015-01-07 19:02 ` John Stultz
2015-01-07 19:04 ` Sasha Levin
2015-01-07 19:09 ` Greg KH
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=54A76ADE.5070305@amacapital.net \
--to=luto@amacapital.net \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=sasha.levin@oracle.com \
--cc=stable@vger.kernel.org \
--cc=tglx@linutronix.de \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.