mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Yury Norov <yury.norov@gmail.com>
Cc: Alexander Potapenko <glider@google.com>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Syed Nayyar Waris <syednwaris@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	kernel test robot <lkp@intel.com>,
	<oe-kbuild-all@lists.linux.dev>,
	<linux-hardening@vger.kernel.org>,
	"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: Wed, 8 Nov 2023 13:28:52 +0100	[thread overview]
Message-ID: <2a1d3097-b8e7-4007-b98b-5b111c4b7702@intel.com> (raw)
In-Reply-To: <ZUqPAZC4sS455xtx@yury-ThinkPad>

From: Yury Norov <yury.norov@gmail.com>
Date: Tue, 7 Nov 2023 11:24:49 -0800

> On Tue, Nov 07, 2023 at 07:52:19PM +0100, Alexander Lobakin wrote:
>> From: Yury Norov <yury.norov@gmail.com>
>> Date: Tue, 7 Nov 2023 10:32:06 -0800
>>
>>> On Tue, Nov 07, 2023 at 06:24:04PM +0100, Alexander Lobakin wrote:
>>>> From: Alexander Lobakin <aleksander.lobakin@intel.com>
>>>> Date: Tue, 7 Nov 2023 17:44:00 +0100
>>>>
>>>>> From: Alexander Potapenko <glider@google.com>
>>>>> Date: Tue, 7 Nov 2023 17:33:56 +0100
>>>>>
>>>>>> On Tue, Nov 7, 2023 at 2:23 PM Alexander Lobakin
>>>>>> <aleksander.lobakin@intel.com> wrote:
>>>>
>>>> [...]
>>>>
>>>>> I tested it on GCC 9 using modified make.cross from lkp and it triggers
>>>>> on one more file:
>>>>>
>>>>> drivers/thermal/intel/intel_soc_dts_iosf.c: In function 'sys_get_curr_temp':
>>>>> ./include/linux/bitmap.h:601:18: error: array subscript [1,
>>>>> 288230376151711744] is outside array bounds of 'long unsigned int[1]'
>>>>> [-Werror=array-bounds]
>>>>>
>>>>>> to give the compiler some hints about the range of values passed to
>>>>>> bitmap_write() rather than suppressing the optimizations.
>>>>>
>>>>> OPTIMIZER_HIDE_VAR() doesn't disable optimizations if I get it
>>>>> correctly, rather shuts up the compiler in cases like this one.
>>>>>
>>>>> I've been thinking of using __member_size() from fortify-string.h, we
>>>>> could probably optimize the object code even a bit more while silencing
>>>>> this warning.
>>>>> Adding Kees, maybe he'd like to participate in sorting this out as well.
>>>>
>>>> This one seems to work. At least previously mad GCC 9.3.0 now sits
>>>> quietly, as if I added OPTIMIZER_HIDE_VAR() as Yury suggested.
>>>  
>>> What's wrong with OPTIMIZER_HIDE_VAR()? The problem is clearly on GCC
>>> side, namely - it doesn't realize that the map[index+1] fetch is
>>> conditional.
>>
>> It's totally fine for me to use it, this one is just an alternative
>> (well, a bit broken as per below).
> 
> OK, guys, that's even worse. The 12 and 13 don't fire the warning
> because Warray-bounds is explicitly disabled for gcc-11+. Check
> 0da6e5fd6c372 ("gcc: disable '-Warray-bounds' for gcc-13 too"). I'll
> test how gcc-10 builds it, and if it's broken too, it's worth to shift
> the threshold in init/Kconfig.

OPTIMIZER_HIDE_VAR() silences GCC 11 on my side (`-Warray-bounds` is
enabled via KCFLAGS), but now I'm wondering if it could possibly hide
really incorrect cases like you mentioned before (reading 8 bits
starting at 60 from a 64-bit bitmap).

> 
> Let me check it later today.
> 
> [...]
> 
>> Oh you're right, I didn't think about this. Your approach seems optimal
>> unless hardening folks have anything else.
>>
>> I don't see bitmap_{read,write}() mini-series applied anywhere in your
> 
> I'll not take the code unless there are real kernel users for it. Your
> compressor is still under development AFAIK, so I'm going to pull
> bitmap_read/write with ip_tunnel series, if it comes first. 
> 
>> tree, maybe Alex could incorporate your patch into it and resubmit?
> 
> Yes, that's what I asked him to do. But let's put it on hold while I'm
> testing different compilers.

So now I feel like it's a matter of extending the Kconfig threshold like
you said. The code is clearly valid.

Alternatively, we could trigger a build bug manually when offset, width
and map size are compile-time constants and suppress it otherwise. But
sounds pretty hacky.

> 
> Thanks,
> Yury

Thanks,
Olek

  parent reply	other threads:[~2023-11-08 12:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <202310170708.fJzLlgDM-lkp@intel.com>
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 [this message]
2023-11-07 23:25           ` Kees Cook
2023-11-08  0:48             ` Yury Norov
2023-11-07 13:22   ` Yury Norov

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=2a1d3097-b8e7-4007-b98b-5b111c4b7702@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=glider@google.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@intel.com \
    --cc=oe-kbuild-all@lists.linux.dev \
    --cc=syednwaris@gmail.com \
    --cc=yury.norov@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

all inboxes | Powered by JetHome®