Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp1986404rdf; Mon, 6 Nov 2023 00:47:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrTCeeieAcSUxJfVcuI4tQatykOSnf69REeVeQfdT1CsIsGbmQMLjSRfIh/Qz0OoFcb8+j X-Received: by 2002:a05:6a00:2316:b0:6c3:559c:60ef with SMTP id h22-20020a056a00231600b006c3559c60efmr11829131pfh.1.1699260471679; Mon, 06 Nov 2023 00:47:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699260471; cv=none; d=google.com; s=arc-20160816; b=fUeJR2uSRVBcsB7YUauo0qJdu9hNw0x3YwNxKxO9iwBOBeicZLuym2uNabm2zvykz9 ULHZkRCJsLTQdH4ND6A1sWedyjjHSOiO1aQIgJ8/HqOfP1r+bH/Lx1ElpgQ1vob672lK y8aRxEgQgA9FgxoeAwVuCAvw1LqoAYGGFO2ZL2B2DR9E6f/UR9qE2RcQvGtTW4imCMxv XrYsDC7B+5LUgPjSWAN7mWcItdz8GQtcdgpRiSfNiIAOSjD/5SdH2b/gob6q4T80+IeN wbJA/cLLSmWFhxCg3beNFJR2XUU6eL7ElhPKTEhMuRm0qWxIY5aIFug5O8HOFkmFkRA9 YbpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=nSdh9aVbvYJU/GlJs9OpXtR3as1eL/wmBH+XlHFyTXE=; fh=322Fmt935OpefA95ObI5ljt3RMICB01OgjsCMOnS8Fo=; b=nKSofEOZPlPb21pjysOYLQFR90FF2EoDGkCBAr55TW2MI4FLH9ak8XD/7PCiKkL83q CG0JTfhz4xFxvAvii85dosF9DbkJkhIUUn8+JA0pzeIWWmvozi6oYJKbKg6QvEKuarqv YHfNdo2uXa8tHQE31+lxjBpdlfoSyQH42fJ7w9iQoyEHuF7IulWXKgdfPoKQK7j0puyZ 9ldF/jNBYE3b7O2uFHPTvrrBOTLKm+MspT6S35VSPxFxSd99lFYuJ1zH3LIamaH/RQIC +fCvfrRhxTy+ccjV2j9sEP+LYsaW/qkzXp8fpPkGbSB86irfUKpbDEPNwE7tRIqi55DT I2QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dy62QEtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id i62-20020a636d41000000b005ab92870413si7807275pgc.498.2023.11.06.00.47.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 00:47:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=dy62QEtq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 20C6680569B1; Mon, 6 Nov 2023 00:47:49 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbjKFIrk (ORCPT + 99 others); Mon, 6 Nov 2023 03:47:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbjKFIrj (ORCPT ); Mon, 6 Nov 2023 03:47:39 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1C00C9 for ; Mon, 6 Nov 2023 00:47:36 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-40837124e1cso83655e9.0 for ; Mon, 06 Nov 2023 00:47:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1699260455; x=1699865255; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=nSdh9aVbvYJU/GlJs9OpXtR3as1eL/wmBH+XlHFyTXE=; b=dy62QEtqpJVO2ztNFZX4EAFPPHWQa3/P+9cwiDUdhDyPizttWHGQ9MzRD67V/NMhv8 0g/AQda9YUva8f3WXjwS3Smd3sbWSeOHADxIo1QbFP4Kaq+hb76lLdl8LYiM6r4vaeWe Xiig033d2KC8h/sz+t9fUmudF3bsLEy8rTny8k1iscauI8zyUa3T64nEVMHv8VtUcwsQ Z9kHOgafbq60CQvbBBigMaploeWsBrg8fp4YBeov1+5g13q+RqTnlmxtFiTSrQ5JpklS hCpj4C2tqhwGbH9JYM+GJnN6Y8cEoRqTNtbvI/QZcmEqbGreguQVJ9GFLmPOLBD9ZKea RwMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699260455; x=1699865255; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nSdh9aVbvYJU/GlJs9OpXtR3as1eL/wmBH+XlHFyTXE=; b=ZVmJNhU6nlCgkcZZIsLGHrAhGeliXiGiUS/Vx+gbRI4zUJ+b2wTeHWjpRr3U0koKkZ HhXdMIlXO/CBgO0O5/clfq97l7KY/FoyNSqegdH7RWqyVwd8UkvtNSBaRTOsabn1qDCE gPmlSMpGz6ZLauyW0W/F5I2QPgFiToruAdh03J0JKZemyuWIbjOSvO5D1d/yLAmLbJ4J jTd15Miyrqa5h8YzWYNKgSpO4mbORpmoq3IdFISOzD66zt+nFo0qqGDo2mRFFx4rlx3y KUH2fYFWjlqbZGJL/IOjGX7ypf4qjz3e+oxIkfLcaTfQpa467pPt8pk4PYSnjHOMT3WT SelA== X-Gm-Message-State: AOJu0YxsToAOH74/uT4ZKlyOqq5jHSOTMiU/GHVO3ddvrwiWTLZVrd79 cRUx1W743C4GI4fyOFRsrkmxiFizEWKzA4U+6Eyu X-Received: by 2002:a05:600c:3b06:b0:400:c6de:6a20 with SMTP id m6-20020a05600c3b0600b00400c6de6a20mr94311wms.3.1699260455014; Mon, 06 Nov 2023 00:47:35 -0800 (PST) MIME-Version: 1.0 References: <20231104204334.work.160-kees@kernel.org> In-Reply-To: <20231104204334.work.160-kees@kernel.org> From: Bill Wendling Date: Mon, 6 Nov 2023 00:47:16 -0800 Message-ID: Subject: Re: [PATCH] gcc-plugins: randstruct: Only warn about true flexible arrays To: Kees Cook Cc: KP Singh , linux-hardening@vger.kernel.org, kernel test robot , "Gustavo A. R. Silva" , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 06 Nov 2023 00:47:49 -0800 (PST) On Sat, Nov 4, 2023 at 1:43=E2=80=AFPM Kees Cook wr= ote: > > The randstruct GCC plugin tried to discover "fake" flexible arrays > to issue warnings about them in randomized structs. In the future > LSM overhead reduction series, it would be legal to have a randomized > struct with a 1-element array, and this should _not_ be treated as a > flexible array, especially since commit df8fc4e934c1 ("kbuild: Enable > -fstrict-flex-arrays=3D3"). Disable the 0-sized and 1-element array > discovery logic in the plugin, but keep the "true" flexible array check. > > Cc: KP Singh > Cc: linux-hardening@vger.kernel.org > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202311021532.iBwuZUZ0-lkp@i= ntel.com/ > Fixes: df8fc4e934c1 ("kbuild: Enable -fstrict-flex-arrays=3D3") > Signed-off-by: Kees Cook Reviewed-by: Bill Wendling > --- > scripts/gcc-plugins/randomize_layout_plugin.c | 10 ---------- > 1 file changed, 10 deletions(-) > > diff --git a/scripts/gcc-plugins/randomize_layout_plugin.c b/scripts/gcc-= plugins/randomize_layout_plugin.c > index 366395cab490..910bd21d08f4 100644 > --- a/scripts/gcc-plugins/randomize_layout_plugin.c > +++ b/scripts/gcc-plugins/randomize_layout_plugin.c > @@ -278,8 +278,6 @@ static bool is_flexible_array(const_tree field) > { > const_tree fieldtype; > const_tree typesize; > - const_tree elemtype; > - const_tree elemsize; > > fieldtype =3D TREE_TYPE(field); > typesize =3D TYPE_SIZE(fieldtype); > @@ -287,20 +285,12 @@ static bool is_flexible_array(const_tree field) > if (TREE_CODE(fieldtype) !=3D ARRAY_TYPE) > return false; > > - elemtype =3D TREE_TYPE(fieldtype); > - elemsize =3D TYPE_SIZE(elemtype); > - > /* size of type is represented in bits */ > > if (typesize =3D=3D NULL_TREE && TYPE_DOMAIN(fieldtype) !=3D NULL= _TREE && > TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) =3D=3D NULL_TREE) > return true; > > - if (typesize !=3D NULL_TREE && > - (TREE_CONSTANT(typesize) && (!tree_to_uhwi(typesize) || > - tree_to_uhwi(typesize) =3D=3D tree_to_uhwi(elemsize)))) > - return true; > - > return false; > } > > -- > 2.34.1 > >