From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Benson Leung <bleung@chromium.org>,
Guenter Roeck <groeck@chromium.org>,
chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] platform/chrome: Fix -Warray-bounds warnings
Date: Thu, 14 Dec 2023 08:37:13 -0800 [thread overview]
Message-ID: <202312140836.5AB528D54F@keescook> (raw)
In-Reply-To: <ZCTrutoN+9TiJM8u@work>
On Wed, Mar 29, 2023 at 07:54:02PM -0600, Gustavo A. R. Silva wrote:
> GCC-13 (and Clang) does not like having a partially allocated object,
> since it cannot reason about it for bounds checking.
>
> Notice that the compiler is legitimately complaining about accessing
> an object (params, in this case) for which not enough memory was
> allocated.
>
> The object is of size 20 bytes:
>
> struct ec_params_vbnvcontext {
> uint32_t op; /* 0 4 */
> uint8_t block[16]; /* 4 16 */
>
> /* size: 20, cachelines: 1, members: 2 */
> /* last cacheline: 20 bytes */
> };
>
> but only 16 bytes are allocated:
>
> sizeof(struct ec_response_vbnvcontext) == 16
>
> In this case, as only enough space for the op field is allocated,
> we can use an object of type uint32_t instead of a whole
> struct ec_params_vbnvcontext (for which not enough memory is
> allocated).
>
> Fix the following warning seen under GCC 13:
> drivers/platform/chrome/cros_ec_vbc.c: In function ‘vboot_context_read’:
> drivers/platform/chrome/cros_ec_vbc.c:36:15: warning: array subscript ‘struct ec_params_vbnvcontext[1]’ is partly outside array bounds of ‘unsigned char[36]’ [-Warray-bounds=]
> 36 | params->op = EC_VBNV_CONTEXT_OP_READ;
> | ^~
> In file included from drivers/platform/chrome/cros_ec_vbc.c:12:
> In function ‘kmalloc’,
> inlined from ‘vboot_context_read’ at drivers/platform/chrome/cros_ec_vbc.c:30:8:
> ./include/linux/slab.h:580:24: note: at offset 20 into object of size 36 allocated by ‘kmalloc_trace’
> 580 | return kmalloc_trace(
> | ^~~~~~~~~~~~~~
> 581 | kmalloc_caches[kmalloc_type(flags)][index],
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 582 | flags, size);
> | ~~~~~~~~~~~~
>
> Link: https://github.com/KSPP/linux/issues/278
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
FWIW, I think this is the right change that disrupts the code the least.
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
next prev parent reply other threads:[~2023-12-14 16:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 1:54 [PATCH][next] platform/chrome: Fix -Warray-bounds warnings Gustavo A. R. Silva
2023-03-30 7:01 ` Tzung-Bi Shih
2023-03-30 7:11 ` Greg KH
2023-03-30 20:44 ` Gustavo A. R. Silva
2023-12-14 16:35 ` Kees Cook
2023-12-14 16:37 ` Kees Cook [this message]
2023-12-15 8:17 ` Tzung-Bi Shih
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=202312140836.5AB528D54F@keescook \
--to=keescook@chromium.org \
--cc=bleung@chromium.org \
--cc=chrome-platform@lists.linux.dev \
--cc=groeck@chromium.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@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 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.