mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <linux@roeck-us.net>
To: "Gustavo A. R. Silva" <gustavo@embeddedor.com>,
	Kees Cook <keescook@chromium.org>,
	Jim Cromie <jim.cromie@gmail.com>
Cc: Jean Delvare <jdelvare@suse.com>,
	linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org
Subject: Re: [PATCH] hwmon: (pc87360) Bounds check data->innr usage
Date: Thu, 30 Nov 2023 12:31:26 -0800	[thread overview]
Message-ID: <43effb57-abbd-46bb-ac7d-cab9616a4532@roeck-us.net> (raw)
In-Reply-To: <cdc00899-cf44-44dd-b708-6cf7dc4b8375@embeddedor.com>

On 11/30/23 12:11, Gustavo A. R. Silva wrote:
> 
> 
> On 11/30/23 14:02, Kees Cook wrote:
>> Without visibility into the initializers for data->innr, GCC suspects
>> using it as an index could walk off the end of the various 14-element
>> arrays in data. Perform an explicit clamp to the array size. Silences
>> the following warning with GCC 12+:
>>
>> ../drivers/hwmon/pc87360.c: In function 'pc87360_update_device':
>> ../drivers/hwmon/pc87360.c:341:49: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=]
>>    341 |                                 data->in_max[i] = pc87360_read_value(data,
>>        |                                 ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
>>    342 |                                                   LD_IN, i,
>>        |                                                   ~~~~~~~~~
>>    343 |                                                   PC87365_REG_IN_MAX);
>>        |                                                   ~~~~~~~~~~~~~~~~~~~
>> ../drivers/hwmon/pc87360.c:209:12: note: at offset 255 into destination object 'in_max' of size 14
>>    209 |         u8 in_max[14];          /* Register value */
>>        |            ^~~~~~
>>
>> Cc: Jim Cromie <jim.cromie@gmail.com>
>> Cc: Jean Delvare <jdelvare@suse.com>
>> Cc: Guenter Roeck <linux@roeck-us.net>
>> Cc: linux-hwmon@vger.kernel.org
>> Signed-off-by: Kees Cook <keescook@chromium.org>
> 
> Looks good to me.
> 
> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> 

Guess I'll apply it, even though it is quite pointless. But arguing against
such changes seems like shouting into the wind, so whatever.

There are several other similar "unchecked" loops, including loops for
fannr and tempnr. The driver would misbehave badly if any of those would
ever be outside the valid range, both when accessing the hardware and
writing into various arrays.

Guenter


      reply	other threads:[~2023-11-30 20:31 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 20:02 Kees Cook
2023-11-30 20:11 ` Gustavo A. R. Silva
2023-11-30 20:31   ` Guenter Roeck [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=43effb57-abbd-46bb-ac7d-cab9616a4532@roeck-us.net \
    --to=linux@roeck-us.net \
    --cc=gustavo@embeddedor.com \
    --cc=jdelvare@suse.com \
    --cc=jim.cromie@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-hwmon@vger.kernel.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 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®