Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2322036rdb; Tue, 3 Oct 2023 18:45:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGUKRmNS7WZtqjXLpOv8xLvN8bpqqyRbqgILx9PYMs5GepR6NxMNS84cyiPMN+BY7fqy43c X-Received: by 2002:a05:6a20:104f:b0:154:e7e6:85c8 with SMTP id gt15-20020a056a20104f00b00154e7e685c8mr973363pzc.31.1696383945907; Tue, 03 Oct 2023 18:45:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696383945; cv=none; d=google.com; s=arc-20160816; b=OKeI2JBei6qxfmUSXW+zUXRr4PcCLxCzkb/5MgZUAprJwigojaSr9fSm3ZJeQQU1n1 JtXqk/v06vs+Cyfdxd4L+Rtgr6cHpzUlUN5eiArTUSRlfVjs/plkPRUSPL39FTh3m07A Y3+0rtcSuR+/hM2+KUm/zIaZrZNT2Qgjy5o9WaeukBEBBTVofFB9suWxtGDddUpKXvjL 5RYCSJ/f2FEnwjBOC82rXYLqCs85kdwgYJyg6PheYcaBeU65lrYpCTeSJ9IQX7YpU4cj RmeJal7ySH3mfQhhi8DgdFlHbRtYHI62lDcWt+nexh2IDg1u0doFcfCvrfsLgoLTNoC3 9igg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=6m+ltiUxBgyP6O6NGVJRhv6n+IMmSQtxpfXHOcBL8MI=; fh=9lR+DZLvOVudmWd/QFgwR0a8yuSr2x3rujqpFV27fY8=; b=lce/sXg2lt0wz7xaam+eQen85AZLyLcIDmc1/OzPhTEOotRXRWWR2BOG8q/wMWTPXU YplghlPBPLbgQLul8QDFNtb5qXLkA1KX+G/HIH/RXbgeXeJvKmQ/W7jr+c6MNIZMIwW8 ucvyqn3KvRXZCF0PnDj+7M+vCb1ExLznNwSGAcOeM0q1/Msai1pnb3XYRrxA2V05UjNX 9UYEXlP3qhMxaVnuEaUuOazNKF3x0v5BzTgx0tYkrM+jCxmPPj0eUcGmDjb4AnloYXaK Ufh6pagjZSHmDyOdXnNg4pM8sf7qfbgr8C36hxWrWgQYwQQeRjsb1vT1X5jW1gDVRIkt qvig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cxbpQhcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bw16-20020a056a00409000b0068e3efffe2csi2749657pfb.243.2023.10.03.18.45.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 18:45:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=cxbpQhcl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 71590806A606; Tue, 3 Oct 2023 18:45:08 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239709AbjJDBo5 (ORCPT + 99 others); Tue, 3 Oct 2023 21:44:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbjJDBo4 (ORCPT ); Tue, 3 Oct 2023 21:44:56 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5547BAB for ; Tue, 3 Oct 2023 18:44:53 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-27763c2c22eso1139635a91.3 for ; Tue, 03 Oct 2023 18:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696383893; x=1696988693; 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=6m+ltiUxBgyP6O6NGVJRhv6n+IMmSQtxpfXHOcBL8MI=; b=cxbpQhcllg9aTHbTy6a3vGKZq5DMQujQscQ01G285jPDoIIoOdHUr3WWFzyyJzvd3d KI+VNTG/FSdBUPyYQ3XVZ94EpOo2eOwBG2/yG7rEVFrJ33oiDlQOSWqMPafrHk0QUCrK T8Sy7zuVGoRHdu72VNg5Sv31yZiQ9K9VKdldw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696383893; x=1696988693; 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=6m+ltiUxBgyP6O6NGVJRhv6n+IMmSQtxpfXHOcBL8MI=; b=xDWNYnQGNGZZ0e/stNUC3sHcgSIAl4EMSjexQv7ZE6hMgp3tCX62i4lPLYWm4Y1f1X jhHtRl0DF7WbnTWTSynHrPlFDJlN3vWbv18K456zBos5Rqw0IJNH0bv2qE48b/2EMY+e cNZ95cMBQL+xEX7vMGA2JB2kxzyFpq4EAaGrhweq1D8KBAKDITz5fwQ6xxRDKEedisur Pf6NHZQ0mBf92s1GqX6AeGpH+fgLenV3me1kQwHI/SpjpK0ZYrJ7zibIZjXEo33lsP6c mWFRrSfUKB8pp0h+j96LSimaEAUhoJ3Y5t2+2W0X19aCkdAyJ0z+XLPudelkLO25VtGU 4jXQ== X-Gm-Message-State: AOJu0YzdVHybZzDdZjB/tBXls8mOxHDqnkTlYCSOpWRUJBemJE42iCI2 WRsuj0DwKWDkylSclP1gK38XVw== X-Received: by 2002:a17:90b:164f:b0:274:735c:e2d3 with SMTP id il15-20020a17090b164f00b00274735ce2d3mr999366pjb.8.1696383892759; Tue, 03 Oct 2023 18:44:52 -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 13-20020a17090a030d00b0026971450601sm287996pje.7.2023.10.03.18.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 18:44:52 -0700 (PDT) From: Kees Cook To: David Ahern Cc: Kees Cook , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: [PATCH] nexthop: Annotate struct nh_group with __counted_by Date: Tue, 3 Oct 2023 18:44:49 -0700 Message-Id: <20231004014445.work.587-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1227; i=keescook@chromium.org; h=from:subject:message-id; bh=cMswho+iyVCS84W5fjbN8jRy801YZPgydXwTL+hQ8kc=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlHMOR/Qnr9xsjz+RFrB//RUqkmhmuWuLMRFIHY H/zRm5APC2JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRzDkQAKCRCJcvTf3G3A JuubD/4pBLzIK8LRipBfuGiuOfRseLiRbFNh1J5EeR0aFUlyz21VWo/ONGuXtGXOxgktDliVWxQ pv0tg3RLvxJNCOGY0pFJOG7j7tgN8w7Tn1Eomvh7IHQ5UyysY1/txn95G/iwzma9N0e7cspWjOk i71eVTwBrYMFx/XI4JIGT/Y9Zt1Z7uXKyqTlkZXE6kTi3ZsMUE37k9g0yX58iiGmmdLols1ocL0 rqjyPdN/KncryQkGHLsjMD3SXftQJUoKrZK61q7t0of7ZLGX8o4I0yTevYIk1imAMduLhWTqEYR n5BRvPG5JvAE5d8L3VsggU36WF5pidU5c5RPVzoOeztl69WWEB9ecpndC9ok0Z2xCh48x36HD/G G8235S8ONP14DbGP/eVc/1yqdWpS4vrLruFiJ1HySU5pHPtGQ2rcuJbbPDQx35xXPl6D7okwBw5 6MMdORrwX7unzOIOhGIWeKBICZes22QAxOctpG8/+dcQkEIty1JY7KSivhZUA1pxzAp73DIoOtr hNj60Fetls5Hcp93vQjT0Ls91cpLL/i80y2sZmrX6m/CIEexZMYuGUrLdBMlDJrEb/v487rDH+P CEGyWn17nSifdO3/K+Cm1GoILthQET2DXe6j2wjQk5tbiB+Rs+XVL9eXb9mtQUGsB5NdyB+aJU3 MmGRBkZ wCCDJXzA== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 03 Oct 2023 18:45:08 -0700 (PDT) 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 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 nh_group. Cc: David Ahern Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook --- include/net/nexthop.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/nexthop.h b/include/net/nexthop.h index 8f5a2ab45920..d92046a4a078 100644 --- a/include/net/nexthop.h +++ b/include/net/nexthop.h @@ -126,7 +126,7 @@ struct nh_group { bool has_v4; struct nh_res_table __rcu *res_table; - struct nh_grp_entry nh_entries[]; + struct nh_grp_entry nh_entries[] __counted_by(num_nh); }; struct nexthop { -- 2.34.1