Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp1216979rwn; Thu, 8 Sep 2022 15:40:57 -0700 (PDT) X-Google-Smtp-Source: AA6agR7XqcXmFTfBdsFLjr8NY9QZDIgZ9nR3SELtKniFAK+Z38LyaWDkhVjeFdc7PujwcktpmweP X-Received: by 2002:a05:651c:1104:b0:268:98d0:5413 with SMTP id e4-20020a05651c110400b0026898d05413mr3012105ljo.384.1662676857137; Thu, 08 Sep 2022 15:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662676857; cv=none; d=google.com; s=arc-20160816; b=0O7CBcubOUo7vmKWRnVXn5/mBc4pjLxLtufhU8bFOCr3u+/Pt0VW2KO+VkcqYBLeQi zWNu7FliyL6x/hC35uJu+jxsE5tv05DAebAbBv9E8wEeJW+oRItOSTy/IcP/7qgFMeK2 h8gixC0tJDeYHd73gpVupOcOZcRtkPZDsOeXqqcMnLnbBwg/zafzIUNgjtBsImCkdAWE TYriqTopFKx6VHlJ4qI4u6bGniouJ5plTmd+MQafEJ29VjCkI/KlFChtX9puAFVrjc8e zwdwymRAgKsyOzhD+C2PoTjYDEbHczZElUKE13C+AXje5gZDBJ3ZgvhveojxlkWgjuDm NhBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=g0KkF4pWZUB2dBi7v71BMKzSGV2+jlrsEMGJ/KOK0D4=; b=pQLpkJFzBYv7pB0uJvdv0hCH70p2+dzFLvME4b4hh+pUW1srcwZlIlraf3QzVtmxuA Xcn6kZLSRM4ThSfKFf12ja1YSGxsb2sj3WzuQFFdURRdWgPie0vXzYgeXFVVQkKwqmXo bWn9EHaJEht8CGxVlQwmx3fK1MXXq1il0d1uSBvPMh/ozE4f8LtRL4LyCrPepokSe8NF dMda3jxuzmMDRosnhifoAigf87whY5E9oaDr9Cc7FOHXV+qTkJUGV7VosnSCuhDqFtip Yzuw77IRM5LECYpvjH6KtBuWokkusrU5qnn9cRuR7wDY1yMC/nBtjb3qrfh4OIrM8frQ cB3Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w24-20020a2e9598000000b00261e320b4absi20175ljh.503.2022.09.08.15.40.28; Thu, 08 Sep 2022 15:40:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230164AbiIHWbB (ORCPT + 99 others); Thu, 8 Sep 2022 18:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229937AbiIHWa5 (ORCPT ); Thu, 8 Sep 2022 18:30:57 -0400 X-Greylist: delayed 913 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Thu, 08 Sep 2022 15:30:54 PDT Received: from brightrain.aerifal.cx (brightrain.aerifal.cx [216.12.86.13]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5F45B284E for ; Thu, 8 Sep 2022 15:30:53 -0700 (PDT) Date: Thu, 8 Sep 2022 18:15:39 -0400 From: Rich Felker To: Kees Cook Cc: Yoshinori Sato , linux-sh@vger.kernel.org, Geert Uytterhoeven , Paul Mundt , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] sh: machvec: Use char[] for section boundaries Message-ID: <20220908221538.GD8773@brightrain.aerifal.cx> References: <20220907234345.96798-1-keescook@chromium.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220907234345.96798-1-keescook@chromium.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Sep 07, 2022 at 04:43:45PM -0700, Kees Cook wrote: > As done for other sections, define the extern as a character array, > which relaxes many of the compiler-time object size checks, which would > otherwise assume it's a single long. Solves the following build error: > > arch/sh/kernel/machvec.c: error: array subscript 'struct sh_machine_vector[0]' is partly outside array bounds of 'long int[1]' [-Werror=array-bounds]: => 105:33 LGMT. This is the approach I recommend for this general type of mechanism. So, Acked-by: Rich Felker Since I haven't been on top of collating patches for upstreaming, I'd be happy if anyone else wants to take this in their tree before I get back to it. Rich > Cc: Yoshinori Sato > Cc: Rich Felker > Cc: linux-sh@vger.kernel.org > Reported-by: Geert Uytterhoeven > Link: https://lore.kernel.org/lkml/alpine.DEB.2.22.394.2209050944290.964530@ramsan.of.borg/ > Fixes: 9655ad03af2d ("sh: Fixup machvec support.") > Signed-off-by: Kees Cook > --- > arch/sh/include/asm/sections.h | 2 +- > arch/sh/kernel/machvec.c | 10 +++++----- > 2 files changed, 6 insertions(+), 6 deletions(-) > > diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h > index 8edb824049b9..0cb0ca149ac3 100644 > --- a/arch/sh/include/asm/sections.h > +++ b/arch/sh/include/asm/sections.h > @@ -4,7 +4,7 @@ > > #include > > -extern long __machvec_start, __machvec_end; > +extern char __machvec_start[], __machvec_end[]; > extern char __uncached_start, __uncached_end; > extern char __start_eh_frame[], __stop_eh_frame[]; > > diff --git a/arch/sh/kernel/machvec.c b/arch/sh/kernel/machvec.c > index d606679a211e..57efaf5b82ae 100644 > --- a/arch/sh/kernel/machvec.c > +++ b/arch/sh/kernel/machvec.c > @@ -20,8 +20,8 @@ > #define MV_NAME_SIZE 32 > > #define for_each_mv(mv) \ > - for ((mv) = (struct sh_machine_vector *)&__machvec_start; \ > - (mv) && (unsigned long)(mv) < (unsigned long)&__machvec_end; \ > + for ((mv) = (struct sh_machine_vector *)__machvec_start; \ > + (mv) && (unsigned long)(mv) < (unsigned long)__machvec_end; \ > (mv)++) > > static struct sh_machine_vector * __init get_mv_byname(const char *name) > @@ -87,8 +87,8 @@ void __init sh_mv_setup(void) > if (!machvec_selected) { > unsigned long machvec_size; > > - machvec_size = ((unsigned long)&__machvec_end - > - (unsigned long)&__machvec_start); > + machvec_size = ((unsigned long)__machvec_end - > + (unsigned long)__machvec_start); > > /* > * Sanity check for machvec section alignment. Ensure > @@ -102,7 +102,7 @@ void __init sh_mv_setup(void) > * vector (usually the only one) from .machvec.init. > */ > if (machvec_size >= sizeof(struct sh_machine_vector)) > - sh_mv = *(struct sh_machine_vector *)&__machvec_start; > + sh_mv = *(struct sh_machine_vector *)__machvec_start; > } > > pr_notice("Booting machvec: %s\n", get_system_type()); > -- > 2.34.1