Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp2005591rdh; Sat, 25 Nov 2023 09:54:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFSAsjt+7mTx+tAYiAAJrkE21GEZm/KOmRlmlxgS4ZkRXd/IVIpPa4Y+LThgtMk91FfeVM1 X-Received: by 2002:a17:90b:1bcf:b0:285:8646:bf61 with SMTP id oa15-20020a17090b1bcf00b002858646bf61mr6659350pjb.33.1700934894771; Sat, 25 Nov 2023 09:54:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700934894; cv=none; d=google.com; s=arc-20160816; b=SE83mJFQrqx7AUNJgCoCsIKC+F6xs+UIybupLdxJj3ljOnD2rpmIxscvkdGMyBHuXz x+bUvOgktDjHIVnPYtrBHnYFZmP5kdvOoOZKFv9+9b/dfBxRu7h/Hv65ZEKJSwNnVqs3 4nUvidYGIEIX+YLxppJscvR8Bdt3VCcvwr5PW+ULa6fHWYjXzXWuLL3zgQyFdmt5Fq/u aZ5n1paacQ0U9VUOmDxge5FVTtvvHuAu4G9uW5A1UgfA9sO4Ab2OIuktISRKvVKj01iY xehn5MXiYlwZLaPfwHOuhIk0h7V1A9wIMnsXEKfGm1D74niSIrnTNwQsooB3O1KgjokT H1rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :content-language:references:cc:to:from:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=fQ6gkAIpegcRMWjhELvU1rTB6lMBEW1z2DgZ25eNdo0=; fh=eHekh3Mt4zqv4QvsUnmE8Cs4Rre53Mj4fCny7sgfjro=; b=QUZqcfjWGHkOkY2uCwim3h82VoWD2e8wxwpOOQFCccHTWgpuaBrq5ZXe/ko8OEUNee /Z/UU9ba6tK/AMrNYbNd1S4CPfB48mPJw07Iov3hJr/2boNwrOUnJZIXuqb3B9dbMTeJ NKa/Fmhcym3oSG5zg6TZuisj8a0ga0ge+rUl/okKc6MvwfRSIL3qBTauKd1g9qYPBGUK jMqa7OmBwh7P51LMh/i8dEdYoIt1R1N8M9hz/xymhu9BWChwdWxjNTfLTV2Wmu60fLHA SlbIEG60smjbACH8KADmF8iRS4fY1v7HuMMvzRjqOCb9OKKpZ0oF6GwOm5K6z7WnzYFx EeSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=bRBdEzaw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id s10-20020a17090ad48a00b002850e97e25esi6277599pju.2.2023.11.25.09.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 09:54:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=fail header.i=@embeddedor.com header.s=default header.b=bRBdEzaw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E4A9C802093F; Sat, 25 Nov 2023 09:54:51 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231697AbjKYRye (ORCPT + 99 others); Sat, 25 Nov 2023 12:54:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbjKYRyc (ORCPT ); Sat, 25 Nov 2023 12:54:32 -0500 Received: from omta36.uswest2.a.cloudfilter.net (omta36.uswest2.a.cloudfilter.net [35.89.44.35]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 461A2127 for ; Sat, 25 Nov 2023 09:54:39 -0800 (PST) Received: from eig-obgw-5008a.ext.cloudfilter.net ([10.0.29.246]) by cmsmtp with ESMTPS id 6h1fr2VbBhqFd6wrWrLe2E; Sat, 25 Nov 2023 17:54:38 +0000 Received: from gator4166.hostgator.com ([108.167.133.22]) by cmsmtp with ESMTPS id 6wrVrQmwKkUbt6wrVrWRjH; Sat, 25 Nov 2023 17:54:38 +0000 X-Authority-Analysis: v=2.4 cv=WpU4jPTv c=1 sm=1 tr=0 ts=656234de a=1YbLdUo/zbTtOZ3uB5T3HA==:117 a=yGeM7+xMb5a5VK1DGQx1ew==:17 a=OWjo9vPv0XrRhIrVQ50Ab3nP57M=:19 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=IkcTkHD0fZMA:10 a=BNY50KLci1gA:10 a=wYkD_t78qR0A:10 a=6mUrkXxl0K-UJ-lciFYA:9 a=QEXdDO2ut3YA:10 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=embeddedor.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:References:Cc:To:From:Subject:MIME-Version:Date:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=fQ6gkAIpegcRMWjhELvU1rTB6lMBEW1z2DgZ25eNdo0=; b=bRBdEzawFlxZI6RfftSz5OGGHW z0dZeVUJfzQWuG5en1b8FHMQV64h0L/nqbMfs1ICF2ClihuEB5tdHWEllGs2HoSBvakVdJy7EtCJA 7VT2d2wrnpYxOr9wx+6w3OB4a5BZ7j/DQJ5ZLnZFvlB4mkA9Sv0rYsIVzFnfLs/z+0fIsx16pkESP EigUzMG5Bj8r7dHO6vR5niEJMExQ6CmE6c9DSrbSaBdwwoWPzPyNcd0ovdbsh682p8kfjh1pCVRtx TWXY/M26fKScoz8f2HLGEe5Lkfx64NI008IBAyBm1U7270CHv3fTSYnXxSCW2jCb/EdqYzAIUqBTG 2q6Hu3Wg==; Received: from 187.184.157.122.cable.dyn.cableonline.com.mx ([187.184.157.122]:46244 helo=[192.168.0.25]) by gator4166.hostgator.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96.2) (envelope-from ) id 1r6wrU-001o7P-2I; Sat, 25 Nov 2023 11:54:36 -0600 Message-ID: Date: Sat, 25 Nov 2023 11:54:28 -0600 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [BUG] Boot crash on v6.7-rc2 From: "Gustavo A. R. Silva" To: Joey Gouly , Kees Cook , linux-hardening@vger.kernel.org, netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" References: <20231124102458.GB1503258@e124191.cambridge.arm.com> <7086f60f-9f74-4118-a10c-d98b9c6cc8eb@embeddedor.com> Content-Language: en-US In-Reply-To: <7086f60f-9f74-4118-a10c-d98b9c6cc8eb@embeddedor.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator4166.hostgator.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - embeddedor.com X-BWhitelist: no X-Source-IP: 187.184.157.122 X-Source-L: No X-Exim-ID: 1r6wrU-001o7P-2I X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 187.184.157.122.cable.dyn.cableonline.com.mx ([192.168.0.25]) [187.184.157.122]:46244 X-Source-Auth: gustavo@embeddedor.com X-Email-Count: 2 X-Org: HG=hgshared;ORG=hostgator; X-Source-Cap: Z3V6aWRpbmU7Z3V6aWRpbmU7Z2F0b3I0MTY2Lmhvc3RnYXRvci5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfHyUqeV6zvtsZFpRirITFeuNBqkRB8qT4MmmU4i+3stVJ0IgYAY17//Rt2yLm0KgMjefrSc3wNt2Pz6/P6pXkMb/ulMeyqzVG7iSntm4bSX3vRtASsYP wbHI6dBEt9h9xcN670Dt2QMwfQAx5sNbZR9d6HtPR+jN0RYogugOyRYuIuqygShOO2aH7nKkC3QUA0feCIPVV2ePv2DPlgqiXS03KsdvScwtLWOuAKQBRyaI X-Spam-Status: No, score=3.0 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Sat, 25 Nov 2023 09:54:52 -0800 (PST) On 11/24/23 09:28, Gustavo A. R. Silva wrote: > > > On 11/24/23 04:24, Joey Gouly wrote: >> Hi all, >> >> I just hit a boot crash on v6.7-rc2 (arm64, FVP model): > > [..] > >> Checking `struct neighbour`: >> >>     struct neighbour { >>         struct neighbour __rcu    *next; >>         struct neigh_table    *tbl; >>     .. fields .. >>         u8            primary_key[0]; >>     } __randomize_layout; >> >> Due to the `__randomize_layout`, `primary_key` field is being placed before `tbl` (actually it's the same address since it's a 0 length array). That means the >> memcpy() corrupts the tbl pointer. >> >> I think I just got unlucky with my CONFIG_RANDSTRUCT seed (I can provide it if needed), it doesn't look as if it's a new issue. > > It seems the issue is caused by this change that was recently added to -rc2: > > commit 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays") > > Previously, one-element and zero-length arrays were treated as true flexible arrays > (however, they are "fake" flex arrays), and __randomize_layout would leave them > untouched at the end of the struct; the same for proper C99 flex-array members. But > after the commit above, that's no longer the case: Only C99 flex-array members will > behave correctly (remaining untouched at end of the struct), and the other two types > of arrays will be randomized. mmh... it seems that commit 1ee60356c2dc only prevents one-element arrays from being treated as flex arrays, while the code should still keep zero-length arrays untouched: if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE && TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE) return true; - if (typesize != NULL_TREE && - (TREE_CONSTANT(typesize) && (!tree_to_uhwi(typesize) || - tree_to_uhwi(typesize) == tree_to_uhwi(elemsize)))) - return true; - Sorry about the confusion. > >> >> I couldn't reproduce directly on v6.6 (the offsets for `tbl` and `primary_key` didn't overlap). >> However I tried changing the zero-length-array to a flexible one: >> >>     +    DECLARE_FLEX_ARRAY(u8, primary_key); >>     +    u8        primary_key[0]; >> >> Then the field offsets ended up overlapping, and I also got the same crash on v6.6. > > The right approach is to transform the zero-length array into a C99 flex-array member, > like this: > > diff --git a/include/net/neighbour.h b/include/net/neighbour.h > index 07022bb0d44d..0d28172193fa 100644 > --- a/include/net/neighbour.h > +++ b/include/net/neighbour.h > @@ -162,7 +162,7 @@ struct neighbour { >         struct rcu_head         rcu; >         struct net_device       *dev; >         netdevice_tracker       dev_tracker; > -       u8                      primary_key[0]; > +       u8                      primary_key[]; >  } __randomize_layout; > >  struct neigh_ops { In any case, I think we still should convert [0] to [ ]. -- Gustavo