Message ID | 20230922172858.3822653-8-keescook@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp5916780vqi; Fri, 22 Sep 2023 16:06:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGym6snLfFkaoH+fXuSqPzeBqnpRuB6x7SiWW3o/vkWRZ0vTMlDU/GwTU0b9gHBTgIbJYTk X-Received: by 2002:a05:6a20:ce94:b0:15d:f3ae:665b with SMTP id if20-20020a056a20ce9400b0015df3ae665bmr949313pzb.28.1695423983864; Fri, 22 Sep 2023 16:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695423983; cv=none; d=google.com; s=arc-20160816; b=cGtxH/shdXC+6GsxOMijQ7Tfg8f+eDGnZlNgmQ1eQ2Zc0y0eHtbyIjCRvvEi8GqF+q IVvdzic9vzk7Evdb2xrZfjX3Lj+4MFk5bU0oZhwvRc3oE0IYs8TxorkzDfyXS4WcEDen DZX0ZOmYsqPWXdt+cceydRIPH67pXaj0TIuf9miqwrLZkjmG26mj0hdYRYXDht9yIKct Ixx8r6GZFcfp+zTkPsBPCe+oklCqGvbShaBQ27asgSHUAPhq4WB45mbQD2zBnb6KF8xZ kvRg40NqlYwgfV4iT1EHgEkyuUv7kGXX5Na0fg8ixtFDzE60U00gHShUutsh60TsBfXI vpCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ZheShKBMXsJafSBhUem9NUmco8TlRbxuPgRJhrYLuF4=; fh=EVOjgj+CHRmdD4EtZw/Xkl4EwHIWgdzRh/7nqdeuwBQ=; b=X1f+aHFZnj8D7BJN7uN2HRLoNIxYE3lIN+weR5myiZpWO2ifJYv8LQcG2jYPdYDnOK x5buShT9jRYiM6FSk0yanM//nlWHtsDVrwZbY2PRFIkRNZyDgLR9KUrR/5CtqPty7C0d p8sZMXYht8NcC/k9wXM1F1O4fbonuX6Xsa/x2DKLER8Yem6Z7TdhpCVFt+PjnPIe9VTy S2aJcU8ZtJZDxcz0wyl/L6zjJ1SM7eQDYKWcOx3YSLp+XfDfwkQUjgEQffpyD0/aei+d UULNZdbHJ3nHLVaTpo9xOm92NHCk/VaoQ+CdJ5edT53wC3bPKNy4avKTyFoV6le8N7NT 5Q/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=mu+50WzR; 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=chromium.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n22-20020a63f816000000b0056f7592d732si4577373pgh.424.2023.09.22.16.06.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 16:06:23 -0700 (PDT) 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=@chromium.org header.s=google header.b=mu+50WzR; 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=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 0606081D2AF6; Fri, 22 Sep 2023 10:29:35 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231589AbjIVR3f (ORCPT <rfc822;pwkd43@gmail.com> + 28 others); Fri, 22 Sep 2023 13:29:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232893AbjIVR3N (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 13:29:13 -0400 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42FD41A7 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:29:06 -0700 (PDT) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6910ea9cddbso2038610b3a.0 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:29:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695403745; x=1696008545; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZheShKBMXsJafSBhUem9NUmco8TlRbxuPgRJhrYLuF4=; b=mu+50WzRPb9bbl0T3bxpkUbT0QWHF28QLLRdjKAqoxTUvyL8dLakRT9mSMy8lklS0G SZCcmYbRKmIRKqXI/PoNdd33PDM4nBOXc2Uk66KQpQPVK/WcrYEb0rtxrEERka1HXJ9I xABIWUdNXMizKp5cTzCu6E7/2r1DaXyKNacTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695403745; x=1696008545; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZheShKBMXsJafSBhUem9NUmco8TlRbxuPgRJhrYLuF4=; b=VRVCSsdImDbvbZp2k9Id8znzLV+2sDKYraz+xamXieplckFwI1b9KFzaTE2T7XcnvP xZ2x+wiDu8shthfhUm5qPCCQC4LcqcdC0gBzc4J67D9xvB1HmzAhLC+sZLabf41hKtSs cvwwwCyEl3m0Cq3bxqn1JCsEgbE0veiq51E1pdO/1s0VcDmp0J/AK8sz1XqPz068CEyc 7bws0OOwSIQn5uCTZ2a7M2ehAsTo9a5G4mWlyM9tHIHRAGeKjuJCs80gwor5Xznu+1I2 7boeKU94tCJZWGKTYf5wvq7RRax+nyi0pqgXTJC4UwXNTBJ4YJjUVzOIX55nFPXYtWC8 yJPQ== X-Gm-Message-State: AOJu0YzEncf36AGHsoEGDJKeCBIPhCbMfP0VXYi1bBX6/OeQdCe87o/k 91mlznIeGlsOx7X3c96HTbraHA== X-Received: by 2002:a05:6a20:3cac:b0:158:17e6:7a6 with SMTP id b44-20020a056a203cac00b0015817e607a6mr221373pzj.42.1695403745651; Fri, 22 Sep 2023 10:29:05 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id b6-20020aa78706000000b0068e12e6954csm3458358pfo.36.2023.09.22.10.29.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:29:03 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Jakub Kicinski <kuba@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Alex Elder <elder@kernel.org>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, Jamal Hadi Salim <jhs@mojatatu.com>, David Ahern <dsahern@kernel.org>, Martin KaFai Lau <martin.lau@kernel.org>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, Alexei Starovoitov <ast@kernel.org>, Yisen Zhuang <yisen.zhuang@huawei.com>, Salil Mehta <salil.mehta@huawei.com>, Claudiu Manoil <claudiu.manoil@nxp.com>, Vladimir Oltean <vladimir.oltean@nxp.com>, "K. Y. Srinivasan" <kys@microsoft.com>, Haiyang Zhang <haiyangz@microsoft.com>, Wei Liu <wei.liu@kernel.org>, Dexuan Cui <decui@microsoft.com>, Long Li <longli@microsoft.com>, Ajay Sharma <sharmaajay@microsoft.com>, Pravin B Shelar <pshelar@ovn.org>, Shaokun Zhang <zhangshaokun@hisilicon.com>, Cong Wang <xiyou.wangcong@gmail.com>, Jiri Pirko <jiri@resnulli.us>, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Tom Rix <trix@redhat.com>, Simon Horman <horms@kernel.org>, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-rdma@vger.kernel.org, dev@openvswitch.org, linux-parisc@vger.kernel.org, llvm@lists.linux.dev, linux-hardening@vger.kernel.org Subject: [PATCH 08/14] net: ipa: Annotate struct ipa_power with __counted_by Date: Fri, 22 Sep 2023 10:28:50 -0700 Message-Id: <20230922172858.3822653-8-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230922172449.work.906-kees@kernel.org> References: <20230922172449.work.906-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1399; i=keescook@chromium.org; h=from:subject; bh=ZVNa42RINhV0v/Ht3T7iUT3nE/j+aJWcJU1ourfEiHs=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDc7Xrsd3u3GIIaa0RoAqhrB+eBWXpaTGMEQ/u 44xb3Uo6V+JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3O1wAKCRCJcvTf3G3A Ju/8D/sG14Nl2om0NTcT3T/FMCMrw5caewzWYYZZA5qGbOQyUerx5rGQueGAkyPPzVCA3z1X5Ei RAGkC4MQg8U6DuG+B6Y1GivTSRwcfrgH0NCU6rCO6TCwfwx3GMsNvAVp1J0YiNbBKcGq0C1Pwn3 tOg+us9yQCjqWWxhOxxt+uFv25NxnxjZjDDqxtYh6SYPQRwSw49hCykEDOott+K24NhX8NPAYaz jcD8tBJDS2QTRtd56RnyfIIeDq7ekRHm7ECmBw7eXdLbD1D1jzGncRJuupIgENxJO55A1F/abO2 rp7ZAzuNHsSIezVTtETCcKaGUBAx7qAE2T5yIZT+yed0mwppMzZm79vOzVq9N6hVgyw3lKWllRx 42WAgbPQ4Etr9HIBG3IkmYAyAvxu6db3KV9eDsWJ+49A2sbLor6jbJmppVskRGaBKsq1jm54hAK DtyjOKF2noGlhzLtQU3xpPVLiyizpXlHiGphYq+WC+nuXS7ILP2asn0W0c2Ip9uX1sml99XYNbj L9MR+41qLcYAX5yN6Jd+WAlhJO2SVaZHdWsr5FDN80BNIQO3kRKYVc4rzv4J4ZiBpukNZ7gqU2H tmh0agc3IN/G2PWAx2O6+YIDCIdoGDabLbVvGpLrI2tAQfg5cIYqgJoQMkstH5cn9Zy8t+JEv2d c8jebhrkUEu4ufQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit 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_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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]); Fri, 22 Sep 2023 10:29:35 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777780899152453804 X-GMAIL-MSGID: 1777780899152453804 |
Series |
Batch 1: Annotate structs with __counted_by
|
|
Commit Message
Kees Cook
Sept. 22, 2023, 5:28 p.m. UTC
Prepare for the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).
As found with Coccinelle[1], add __counted_by for struct ipa_power.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Alex Elder <elder@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
---
drivers/net/ipa/ipa_power.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On 9/22/23 11:28, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct ipa_power. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Alex Elder <elder@kernel.org> > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Eric Dumazet <edumazet@google.com> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Paolo Abeni <pabeni@redhat.com> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Thanks
On 9/22/23 12:28 PM, Kees Cook wrote: > Prepare for the coming implementation by GCC and Clang of the __counted_by > attribute. Flexible array members annotated with __counted_by can have > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > functions). > > As found with Coccinelle[1], add __counted_by for struct ipa_power. Looks good, thanks. Reviewed-by: Alex Elder <elder@linaro.org> Note that there is some interaction between struct ipa_power_data and struct ipa_power (the former is used to initialize the latter). Both of these contain flexible arrays counted by another field in the structure. It seems possible that the way these are initialized might need slight modification to allow the compiler to do its enforcement; if that's the case, please reach out to me. -Alex > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Alex Elder <elder@kernel.org> > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Eric Dumazet <edumazet@google.com> > Cc: Jakub Kicinski <kuba@kernel.org> > Cc: Paolo Abeni <pabeni@redhat.com> > Cc: netdev@vger.kernel.org > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > drivers/net/ipa/ipa_power.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c > index 0eaa7a7f3343..e223886123ce 100644 > --- a/drivers/net/ipa/ipa_power.c > +++ b/drivers/net/ipa/ipa_power.c > @@ -67,7 +67,7 @@ struct ipa_power { > spinlock_t spinlock; /* used with STOPPED/STARTED power flags */ > DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT); > u32 interconnect_count; > - struct icc_bulk_data interconnect[]; > + struct icc_bulk_data interconnect[] __counted_by(interconnect_count); > }; > > /* Initialize interconnects required for IPA operation */
On Sat, Sep 23, 2023 at 07:09:19AM -0500, Alex Elder wrote: > On 9/22/23 12:28 PM, Kees Cook wrote: > > Prepare for the coming implementation by GCC and Clang of the __counted_by > > attribute. Flexible array members annotated with __counted_by can have > > their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS > > (for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family > > functions). > > > > As found with Coccinelle[1], add __counted_by for struct ipa_power. > > Looks good, thanks. > > Reviewed-by: Alex Elder <elder@linaro.org> > > Note that there is some interaction between struct ipa_power_data > and struct ipa_power (the former is used to initialize the latter). > Both of these contain flexible arrays counted by another field in > the structure. It seems possible that the way these are initialized > might need slight modification to allow the compiler to do its > enforcement; if that's the case, please reach out to me. I think it's all okay: struct ipa_power_data { u32 core_clock_rate; u32 interconnect_count; /* # entries in interconnect_data[] */ const struct ipa_interconnect_data *interconnect_data; }; "interconnect_data" here is a pointer, not a flexible array. (Yes, __counted_by is expected to be expanded in the future for pointers, but not yet.) Looking at initializers, I didn't see any problems with how struct ipa_power is allocated. Thanks for the heads-up; I'm sure I'll look at this again when we can further expand __counted_by to pointers. :) -Kees
diff --git a/drivers/net/ipa/ipa_power.c b/drivers/net/ipa/ipa_power.c index 0eaa7a7f3343..e223886123ce 100644 --- a/drivers/net/ipa/ipa_power.c +++ b/drivers/net/ipa/ipa_power.c @@ -67,7 +67,7 @@ struct ipa_power { spinlock_t spinlock; /* used with STOPPED/STARTED power flags */ DECLARE_BITMAP(flags, IPA_POWER_FLAG_COUNT); u32 interconnect_count; - struct icc_bulk_data interconnect[]; + struct icc_bulk_data interconnect[] __counted_by(interconnect_count); }; /* Initialize interconnects required for IPA operation */