Message ID | 20230922172858.3822653-14-keescook@chromium.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:910f:0:b0:403:3b70:6f57 with SMTP id r15csp28822vqg; Fri, 22 Sep 2023 18:45:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQ9SqpQa48l4NrehzfM4TvkQwzVnRvmTSy81kz52ZIod24IMwOwoee8J8adKoP0uOINcXI X-Received: by 2002:a05:6358:2822:b0:143:5d3f:f397 with SMTP id k34-20020a056358282200b001435d3ff397mr1449257rwb.16.1695433544357; Fri, 22 Sep 2023 18:45:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695433544; cv=none; d=google.com; s=arc-20160816; b=ne2au+4ELuMPOMEDS4PuTCIlKSkX9Mh/K67rgukxNMRBhmNUkpFNhKvyT4EH1qE1Rb F9L8rTm4zwSZU+ZzNrKVXq56IRBKe1gKN/T9kjbAruA092ASGsYwWOpDWEF+99bp+E6O QVQVuXBtrjZ2B9jBCAOlYWKTNyVmlppIZ1LUqc+X0x5Ulhs1RjQ1Lddj9bYkWLsp227I pO8IsP985AHsTbzWR4TfHVxnouXxD+eYGc9q3vjnrIrsI5QDnDwzf4huLbwYbgcZr5E6 zEaod9yvYrquMkP9sceWzrXJAYdBF3150eDVSFi0mXod8Pl25YJQbfWPJQ8XFnJviXfy Obuw== 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=4qbLpDWUwgzzYPCRaxCJqmb/nv0TKtcjFS6rBqkmcgY=; fh=TFdx85WNDn26cN2UpQ/oRcnMpzOZHXVPBKkf6MO6Zbo=; b=Wxm0NbXlwaPKpRqnipKioWigOWF2jmJKh+S5jnCkh+Hm56BJKIZGwlG//EbXbD7DD+ YhKUcCiW5D90ik06dyL+Ns2ot66GrXJNAZ8dDEMSVMwIYa0F9yoOg0HvRL/uf8j6xFzj KgXv+CQIi1MUoD758qr7Hu7ILTS6FX+S2wansOAsawVsweyh7+5b4jOxKClK31Gz/wRi Bki2oD13dGiY647LUhMuhHqsxqBG4W+i23LTPBnaDJmGagMyHU/xOwRID3Zf3tsBZ57a PV7rR1WBePfpPJ/bYizeueo4KiO888WvwyDNG578SIr3S/9S67fH0TFD2NN/IXiuyxne CaHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Rmhof9VC; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id bf13-20020a17090b0b0d00b00274b668b762si5011021pjb.172.2023.09.22.18.45.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 18:45:44 -0700 (PDT) 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=pass header.i=@chromium.org header.s=google header.b=Rmhof9VC; 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; 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 howler.vger.email (Postfix) with ESMTP id A2C22860AD28; Fri, 22 Sep 2023 10:29:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233228AbjIVR3u (ORCPT <rfc822;pwkd43@gmail.com> + 28 others); Fri, 22 Sep 2023 13:29:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233050AbjIVR3S (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 13:29:18 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA3C4CE9 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:29:10 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1bdf4752c3cso19960355ad.2 for <linux-kernel@vger.kernel.org>; Fri, 22 Sep 2023 10:29:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695403750; x=1696008550; 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=4qbLpDWUwgzzYPCRaxCJqmb/nv0TKtcjFS6rBqkmcgY=; b=Rmhof9VCSONI8qKtDgVkygB/9N3WKOhTVZNbN1IpQGHyy1Cm/rnPQH4RrzAL29vhf3 3xaySxt4zTIVA2CfdsC4DkiOuyIczVoCn/OER7DaWq8UELh5Vzs+H4OBEVxC8Vc/SX5h bIHZ4J+TKjAavKK3Ucs071KIMcDVhPmOY1RbU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695403750; x=1696008550; 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=4qbLpDWUwgzzYPCRaxCJqmb/nv0TKtcjFS6rBqkmcgY=; b=Pg5fh3Zcfw6jZBggqXFELpoWe/f/lpComerTlk2eAVVfUo6cjon+QLvuxp82rhogeN p99R8K98/4ahoWqx/8ZNGK7m1YxykiJcjd2QNokMiDILMHqaGucsAcsUPt2fkM/u8Tu7 DABUMO92Iu+wjjZrWfH/pvB0BqtiAGfcdYq11xIeIPK0WdkmUmV42DdPfuK8SjaAKnaM +J3j9y59tBpRoUyrP5ezbmibSvkbpuWx9GKwwIqaFXgZ4FD1QVH92AvO6/34ZaOUkpcu bAi00wKjfcDuDozmkXulCXdGmMjSh+MYPliBBxC+GV5sGOs96+MLMhxHv/m3oUE55LRt LWoQ== X-Gm-Message-State: AOJu0Ywh0ZQe+D/h2Jdv09CCRjtGPtmdlNo+241dJzn6Td8Hr/EgSSKw znDBi2bh5IoGZB1tuxlJb9mhjg== X-Received: by 2002:a17:903:1109:b0:1bb:d59d:8c57 with SMTP id n9-20020a170903110900b001bbd59d8c57mr130556plh.18.1695403750017; Fri, 22 Sep 2023 10:29:10 -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 a2-20020a170902ee8200b001b66a71a4a0sm3749961pld.32.2023.09.22.10.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 10:29:04 -0700 (PDT) From: Kees Cook <keescook@chromium.org> To: Jakub Kicinski <kuba@kernel.org> Cc: Kees Cook <keescook@chromium.org>, Jamal Hadi Salim <jhs@mojatatu.com>, Cong Wang <xiyou.wangcong@gmail.com>, Jiri Pirko <jiri@resnulli.us>, "David S. Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@google.com>, Paolo Abeni <pabeni@redhat.com>, netdev@vger.kernel.org, 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>, Alex Elder <elder@kernel.org>, Pravin B Shelar <pshelar@ovn.org>, Shaokun Zhang <zhangshaokun@hisilicon.com>, 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 14/14] net: sched: Annotate struct tc_pedit with __counted_by Date: Fri, 22 Sep 2023 10:28:56 -0700 Message-Id: <20230922172858.3822653-14-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=1707; i=keescook@chromium.org; h=from:subject; bh=2t/ZxOWEU2viROo1UvEVFxKv5vcCA9cvfvIY7AUZekI=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlDc7XaxqapjSBY/SPBC/x04RSUHK/UIttRsNmQ BtJyGkw5WiJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZQ3O1wAKCRCJcvTf3G3A Jh2RD/0dUjACoTlVEZR/rUTfjAaXcRrjdWj/jRwZhzM+BFjVVrkW2WL4vF8f3OtpT1D37kVC6yt 5krc2k1SgI9i4EIbbTCTHDKmLHFMdeNJj5yXkZqGe2kQocQH6O2t4MI9L3hpREI1/FZbqJdfIhP O0VkQhiYhU7Nivmec62bTZvgzPCuVjj1QbCRx64McRRzIsCOrxiOJVxaLRn8MXUoag8JHHVtq8N C0GRweTtJdTEnvySnkIRdOv1aQSe9bmyu3n6UfeVSb99zjCgoSq6MzdIJIykmvV+ipPWiTOAHXF hgcx6Nj7vOyb/udVU8Sy2EyA+QKSJGjs4xelXxxAAt5eYBvynuKGDPq+5enCP676vNeK5lYIcdM tjR9wL1D90SxMp0k31niGjQQfhd2hZX207yL3hWHrAmFhKgGM58T6wcW6TJM3kyVNhw0Rsgw57I 3Qs/3XpeZD+0L6Yz/nZiIjHP5q0ZEHd8RaV5+RBsuMFOD4sSxoz2dpbIgFlMC5M6rSM3HYp9QRu 8bWPWgo4YgaynOSa3gYtVwkMV4winLmyJPRJ1RnvUXpyMWvyDnfoH38MZwyqVEnPdIXXbXejgny eDjoni1yyVaDXPOQYroF9Gf+NTE14pE11tfkIsS5+ql+igraxVPAXLcoQzTe5Q1j/7N7pAMKrKE ckNAllL+gDJgldQ== 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 (howler.vger.email [0.0.0.0]); Fri, 22 Sep 2023 10:29:50 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777781276427591484 X-GMAIL-MSGID: 1777790924086805265 |
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 tc_pedit.
Additionally, since the element count member must be set before accessing
the annotated flexible array member, move its initialization earlier.
[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jiri Pirko <jiri@resnulli.us>
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>
---
net/sched/act_pedit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Sep 22, 2023 at 10:28:56AM -0700, 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 tc_pedit. > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Jamal Hadi Salim <jhs@mojatatu.com> > Cc: Cong Wang <xiyou.wangcong@gmail.com> > Cc: Jiri Pirko <jiri@resnulli.us> > 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> > --- > net/sched/act_pedit.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c > index 1ef8fcfa9997..77c407eff3b0 100644 > --- a/net/sched/act_pedit.c > +++ b/net/sched/act_pedit.c > @@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, > spin_unlock_bh(&p->tcf_lock); > return -ENOBUFS; > } > + opt->nkeys = parms->tcfp_nkeys; > > memcpy(opt->keys, parms->tcfp_keys, > flex_array_size(opt, keys, parms->tcfp_nkeys)); > opt->index = p->tcf_index; > - opt->nkeys = parms->tcfp_nkeys; > opt->flags = parms->tcfp_flags; > opt->action = p->tcf_action; > opt->refcnt = refcount_read(&p->tcf_refcnt) - ref; > -- > 2.34.1 Gustavo pointed out that the annotation half of this patch in missing. My mistake! I will figure out where it went. :P Ah, the joys of splitting up a treewide patch series...
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 tc_pedit. I think the annotation for struct tc_pedit_sel is missing. Thanks -- Gustavo > Additionally, since the element count member must be set before accessing > the annotated flexible array member, move its initialization earlier. > > [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci > > Cc: Jamal Hadi Salim <jhs@mojatatu.com> > Cc: Cong Wang <xiyou.wangcong@gmail.com> > Cc: Jiri Pirko <jiri@resnulli.us> > 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> > --- > net/sched/act_pedit.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c > index 1ef8fcfa9997..77c407eff3b0 100644 > --- a/net/sched/act_pedit.c > +++ b/net/sched/act_pedit.c > @@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, > spin_unlock_bh(&p->tcf_lock); > return -ENOBUFS; > } > + opt->nkeys = parms->tcfp_nkeys; > > memcpy(opt->keys, parms->tcfp_keys, > flex_array_size(opt, keys, parms->tcfp_nkeys)); > opt->index = p->tcf_index; > - opt->nkeys = parms->tcfp_nkeys; > opt->flags = parms->tcfp_flags; > opt->action = p->tcf_action; > opt->refcnt = refcount_read(&p->tcf_refcnt) - ref;
diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 1ef8fcfa9997..77c407eff3b0 100644 --- a/net/sched/act_pedit.c +++ b/net/sched/act_pedit.c @@ -515,11 +515,11 @@ static int tcf_pedit_dump(struct sk_buff *skb, struct tc_action *a, spin_unlock_bh(&p->tcf_lock); return -ENOBUFS; } + opt->nkeys = parms->tcfp_nkeys; memcpy(opt->keys, parms->tcfp_keys, flex_array_size(opt, keys, parms->tcfp_nkeys)); opt->index = p->tcf_index; - opt->nkeys = parms->tcfp_nkeys; opt->flags = parms->tcfp_flags; opt->action = p->tcf_action; opt->refcnt = refcount_read(&p->tcf_refcnt) - ref;