public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Boris Ostrovsky <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@kernel.org,
	konrad.wilk@oracle.com, boris.ostrovsky@oracle.com,
	tglx@linutronix.de
Subject: [tip:x86/urgent] x86, vdso, time: Cast tv_nsec to u64 for proper shifting in update_vsyscall()
Date: Fri, 9 May 2014 09:31:40 -0700	[thread overview]
Message-ID: <tip-28b92e09e25bdc0ae864b22eacf195a74f861389@git.kernel.org> (raw)
In-Reply-To: <1399648287-15178-1-git-send-email-boris.ostrovsky@oracle.com>

Commit-ID:  28b92e09e25bdc0ae864b22eacf195a74f861389
Gitweb:     http://git.kernel.org/tip/28b92e09e25bdc0ae864b22eacf195a74f861389
Author:     Boris Ostrovsky <boris.ostrovsky@oracle.com>
AuthorDate: Fri, 9 May 2014 11:11:27 -0400
Committer:  H. Peter Anvin <hpa@zytor.com>
CommitDate: Fri, 9 May 2014 08:45:52 -0700

x86, vdso, time: Cast tv_nsec to u64 for proper shifting in update_vsyscall()

With tk->wall_to_monotonic.tv_nsec being a 32-bit value on 32-bit
systems, (tk->wall_to_monotonic.tv_nsec << tk->shift) in update_vsyscall()
may lose upper bits or, worse, add them since compiler will do this:
	(u64)(tk->wall_to_monotonic.tv_nsec << tk->shift)
instead of
	((u64)tk->wall_to_monotonic.tv_nsec << tk->shift)

So if, for example, tv_nsec is 0x800000 and shift is 8 we will end up
with 0xffffffff80000000 instead of 0x80000000. And then we are stuck in
the subsequent 'while' loop.

We need an explicit cast.

Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Link: http://lkml.kernel.org/r/1399648287-15178-1-git-send-email-boris.ostrovsky@oracle.com
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: <stable@vger.kernel.org> # v3.14
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 arch/x86/kernel/vsyscall_gtod.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/vsyscall_gtod.c b/arch/x86/kernel/vsyscall_gtod.c
index f9c6e56..9531fbb 100644
--- a/arch/x86/kernel/vsyscall_gtod.c
+++ b/arch/x86/kernel/vsyscall_gtod.c
@@ -43,7 +43,7 @@ void update_vsyscall(struct timekeeper *tk)
 	vdata->monotonic_time_sec	= tk->xtime_sec
 					+ tk->wall_to_monotonic.tv_sec;
 	vdata->monotonic_time_snsec	= tk->xtime_nsec
-					+ (tk->wall_to_monotonic.tv_nsec
+					+ ((u64)tk->wall_to_monotonic.tv_nsec
 						<< tk->shift);
 	while (vdata->monotonic_time_snsec >=
 					(((u64)NSEC_PER_SEC) << tk->shift)) {

      parent reply	other threads:[~2014-05-09 16:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-09 15:11 [PATCH] time: Cast tv_nsec to u64 for proper shifting in update_vsyscall() Boris Ostrovsky
2014-05-09 15:43 ` H. Peter Anvin
2014-05-09 15:59   ` Boris Ostrovsky
2014-05-09 16:03     ` H. Peter Anvin
2014-05-09 16:23       ` Boris Ostrovsky
2014-05-09 16:31 ` tip-bot for Boris Ostrovsky [this message]

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=tip-28b92e09e25bdc0ae864b22eacf195a74f861389@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=boris.ostrovsky@oracle.com \
    --cc=hpa@zytor.com \
    --cc=konrad.wilk@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@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