Message ID | 20240216232744.work.514-kees@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp49281dyc; Fri, 16 Feb 2024 15:28:11 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXqv4eKu68PA4K1OqQuxGCc0Idf+d+yg/9GN90/mW1FD6/cAMsEqznX+vDWEjlGt7YYHCmwfUhcY/covPVJiVmQMxVaiw== X-Google-Smtp-Source: AGHT+IFWqhJBMhOPD2qzr9Dtar/1HYAJdTMvQOFsy7s43tocMT5lI+AEqs7QzT4GM0AtJXM2ehDi X-Received: by 2002:a05:6358:78b:b0:178:99cc:e52e with SMTP id n11-20020a056358078b00b0017899cce52emr6801679rwj.20.1708126091294; Fri, 16 Feb 2024 15:28:11 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708126091; cv=pass; d=google.com; s=arc-20160816; b=1KI8kBoTpbVdDEE++LMlRaeWdJmbvN0VLgDlGStiM6TsEGxFzMvIoPTLiBJgBIrnmk uGK7XUh2xwMgE5lsAaYet+uXGX9FOazgEY7HgHhexkfSJbymtAc/EWrl40/jRl2QEC6B n2eQCY3L9X/vB2ziVY2EcqARaOh03IRGqs1kqa/MGqYD328WXd+TgD2RYYT0xmjtAnrp RqDwf2LUzT4V5UYrmF0xO0A92QYFzghK67F3w54X/8pMGgni2oR87/6taIGLVAfSHMEH wfyge34Ej0TkBSbxXPO+wsCepM2AjDg+0EHc/8Pa3xKxC7Vxxs4AgiQcU5C4TgMSCLby 1Rzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=lLi9PHtxZsuZz7e5RQdykX5MWOEl3dE9qrCPIM1hrRo=; fh=hPe7hYRH+nNx8GgaPOXtVszlrouNy9YHJ4haMEXzjhg=; b=wIHOXeuatCsEho2Jcl5yvrIGXThAiMwwnH5gqgsw1oPOO9DzEbG1gIngj+wcwwHEj8 Fw+WN3mfYGsAsD+DdKTFxqguFC5PfPxFVg8uSgjfGcDg2iEnf1/O/JhUrm8x/O5uYYV1 2Uj2I/G0NDj3H0td+HpXQb7oTAWNdh3kFF7r2uAEXpR9S8TiB0+ZQeUVmjH0LruJoEsu EgmTzG/hhYCMjep9KD736Qmr6G7CBidjwfZDhzdl6khRZBKUT/pb+Pi90q2eDOJZPKgb tc21JMgUv1kpZ9LeNDbvJV+E52ZzIV9M5XECbzplDqH5t6ERZsepeFYyHWM5F6cGlKkg 7x+w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SRBq0NJN; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id r65-20020a632b44000000b005dc5070656csi561488pgr.785.2024.02.16.15.28.11 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:28:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=SRBq0NJN; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69478-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 139FC2894FA for <ouuuleilei@gmail.com>; Fri, 16 Feb 2024 23:28:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B0777148FFE; Fri, 16 Feb 2024 23:27:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="SRBq0NJN" Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 562F1146904 for <linux-kernel@vger.kernel.org>; Fri, 16 Feb 2024 23:27:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708126069; cv=none; b=k41uAX1uhtcAwUQMe5IV3n2xiR2EgKYJRBQh9zCOD5oHheswhaKUpp4eRVAuw1EAlD4Im2H9PJ8u8AOObvzdvJGdD3cDB4jwqmYVt4qafr6oE/nu9B3Ctt1RRxcWzWWnSUBD3qAJ9gMqIEM7t3mh3PBtLAONvYCwVPmopXK0G5c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708126069; c=relaxed/simple; bh=RNT0g0cgXQrcIvbNgrkk3LhFhJNchXw4WLd58eWGTyM=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=WMym5lUPTwVNTSChcJoMOhB++PV8eHIvO6E2inXQhdJ+AKjis8O/KOkxfDbKTBUxzZ5a+Lvf30EcGIZNrSNNnzFwJx9TdOVa76z6uISohtJSKLwApIE5WcQgdKyqDalPi6CchfFHTEmHqHZREeUF6mm1iVBH630ejsPeMYirvRE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=SRBq0NJN; arc=none smtp.client-ip=209.85.215.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5d42e7ab8a9so1946700a12.3 for <linux-kernel@vger.kernel.org>; Fri, 16 Feb 2024 15:27:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708126067; x=1708730867; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=lLi9PHtxZsuZz7e5RQdykX5MWOEl3dE9qrCPIM1hrRo=; b=SRBq0NJNtAZ6jpCpaDoDq0gS2MIV1sFPCquA0NnTAn0Bn4+TCURcDgAjIDwJ5oVser eeounGyiNP722gPZ4vqG3zFwHZeCT5zHIZZj/QNwLUB/DA6U5ImtNn8MuYPeAyPRlbzK /OVmhGvYIXJeeObYRBrFPapXbsXeD2Yx0EVHo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708126067; x=1708730867; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lLi9PHtxZsuZz7e5RQdykX5MWOEl3dE9qrCPIM1hrRo=; b=CSvE0fP+aWFSdkgYtiLU4we1ekgB7LZ0nCk2PsyoAfzh+o5NWWr1I0MMGfqOOqhMMT l+jmjlJOwChiuMkewUTSIkVJgZq8FKZtpLCTPgz6YSdY/reiKsG9zGw4CLIIALqhjYSt I2H+ZDoW0qC0YEFVaHth9Hnr3OKV77dYaPyVx53el6zxY13EjEg22clDZAEZi+8yyu8v hzj2vm9pq2vwtKTrZZz8PBBMcvcU58TUw82zMFlz5GO/LgjkFIyNdUR6ok7EDo10iUqT RGUFU8BYUX1uLoBS2FrMFAPogzrbLgawox+zV3W228C0HUn3uFNHh58hMSUIl8FVR0Kd Sy1w== X-Forwarded-Encrypted: i=1; AJvYcCWjB3+FQSfAxQ4YtHCovdFdPtMGvvCFJo8+Rrb2GcygA+R5j1SeIeYsvYXBPhKUvjmEo6oJtMiUPOhDzlHq1L69WYe2e/Bnx/h1/Ir+ X-Gm-Message-State: AOJu0YyPAZB0cxEtTFi2rRBKGAod9zd6NZTex82VEUkzBu7VE5xUCIy6 mz6a77jjw4tdoURB6Uw03zkKZ/9i0VuC19gLMlr8Yz92Go7uSJKobBf+s7zxmg== X-Received: by 2002:a05:6a20:4fa2:b0:19e:a9bf:d51a with SMTP id gh34-20020a056a204fa200b0019ea9bfd51amr5455247pzb.32.1708126067651; Fri, 16 Feb 2024 15:27:47 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id kn14-20020a170903078e00b001d8f82c61cdsm369379plb.231.2024.02.16.15.27.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 15:27:47 -0800 (PST) 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>, "Gustavo A. R. Silva" <gustavoars@kernel.org>, netdev@vger.kernel.org, linux-hardening@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>, Nick Desaulniers <ndesaulniers@google.com>, Bill Wendling <morbo@google.com>, Justin Stitt <justinstitt@google.com>, linux-kernel@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] net: sched: Annotate struct tc_pedit with __counted_by Date: Fri, 16 Feb 2024 15:27:44 -0800 Message-Id: <20240216232744.work.514-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2338; i=keescook@chromium.org; h=from:subject:message-id; bh=RNT0g0cgXQrcIvbNgrkk3LhFhJNchXw4WLd58eWGTyM=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlz+9w9qSnRo2mb+YJM+Gu1IwPUsAtgHSw+l89v SbeoLT1YpuJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZc/vcAAKCRCJcvTf3G3A JgMGD/9xRXBIxLCBH7+ga8H8o/WOsCi9LCOVzwWZDpHbh6TZefl0ftvDhBHx7fg1n4l61k6f3w9 1El1BpQBebgi7nX+Ets4Ub4/N8660HPXoRbAz6As6Ne5h8z2F1kw3ZBn6ITb7uqN2izMxRfy3/T 8XA/eTuICYCEYDIQa4FqnmhVLh6WkR8mN0/N+LTAymXxd00ECGrhXlJW2dhrUhhTbhkzdvUF3WB XEWJGtf4nP0kA3omfRN5CDGZ0YjDY2GS1mKIvj6eoJZrXXb+a09jCGPm9Y7qU1MB0F5A8pVlwNF hK3T5yvnAdsN2FsboC223ZEzRd9XnGjM+xA+ZoQtpE5cKpu/HX80H11TmqAw/RZZtwbycKZ3MN1 VAlI70Igu9n71hjMCRL6of2MjZud4bPUAduFb42FOvZvXqiKkkwRD0LAy0+R2VX8/KsB2E4TrUA vKh4f615Zd5qR3DKd3mjl1F5VnBxqa7oW67YYU/f+MCg86r+pT9RYj3Yl2tLNnjtBTLG+ePv8rK otI00CvwQ2/R2IU/zEL5jtJqM9y+xTTP4Y2MVa2Mv/3RJSPHSSV8x40Hrpc+RA6rIjMFj19BWI5 oKc5WEPBofLAACgXz8fhUrXfyuUZfg0qeE0JqzukNFzqWGCbGESpOyHoQBYnslPSqhqGdZ3oJjl TVrnnPI y3rX9jFg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791100024269477570 X-GMAIL-MSGID: 1791100024269477570 |
Series |
net: sched: Annotate struct tc_pedit with __counted_by
|
|
Commit Message
Kees Cook
Feb. 16, 2024, 11:27 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.
Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1]
Signed-off-by: Kees Cook <keescook@chromium.org>
---
Cc: Jakub Kicinski <kuba@kernel.org>
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: Paolo Abeni <pabeni@redhat.com>
Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: netdev@vger.kernel.org
Cc: linux-hardening@vger.kernel.org
---
include/uapi/linux/tc_act/tc_pedit.h | 2 +-
net/sched/act_pedit.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
Comments
On 2/16/24 17:27, 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. > > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > Signed-off-by: Kees Cook <keescook@chromium.org> > --- > Cc: Jakub Kicinski <kuba@kernel.org> > 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: Paolo Abeni <pabeni@redhat.com> > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > Cc: netdev@vger.kernel.org > Cc: linux-hardening@vger.kernel.org `opt->nkeys` updated before `memcpy()`, looks good to me: Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Thanks! -- Gustavo > --- > include/uapi/linux/tc_act/tc_pedit.h | 2 +- > net/sched/act_pedit.c | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/include/uapi/linux/tc_act/tc_pedit.h b/include/uapi/linux/tc_act/tc_pedit.h > index f3e61b04fa01..f5cab7fc96ab 100644 > --- a/include/uapi/linux/tc_act/tc_pedit.h > +++ b/include/uapi/linux/tc_act/tc_pedit.h > @@ -62,7 +62,7 @@ struct tc_pedit_sel { > tc_gen; > unsigned char nkeys; > unsigned char flags; > - struct tc_pedit_key keys[0]; > + struct tc_pedit_key keys[] __counted_by(nkeys); > }; > > #define tc_pedit tc_pedit_sel > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c > index 2ef22969f274..21e863d2898c 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;
On Fri, Feb 16, 2024 at 7:04 PM Gustavo A. R. Silva <gustavo@embeddedor.com> wrote: > > > > On 2/16/24 17:27, 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. > > > > Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] > > Signed-off-by: Kees Cook <keescook@chromium.org> > > --- > > Cc: Jakub Kicinski <kuba@kernel.org> > > 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: Paolo Abeni <pabeni@redhat.com> > > Cc: "Gustavo A. R. Silva" <gustavoars@kernel.org> > > Cc: netdev@vger.kernel.org > > Cc: linux-hardening@vger.kernel.org > > `opt->nkeys` updated before `memcpy()`, looks good to me: > > Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org> Looks good to me. Acked-by: Jamal Hadi Salim <jhs@mojatatu.com> cheers, jamal > Thanks! > -- > Gustavo > > > --- > > include/uapi/linux/tc_act/tc_pedit.h | 2 +- > > net/sched/act_pedit.c | 2 +- > > 2 files changed, 2 insertions(+), 2 deletions(-) > > > > diff --git a/include/uapi/linux/tc_act/tc_pedit.h b/include/uapi/linux/tc_act/tc_pedit.h > > index f3e61b04fa01..f5cab7fc96ab 100644 > > --- a/include/uapi/linux/tc_act/tc_pedit.h > > +++ b/include/uapi/linux/tc_act/tc_pedit.h > > @@ -62,7 +62,7 @@ struct tc_pedit_sel { > > tc_gen; > > unsigned char nkeys; > > unsigned char flags; > > - struct tc_pedit_key keys[0]; > > + struct tc_pedit_key keys[] __counted_by(nkeys); > > }; > > > > #define tc_pedit tc_pedit_sel > > diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c > > index 2ef22969f274..21e863d2898c 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;
Hello: This patch was applied to netdev/net-next.git (main) by David S. Miller <davem@davemloft.net>: On Fri, 16 Feb 2024 15:27:44 -0800 you 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. > > [...] Here is the summary with links: - net: sched: Annotate struct tc_pedit with __counted_by https://git.kernel.org/netdev/net-next/c/1e63e5a813fa You are awesome, thank you!
diff --git a/include/uapi/linux/tc_act/tc_pedit.h b/include/uapi/linux/tc_act/tc_pedit.h index f3e61b04fa01..f5cab7fc96ab 100644 --- a/include/uapi/linux/tc_act/tc_pedit.h +++ b/include/uapi/linux/tc_act/tc_pedit.h @@ -62,7 +62,7 @@ struct tc_pedit_sel { tc_gen; unsigned char nkeys; unsigned char flags; - struct tc_pedit_key keys[0]; + struct tc_pedit_key keys[] __counted_by(nkeys); }; #define tc_pedit tc_pedit_sel diff --git a/net/sched/act_pedit.c b/net/sched/act_pedit.c index 2ef22969f274..21e863d2898c 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;