From: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
To: <john.stultz@linaro.org>, <tglx@linutronix.de>,
<sboyd@kernel.org>, <zhangxiaoxu5@huawei.com>,
<linux-kernel@vger.kernel.org>
Subject: [PATCH] time: Validate the usec before covert to nsec in do_adjtimex
Date: Mon, 8 Jul 2019 15:55:04 +0800 [thread overview]
Message-ID: <1562572504-142115-1-git-send-email-zhangxiaoxu5@huawei.com> (raw)
When covert the usec to nsec, it will multiple 1000, it maybe
overflow and lead an undefined behavior.
For example, users may input an negative tv_usec values when
call adjtimex syscall, then multiple 1000 maybe overflow it
to a positive and legal number.
So, we should validate the usec before coverted it to nsec.
Signed-off-by: ZhangXiaoxu <zhangxiaoxu5@huawei.com>
---
kernel/time/timekeeping.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 44b726b..e5c1d00 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -1272,9 +1272,6 @@ static int timekeeping_inject_offset(const struct timespec64 *ts)
struct timespec64 tmp;
int ret = 0;
- if (ts->tv_nsec < 0 || ts->tv_nsec >= NSEC_PER_SEC)
- return -EINVAL;
-
raw_spin_lock_irqsave(&timekeeper_lock, flags);
write_seqcount_begin(&tk_core.seq);
@@ -2321,6 +2318,9 @@ int do_adjtimex(struct __kernel_timex *txc)
if (txc->modes & ADJ_SETOFFSET) {
struct timespec64 delta;
+
+ if (txc->time.tv_usec < 0 || txc->time.tv_usec >= USEC_PER_SEC)
+ return -EINVAL;
delta.tv_sec = txc->time.tv_sec;
delta.tv_nsec = txc->time.tv_usec;
if (!(txc->modes & ADJ_NANO))
--
2.7.4
next reply other threads:[~2019-07-08 7:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-08 7:55 ZhangXiaoxu [this message]
2019-07-08 9:24 ` Thomas Gleixner
2019-07-08 10:42 ` zhangxiaoxu (A)
2019-07-08 16:39 ` Richard Cochran
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=1562572504-142115-1-git-send-email-zhangxiaoxu5@huawei.com \
--to=zhangxiaoxu5@huawei.com \
--cc=john.stultz@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sboyd@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®