From: Guenter Roeck <linux@roeck-us.net>
To: Kees Cook <keescook@chromium.org>
Cc: Richard Henderson <rth@twiddle.net>,
Ivan Kokshaysky <ink@jurassic.park.msu.ru>,
Matt Turner <mattst88@gmail.com>, Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, linux-alpha@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH] alpha: Silence -Warray-bounds warnings
Date: Wed, 2 Feb 2022 15:17:18 -0800 [thread overview]
Message-ID: <20220202231718.GA2539669@roeck-us.net> (raw)
On Wed, Feb 02, 2022 at 02:18:25PM -0800, Kees Cook wrote:
> GCC 11 (incorrectly[1]) assumes that literal values cast to (void *)
> should be treated like a NULL pointer with an offset, and raises
> diagnostics when doing bounds checking:
>
> In function '__memset',
> inlined from '__bad_pagetable' at arch/alpha/mm/init.c:79:2:
> ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds]
> 37 | return __builtin_memset(s, c, n);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> In function '__memset',
> inlined from '__bad_page' at arch/alpha/mm/init.c:86:2:
> ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds]
> 37 | return __builtin_memset(s, c, n);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~
> In function '__memset',
> inlined from 'paging_init' at arch/alpha/mm/init.c:256:2:
> ./arch/alpha/include/asm/string.h:37:32: error: '__builtin_memset' offset [0, 8191] is out of the bounds [0, 0] [-Werror=array-bounds]
> 37 | return __builtin_memset(s, c, n);
>
> This has been solved in other places[2] already by using the recently
> added absolute_pointer() macro. Do the same here.
>
> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578
> [2] https://lore.kernel.org/all/20210912160149.2227137-1-linux@roeck-us.net/
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-and-tested-by: Guenter Roeck <linux@roeck-us.net>
> ---
> arch/alpha/mm/init.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/alpha/mm/init.c b/arch/alpha/mm/init.c
> index f6114d03357c..7511723b7669 100644
> --- a/arch/alpha/mm/init.c
> +++ b/arch/alpha/mm/init.c
> @@ -76,14 +76,14 @@ pgd_alloc(struct mm_struct *mm)
> pmd_t *
> __bad_pagetable(void)
> {
> - memset((void *) EMPTY_PGT, 0, PAGE_SIZE);
> + memset(absolute_pointer(EMPTY_PGT), 0, PAGE_SIZE);
> return (pmd_t *) EMPTY_PGT;
> }
>
> pte_t
> __bad_page(void)
> {
> - memset((void *) EMPTY_PGE, 0, PAGE_SIZE);
> + memset(absolute_pointer(EMPTY_PGE), 0, PAGE_SIZE);
> return pte_mkdirty(mk_pte(virt_to_page(EMPTY_PGE), PAGE_SHARED));
> }
>
> @@ -253,7 +253,7 @@ void __init paging_init(void)
> free_area_init(max_zone_pfn);
>
> /* Initialize the kernel's ZERO_PGE. */
> - memset((void *)ZERO_PGE, 0, PAGE_SIZE);
> + memset(absolute_pointer(ZERO_PGE), 0, PAGE_SIZE);
> }
>
> #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_SRM)
> --
> 2.30.2
>
next reply other threads:[~2022-02-02 23:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-02 23:17 Guenter Roeck [this message]
-- strict thread matches above, loose matches on Subject: below --
2022-02-02 22:18 [PATCH] alpha: Silence -Warray-bounds warnings Kees Cook
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=20220202231718.GA2539669@roeck-us.net \
--to=linux@roeck-us.net \
--cc=arnd@arndb.de \
--cc=ink@jurassic.park.msu.ru \
--cc=keescook@chromium.org \
--cc=linux-alpha@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mattst88@gmail.com \
--cc=rth@twiddle.net \
/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;
as well as URLs for NNTP newsgroup(s).