* [PATCH] linux/bitmap.h: fix potential sign-extension overflow
@ 2019-10-15 18:46 Gustavo A. R. Silva
2019-10-15 19:44 ` Joe Perches
0 siblings, 1 reply; 2+ messages in thread
From: Gustavo A. R. Silva @ 2019-10-15 18:46 UTC (permalink / raw)
To: William Breathitt Gray, Andrew Morton, Stephen Rothwell
Cc: linux-kernel, Gustavo A. R. Silva
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.
Addresses-Coverity: 1487071 ("Bad bit shift operation")
Fixes: d33f5cbaadd8 ("bitops: introduce the for_each_set_clump8 macro")
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
include/linux/bitmap.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 942871bfe47e..96f91db25b06 100644
--- 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);
map[index] |= value << offset;
}
--
2.23.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] linux/bitmap.h: fix potential sign-extension overflow
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
0 siblings, 0 replies; 2+ messages in thread
From: Joe Perches @ 2019-10-15 19:44 UTC (permalink / raw)
To: Gustavo A. R. Silva, William Breathitt Gray, Andrew Morton,
Stephen Rothwell
Cc: linux-kernel
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-10-15 19:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).