All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: David Howells <dhowells@redhat.com>
Cc: Colin Ian King <colin.king@canonical.com>,
	linux-afs@lists.infradead.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places
Date: Wed, 11 Apr 2018 18:58:12 +0300	[thread overview]
Message-ID: <20180411155811.2qznymjhi6zlzgbb@mwanda> (raw)
In-Reply-To: <24493.1523455816@warthog.procyon.org.uk>

On Wed, Apr 11, 2018 at 03:10:16PM +0100, David Howells wrote:
> Colin Ian King <colin.king@canonical.com> wrote:
> 
> > >> -	mask = (1 << nr_slots) - 1;
> > >> +	mask = (1ULL << nr_slots) - 1;
> > > 
> > > nr_slots cannot be larger than 9, so what I wrote is actually fine and is
> > > more efficient on a 32-bit machine.
> > 
> > ok, sorry about the noise.
> 
> It would be possible to cast the value to u64 before assigning it, I suppose.
> Would that help?  E.g.:
> 
> 	mask = (u64)((1 << nr_slots) - 1);
> 
> It looks a bit odd, though, since the cast is made implicitly anyway.

My feeling is that makes it worse.  It would introduce a secret,
unpublished static checker warning on my build and it doesn't help me as
a reviewer.

Ideally static analyzers should know that nr_slots is 0-9, but right now
that seems pretty tricky to figure out...

regards,
dan carpenter

WARNING: multiple messages have this Message-ID (diff)
From: Dan Carpenter <dan.carpenter@oracle.com>
To: David Howells <dhowells@redhat.com>
Cc: Colin Ian King <colin.king@canonical.com>,
	linux-afs@lists.infradead.org, kernel-janitors@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places
Date: Wed, 11 Apr 2018 15:58:12 +0000	[thread overview]
Message-ID: <20180411155811.2qznymjhi6zlzgbb@mwanda> (raw)
In-Reply-To: <24493.1523455816@warthog.procyon.org.uk>

On Wed, Apr 11, 2018 at 03:10:16PM +0100, David Howells wrote:
> Colin Ian King <colin.king@canonical.com> wrote:
> 
> > >> -	mask = (1 << nr_slots) - 1;
> > >> +	mask = (1ULL << nr_slots) - 1;
> > > 
> > > nr_slots cannot be larger than 9, so what I wrote is actually fine and is
> > > more efficient on a 32-bit machine.
> > 
> > ok, sorry about the noise.
> 
> It would be possible to cast the value to u64 before assigning it, I suppose.
> Would that help?  E.g.:
> 
> 	mask = (u64)((1 << nr_slots) - 1);
> 
> It looks a bit odd, though, since the cast is made implicitly anyway.

My feeling is that makes it worse.  It would introduce a secret,
unpublished static checker warning on my build and it doesn't help me as
a reviewer.

Ideally static analyzers should know that nr_slots is 0-9, but right now
that seems pretty tricky to figure out...

regards,
dan carpenter


  parent reply	other threads:[~2018-04-11 15:58 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-11 13:26 [PATCH][next] afs: fix integer overflow when shifting 1 more than 32 places Colin King
2018-04-11 13:26 ` Colin King
2018-04-11 13:39 ` David Howells
2018-04-11 13:39   ` David Howells
2018-04-11 13:42   ` Colin Ian King
2018-04-11 13:42     ` Colin Ian King
2018-04-11 14:10   ` David Howells
2018-04-11 14:10     ` David Howells
2018-04-11 14:17     ` Colin Ian King
2018-04-11 14:17       ` Colin Ian King
2018-04-11 15:58     ` Dan Carpenter [this message]
2018-04-11 15:58       ` Dan Carpenter
2018-04-11 16:03     ` David Howells
2018-04-11 16:03       ` David Howells

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=20180411155811.2qznymjhi6zlzgbb@mwanda \
    --to=dan.carpenter@oracle.com \
    --cc=colin.king@canonical.com \
    --cc=dhowells@redhat.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --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 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.