Message ID | ZWJoRsJGnCPdJ3+2@work |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:ce62:0:b0:403:3b70:6f57 with SMTP id o2csp2166295vqx; Sat, 25 Nov 2023 13:34:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkUKg8L4iBCzYPZNyszMXUDp/PwKT1PCtGFdsLabSpMQC7QeDJXwxdue25Q/KX1lKRgnQC X-Received: by 2002:a05:6a21:999c:b0:18c:651:67fe with SMTP id ve28-20020a056a21999c00b0018c065167femr6920367pzb.62.1700948051954; Sat, 25 Nov 2023 13:34:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700948051; cv=none; d=google.com; s=arc-20160816; b=illjM1+5UFIcmhVuSoRRM1irQLRrhyl84Zxy390uh7xXoyZX3O0BjyJoSypR1qlNM6 aqkNpG3VWaqozFPaObAHZwgvMpVwwT8gMp4DCuRUZUQGYsP5YrrXSJziFxk4lKi3ZGYx Xd4lpz48sdWtn8gh2BjdjTVS4UKmOMOg0i4v7Nr8dsHZjhZxwrmTvfYZcf6FudFMWNFa 2DFc4YzyyQPYZa2OSOyY/jTDe/y42JgkhgY1WXrmsYuPH8vvpvFlC9fTitdXlFUI0ATW ItySX653am4o7tkoCap4T8hgsVRjwZbDkpmjcMWusDeogcT+JHPVzPt3i6vEYaE+zQA0 y/1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=TIZw0sAaej9It30N9kqx5MXKjy5jfVR/TESUkYENOcE=; fh=DXResGQog401Ygj+jDzHM9dGCVIqCydvvJpGoM1oETQ=; b=rSziXJh0Nu36rrThtO2J0ZeowWlptvHr89p2tjm8PHi8KZt1Ix26ZaHGsk96V/MY/l 8XDQJpenvRZyGFjChlVMNjBpez7B/n+XC7zEZAxoT4dDWcVec6TddhHXk4tKdV/mUpa2 0N//0tIDLkwiyPIYVqE+AbVGVXPIW9WvTsd8YljqYfq8AfykdT28YvaMVga2hx27AYQZ NTlgQFg2kx9NaYSB/+kQcBUJNhKX2s/QpzS5MYa2FMd8gK4Qn2KRWz9e4om2Vqcayh0d jR9T+EhtAPy4sj0srNctrzjcgOcS/l+7aOdcSnGAmKcyXOSTPSl9QVdMdG4UbAkoTH/3 H/Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bDyPWWzF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id w1-20020a626201000000b0068fcc84dda7si6030391pfb.327.2023.11.25.13.34.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 25 Nov 2023 13:34:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bDyPWWzF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E1B9C8092EFB; Sat, 25 Nov 2023 13:34:10 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229511AbjKYVd7 (ORCPT <rfc822;kernel.ruili@gmail.com> + 99 others); Sat, 25 Nov 2023 16:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjKYVd5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sat, 25 Nov 2023 16:33:57 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 49E2FFF for <linux-kernel@vger.kernel.org>; Sat, 25 Nov 2023 13:34:04 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 676D7C433C8; Sat, 25 Nov 2023 21:34:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700948043; bh=3PJWnPCtKl6PvabTELl1ZdWeU0rVXun3osxxXR2Cv+U=; h=Date:From:To:Cc:Subject:From; b=bDyPWWzFS+Iqm5I3epM/lwGJhMeAsCxIjgyskeMt0jEuMbAGth62cljmUcdWUx9iM JypYTyhoJ6iMx/wb6yoVWr8kUxaw5+e9neIAfbqcI57AFbhhZeoY76b7n/ibdcnwm7 EzlNYKuzwVi5Eu8L6FPM1BokSaXvhnAwypKVM5RTLy9xuvrzv4Ez0gQXYXz3CgBGN6 Z93kxIJJyn9HpcCWkX1GK512DeV76WomS7TNJtK6J+3gF9o9x1YKSktir9jHDuEt1R DDFvFUP68E+VPd2/l30IqiSlq/mri3uSxbRIMnPfQA8ncyroAzsaB8Vfg7pdyx4C7x NvVCTXUDY8IZQ== Date: Sat, 25 Nov 2023 15:33:58 -0600 From: "Gustavo A. R. Silva" <gustavoars@kernel.org> To: Joey Gouly <joey.gouly@arm.com>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, Bill Wendling <morbo@google.com>, Kees Cook <keescook@chromium.org> Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" <gustavoars@kernel.org>, linux-hardening@vger.kernel.org Subject: [PATCH] neighbour: Fix __randomize_layout crash in struct neighbour Message-ID: <ZWJoRsJGnCPdJ3+2@work> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 25 Nov 2023 13:34:11 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783573304190299465 X-GMAIL-MSGID: 1783573304190299465 |
Series |
neighbour: Fix __randomize_layout crash in struct neighbour
|
|
Commit Message
Gustavo A. R. Silva
Nov. 25, 2023, 9:33 p.m. UTC
Previously, one-element and zero-length arrays were treated as true
flexible arrays, even though they are actually "fake" flex arrays.
The __randomize_layout would leave them untouched at the end of the
struct, similarly to proper C99 flex-array members.
However, this approach changed with commit 1ee60356c2dc ("gcc-plugins:
randstruct: Only warn about true flexible arrays"). Now, only C99
flexible-array members will remain untouched at the end of the struct,
while one-element and zero-length arrays will be subject to randomization.
Fix a `__randomize_layout` crash in `struct neighbour` by transforming
zero-length array `primary_key` into a proper C99 flexible-array member.
Fixes: 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays")
Closes: https://lore.kernel.org/linux-hardening/20231124102458.GB1503258@e124191.cambridge.arm.com/
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
include/net/neighbour.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Sat, Nov 25, 2023 at 03:33:58PM -0600, Gustavo A. R. Silva wrote: > Previously, one-element and zero-length arrays were treated as true > flexible arrays, even though they are actually "fake" flex arrays. > The __randomize_layout would leave them untouched at the end of the > struct, similarly to proper C99 flex-array members. > > However, this approach changed with commit 1ee60356c2dc ("gcc-plugins: > randstruct: Only warn about true flexible arrays"). Now, only C99 > flexible-array members will remain untouched at the end of the struct, > while one-element and zero-length arrays will be subject to randomization. > > Fix a `__randomize_layout` crash in `struct neighbour` by transforming > zero-length array `primary_key` into a proper C99 flexible-array member. > > Fixes: 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays") > Closes: https://lore.kernel.org/linux-hardening/20231124102458.GB1503258@e124191.cambridge.arm.com/ > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> Yes, please. Do we have any other 0-sized arrays hiding out in the kernel? We need to get these all cleared... Reviewed-by: Kees Cook <keescook@chromium.org>
On 11/27/23 18:29, Kees Cook wrote: > On Sat, Nov 25, 2023 at 03:33:58PM -0600, Gustavo A. R. Silva wrote: >> Previously, one-element and zero-length arrays were treated as true >> flexible arrays, even though they are actually "fake" flex arrays. >> The __randomize_layout would leave them untouched at the end of the >> struct, similarly to proper C99 flex-array members. >> >> However, this approach changed with commit 1ee60356c2dc ("gcc-plugins: >> randstruct: Only warn about true flexible arrays"). Now, only C99 >> flexible-array members will remain untouched at the end of the struct, >> while one-element and zero-length arrays will be subject to randomization. >> >> Fix a `__randomize_layout` crash in `struct neighbour` by transforming >> zero-length array `primary_key` into a proper C99 flexible-array member. >> >> Fixes: 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays") >> Closes: https://lore.kernel.org/linux-hardening/20231124102458.GB1503258@e124191.cambridge.arm.com/ >> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > > Yes, please. Do we have any other 0-sized arrays hiding out in the > kernel? We need to get these all cleared... I've found 27 instances of zero-length fake-flex arrays in next-20231127. I'll send a patch series to transform all of them. > > Reviewed-by: Kees Cook <keescook@chromium.org> > Thanks! -- Gustavo
Hi, On Sat, Nov 25, 2023 at 03:33:58PM -0600, Gustavo A. R. Silva wrote: > Previously, one-element and zero-length arrays were treated as true > flexible arrays, even though they are actually "fake" flex arrays. > The __randomize_layout would leave them untouched at the end of the > struct, similarly to proper C99 flex-array members. > > However, this approach changed with commit 1ee60356c2dc ("gcc-plugins: > randstruct: Only warn about true flexible arrays"). Now, only C99 > flexible-array members will remain untouched at the end of the struct, > while one-element and zero-length arrays will be subject to randomization. > > Fix a `__randomize_layout` crash in `struct neighbour` by transforming > zero-length array `primary_key` into a proper C99 flexible-array member. > > Fixes: 1ee60356c2dc ("gcc-plugins: randstruct: Only warn about true flexible arrays") > Closes: https://lore.kernel.org/linux-hardening/20231124102458.GB1503258@e124191.cambridge.arm.com/ > Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org> > --- > include/net/neighbour.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > 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 { Fixes the crash for me! Tested-by: Joey Gouly <joey.gouly@arm.com>
>> 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 { > > Fixes the crash for me! Awesome. :) -- Gustavo
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 {