mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: johnstul@us.ibm.com, tglx@linutronix.de, linux-kernel@vger.kernel.org
Cc: Sasha Levin <levinsasha928@gmail.com>
Subject: [PATCH 2/2] ntp: Fix integer overflow when setting time
Date: Thu, 15 Mar 2012 12:36:14 -0400	[thread overview]
Message-ID: <1331829374-31543-2-git-send-email-levinsasha928@gmail.com> (raw)
In-Reply-To: <1331829374-31543-1-git-send-email-levinsasha928@gmail.com>

'long secs' was being passed as divisor to div_s64, which accepts a 32bit
divisor. On 64bit machines that value would be trimmed back from 8 bytes
back to 4, allowing a divide by zero when the number is bigger than
(1 << 32) - 1 and all 32 lower bits are 0.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
 kernel/time/ntp.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 17fb1b9..c83c228 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -289,7 +289,11 @@ static inline s64 ntp_update_offset_fll(s64 offset64, long secs)
 
 	time_status |= STA_MODE;
 
-	return div_s64(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
+	/* 
+	 * secs is 8 bytes on 64bit systems, which means that it can
+	 * wrap around when dividing.
+	 */
+	return div64_long(offset64 << (NTP_SCALE_SHIFT - SHIFT_FLL), secs);
 }
 
 static void ntp_update_offset(long offset)
-- 
1.7.8.4


  reply	other threads:[~2012-03-15 14:36 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-03-15 16:36 [PATCH 1/2] math: Introduce div64_long Sasha Levin
2012-03-15 16:36 ` Sasha Levin [this message]
2012-03-15 21:53   ` [tip:timers/core] ntp: Fix integer overflow when setting time tip-bot for Sasha Levin
2012-03-16  1:29     ` H. Peter Anvin
2012-03-16  9:48       ` Thomas Gleixner
2012-03-16 14:42         ` H. Peter Anvin
2012-03-15 21:52 ` [tip:timers/core] math: Introduce div64_long tip-bot for Sasha Levin

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=1331829374-31543-2-git-send-email-levinsasha928@gmail.com \
    --to=levinsasha928@gmail.com \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@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 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®