From: Yury Norov <yury.norov@gmail.com>
To: Alexander Lobakin <aleksander.lobakin@intel.com>
Cc: Alexander Potapenko <glider@google.com>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Syed Nayyar Waris <syednwaris@gmail.com>,
kernel test robot <lkp@intel.com>,
oe-kbuild-all@lists.linux.dev,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [alobakin:pfcp 11/19] include/linux/bitmap.h:642:17: warning: array subscript [1, 1024] is outside array bounds of 'long unsigned int[1]'
Date: Tue, 7 Nov 2023 05:22:20 -0800 [thread overview]
Message-ID: <ZUo6DLwy5FoDkZlX@yury-ThinkPad> (raw)
In-Reply-To: <bd7fe929-c6fc-42be-9d2f-3f53ec21fd10@intel.com>
On Mon, Nov 06, 2023 at 05:31:34PM +0100, Alexander Lobakin wrote:
> BTW, I have this in my inbox:
>
> From: Kernel Test Robot <lkp@intel.com>
> Date: Tue, 17 Oct 2023 08:14:51 +0800
>
> > tree: https://github.com/alobakin/linux pfcp
> > head: 9183a3eb639912169a3d3e2be4f25556b465919b
> > commit: c8a652cdcc0964510f108726b3da0784d1bc0cd2 [11/19] bitmap: make bitmap_{get,set}_value8() use bitmap_{read,write}()
>
> So it happened after I converted bitmap_{get,set}_value8() so that they
> use bitmap_{read,write}().
>
> > config: x86_64-randconfig-004-20231017 (https://download.01.org/0day-ci/archive/20231017/202310170708.fJzLlgDM-lkp@intel.com/config)
> > compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> > reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231017/202310170708.fJzLlgDM-lkp@intel.com/reproduce)
[...]
> > 643 | map[index + 1] |= (value >> space);
> > | ^~
> > In file included from include/linux/kasan-checks.h:5,
> > from include/asm-generic/rwonce.h:26,
> > from ./arch/x86/include/generated/asm/rwonce.h:1,
> > from include/linux/compiler.h:246,
> > from include/linux/build_bug.h:5,
> > from include/linux/bits.h:21,
> > from include/linux/ioport.h:13,
> > from include/linux/acpi.h:12,
> > from drivers/gpio/gpio-pca953x.c:11:
> > drivers/gpio/gpio-pca953x.c:1032:17: note: while referencing 'val'
It looks like a gcc-9 false-positive. I tried gcc-12 and gcc-13, and
they both looks OK. Below is the fix that works for me.
Can you please test the following patch and add it to your series?
Thanks,
Yury
From 2a883221ddbd18796ddef0125e9e3022a56edd7b Mon Sep 17 00:00:00 2001
From: Yury Norov <yury.norov@gmail.com>
Date: Tue, 7 Nov 2023 05:05:17 -0800
Subject: [PATCH] bitmap: suppress false-positive -Warray-bounds in
bitmap_{read,write}
bitmap_{read,write} conditionally accesses map[index + 1], carefully
checking before that it's a safe dereference. But still, gcc-9 emits
-Warray-bounds.
Gcc-12 and gcc-13 are both OK with this code. So fix it for gcc-9 with
OPTIMIZER_HIDE_VAR().
Reported-by: Alexander Lobakin <aleksander.lobakin@intel.com>
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310170708.fJzLlgDM-lkp@intel.com/
Signed-off-by: Yury Norov <yury.norov@gmail.com>
---
include/linux/bitmap.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h
index 945a680816cc..0b1a07ff1080 100644
--- a/include/linux/bitmap.h
+++ b/include/linux/bitmap.h
@@ -592,6 +592,11 @@ static inline unsigned long bitmap_read(const unsigned long *map,
if (unlikely(!nbits || nbits > BITS_PER_LONG))
return 0;
+#if CONFIG_GCC_VERSION < 100000
+ /* Suppress gcc-9 false-positive -Warray-bounds */
+ OPTIMIZER_HIDE_VAR(map);
+#endif
+
if (space >= nbits)
return (map[index] >> offset) & BITMAP_LAST_WORD_MASK(nbits);
@@ -634,6 +639,11 @@ static inline void bitmap_write(unsigned long *map, unsigned long value,
fit = space >= nbits;
index = BIT_WORD(start);
+#if CONFIG_GCC_VERSION < 100000
+ /* Suppress gcc-9 false-positive -Warray-bounds */
+ OPTIMIZER_HIDE_VAR(map);
+#endif
+
map[index] &= (fit ? (~(mask << offset)) : ~BITMAP_FIRST_WORD_MASK(start));
map[index] |= value << offset;
if (fit)
--
2.39.2
prev parent reply other threads:[~2023-11-07 13:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 0:14 [alobakin:pfcp 11/19] include/linux/bitmap.h:642:17: warning: array subscript [1, 1024] is outside array bounds of 'long unsigned int[1]' kernel test robot
2023-11-06 16:31 ` Alexander Lobakin
2023-11-06 18:23 ` Andy Shevchenko
2023-11-07 13:21 ` Alexander Lobakin
2023-11-07 16:33 ` Alexander Potapenko
2023-11-07 16:44 ` Alexander Lobakin
2023-11-07 17:24 ` Alexander Lobakin
2023-11-07 18:32 ` Yury Norov
2023-11-07 18:52 ` Alexander Lobakin
2023-11-07 19:24 ` Yury Norov
2023-11-08 10:07 ` Alexander Potapenko
2023-11-08 12:28 ` Alexander Lobakin
2023-11-07 23:25 ` Kees Cook
2023-11-08 0:48 ` Yury Norov
2023-11-07 13:22 ` Yury Norov [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=ZUo6DLwy5FoDkZlX@yury-ThinkPad \
--to=yury.norov@gmail.com \
--cc=aleksander.lobakin@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=glider@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=oe-kbuild-all@lists.linux.dev \
--cc=syednwaris@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 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.