linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	William Breathitt Gray <vilhelm.gray@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	Stephen Rothwell <sfr@canb.auug.org.au>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] linux/bitmap.h: fix potential sign-extension overflow
Date: Tue, 15 Oct 2019 12:44:52 -0700	[thread overview]
Message-ID: <5695bc78caf94d21b760960d4c1a34411cb4cb81.camel@perches.com> (raw)
In-Reply-To: <20191015184657.GA26541@embeddedor>

On Tue, 2019-10-15 at 13:46 -0500, Gustavo A. R. Silva wrote:
> In expression 0xff << offset, left shifting by more than 31 bits has
> undefined behavior. Notice that the shift amount, *offset*, can be as
> much as 63.
> 
> Fix this by adding suffix ULL to integer 0xFF.
[]
> diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
[]
> @@ -520,7 +520,7 @@ static inline void bitmap_set_value8(unsigned long *map, unsigned long value,
>  	const size_t index = BIT_WORD(start);
>  	const unsigned long offset = start % BITS_PER_LONG;
>  
> -	map[index] &= ~(0xFF << offset);
> +	map[index] &= ~(0xFFULL << offset);

BITS_PER_LONG is 32 and 0xFFULL is 64 bit
when compiled for 32 bit arches.

This should just be 0xFFUL and not ULL.



      reply	other threads:[~2019-10-15 19:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 18:46 [PATCH] linux/bitmap.h: fix potential sign-extension overflow Gustavo A. R. Silva
2019-10-15 19:44 ` Joe Perches [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=5695bc78caf94d21b760960d4c1a34411cb4cb81.camel@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=gustavo@embeddedor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    --cc=vilhelm.gray@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).