From: Clemens Ladisch <clemens@ladisch.de>
To: Scotty Bauer <sbauer@eng.utah.edu>, linux-kernel@vger.kernel.org
Subject: Re: Compat sysinfo syscall (kernel/sys.c) relying on undefined behavior?
Date: Wed, 03 Sep 2014 09:13:12 +0200 [thread overview]
Message-ID: <5406BF88.8040102@ladisch.de> (raw)
In-Reply-To: <54062A22.6090804@eng.utah.edu>
Scotty Bauer wrote:
> In the compat version of sysinfo, kernel/sys.c we see the following:
>
> /* Check to see if any memory value is too large for 32-bit and scale
> * down if needed
> */
> if ((s.totalram >> 32) || (s.totalswap >> 32)) {
This code is supposed to check if any of the bits in the upper half of
these 64-bit values are set.
> s.totalram is a u32
Oops.
> the behavior is undefined.
For a constant shift amount, gcc happens to generate correct code, i.e.,
the result is zero. (If the shift amount were not a constant, x86
processors would use only its lowest five bits, and the result would be
wrong.)
Anyway, it's not a good idea to rely on gcc's implementation of this
undefined behaviour; the code should have used upper_32_bits() instead.
Please write a patch.
Regards,
Clemens
prev parent reply other threads:[~2014-09-03 7:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 20:35 Compat sysinfo syscall (kernel/sys.c) relying on undefined behavior? Scotty Bauer
2014-09-03 7:13 ` Clemens Ladisch [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=5406BF88.8040102@ladisch.de \
--to=clemens@ladisch.de \
--cc=linux-kernel@vger.kernel.org \
--cc=sbauer@eng.utah.edu \
/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.