public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Scotty Bauer <sbauer@eng.utah.edu>
To: linux-kernel@vger.kernel.org
Subject: Compat sysinfo syscall (kernel/sys.c) relying on undefined behavior?
Date: Tue, 02 Sep 2014 14:35:46 -0600	[thread overview]
Message-ID: <54062A22.6090804@eng.utah.edu> (raw)

 am getting acquainted with the linux kernel and to do so I've been browsing the source.


In the compat version of sysinfo, kernel/sys.c we see the following:

COMPAT_SYSCALL_DEFINE1(sysinfo, struct compat_sysinfo __user *, info)
{
    struct sysinfo s;

    do_sysinfo(&s);

    /* 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)) {
        int bitcount = 0;

...


s.totalram is a u32, and the standard says:
"If the value of the right operand is negative or is greater than or equal to the width 
of the promoted left operand, the behavior is undefined."

Is there some promotion, compiler flag, something obvious that I am missing, or is this a 
problem?


Best,
Scotty


             reply	other threads:[~2014-09-02 21:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-02 20:35 Scotty Bauer [this message]
2014-09-03  7:13 ` Compat sysinfo syscall (kernel/sys.c) relying on undefined behavior? Clemens Ladisch

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=54062A22.6090804@eng.utah.edu \
    --to=sbauer@eng.utah.edu \
    --cc=linux-kernel@vger.kernel.org \
    /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