Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp125567rdb; Fri, 29 Sep 2023 20:25:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGbdqqKPXCu7AOmeTgKAB4F0lcpeEGWVcvKxYAuPNwvjdUSlTbLILXlD7qBrIo0HnhHq0UY X-Received: by 2002:a17:902:ed8f:b0:1c3:21ae:7a4a with SMTP id e15-20020a170902ed8f00b001c321ae7a4amr4831264plj.38.1696044326999; Fri, 29 Sep 2023 20:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696044326; cv=none; d=google.com; s=arc-20160816; b=MINcI+hrhg9KiKbOa+JdswbC/8boPFc+OQFiO3B/cTXBsy99N7FTnfk3hL9CXxvN3u Wm2SWmPTOfbGS+r2LEoTtOycwMxHw4rnnn/sWtVn8PZ/BJZxyhvUArMPWVJwL/CGA2BO rnCiiD6BBpwiM8geSZGaslYv7jFMtLaqDcrU6CL44i7RC9gOAz8lXXy+MmY1V18wvogp AGUPwy9inuyuwdavfg/FPWhDsD0eiWfrOZkzIph0YGZ2Msydt/fpvuqev0kEN2HVXmLT 4EkQn2NxIwyV9/wYr1NPMyGzIRRCqbn1akz6izcMeRA0hVEqvlRtC7EmGdZCOKLyGd7S 1N1Q== 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=Z1fCnyMESIUDw106GjvVeHm07JaGiyNbi4ApDENYnlM=; fh=NdFsn03G0BQ0yIy7PVh6T+GPRerauJ+2EiKxLNReKMQ=; b=UaQPu8IfJOBtTJGVRCOyom4+rdlpK1rppo3RtJrp+Z2iaz+zeItb5OeRD0hZ09Fxxl kAF4P3YTNEVShDfxeEipoQjsLYQ4xTGD/BdKChTnJQxyDF3N6LFNWgu0Dy2DVPXnbVWG 1cr8gzV5fJZeil6PgLXJ2pVeAqYss2dhpYu+WRNMyPx4Q4OtTfQw7OYlkSQZwxOKVB+s RWbZYL8CTVD99bQOShMO9dlGr+n1Fr2TEDqyCheOG8sqUQn3f2EigGMskjGOgt68B6IQ mQRdn/e9HPjYcomMBc+oGUsjbl4/aNjCiFOoS9JrZbeqbbBxkuACVFXyF6QaWAUtyFgx p0JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i7xHrXvm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id jh19-20020a170903329300b001bba90f8b73si20881755plb.78.2023.09.29.20.25.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 20:25:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=i7xHrXvm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 21D2B820DA0B; Fri, 29 Sep 2023 11:08:05 -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 S233798AbjI2SH5 (ORCPT + 99 others); Fri, 29 Sep 2023 14:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233717AbjI2SHw (ORCPT ); Fri, 29 Sep 2023 14:07:52 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15D871A4 for ; Fri, 29 Sep 2023 11:07:50 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1c60cec8041so77448825ad.3 for ; Fri, 29 Sep 2023 11:07:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696010869; x=1696615669; 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=Z1fCnyMESIUDw106GjvVeHm07JaGiyNbi4ApDENYnlM=; b=i7xHrXvm+x+CXquDtwP3n/6SITwyQLaNnPs/iDit5wVSn9kPZ8ni8jT0KLjaFj1bCn Ol2D23xwnqUrGXkm0hdDWcquaq4LlQ6Z3+qZb8YvupZjLed4EqP4vMcKAl4Sce/U57Ne VNoIs2qPpRmdcN2+VHjE2NTdqJB+HGG2DulUc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696010869; x=1696615669; 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=Z1fCnyMESIUDw106GjvVeHm07JaGiyNbi4ApDENYnlM=; b=XIVY07gaDxDfVCal+1tXFntr9oeObWvMC0bTqJY4M17eZSiN9xGNlittn8MjSzdUHB VZcjd8wYYhcYj4ELlGlihKYLAVJX/2akpRI64qvD0fDNC5xJ0phCeR4hJ7XaPLMbHDbP O7/9yGCK7Q1r6TjxFOSZlatgFypA/3YHQOc3u8ROvEZnfL4jTQTN39MKd589cLeJNQUs JxypIXmacAh4cQ9bPp5qLsyLVKH5X1YcwRWgJa2nwtiSoXs9gID/+slwdRQSDFLieUrC /tnEclqKwyYWH+x+48XsFs/Cmwrj1TltY9e2u6P1IgQRvqz/sSw7CXlBvbQdKwqsinOt qmSA== X-Gm-Message-State: AOJu0Yz+HQ+zn2s61fgLr6fE5OFdveSOKWGbVaOaeH4XYrQhtdKncJXk JCmPojTmfRV/8SjZ/yoeLIlLIQ== X-Received: by 2002:a17:902:c408:b0:1c4:5c05:c3c9 with SMTP id k8-20020a170902c40800b001c45c05c3c9mr5808758plk.56.1696010869523; Fri, 29 Sep 2023 11:07:49 -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 m1-20020a170902d18100b001b8b1f6619asm17332300plb.75.2023.09.29.11.07.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 11:07:47 -0700 (PDT) From: Kees Cook To: Ido Schimmel Cc: Kees Cook , Petr Machata , "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 3/5] mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by Date: Fri, 29 Sep 2023 11:07:42 -0700 Message-Id: <20230929180746.3005922-3-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230929180611.work.870-kees@kernel.org> References: <20230929180611.work.870-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1611; i=keescook@chromium.org; h=from:subject; bh=+RWfw0GyGwLXMxH+fSx74341Dume6vULCGctkWzJyII=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxJvQ2MJX5MIYubHbp+JLru78XV8PSD9HfCip MzkMrfhDwOJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcSbwAKCRCJcvTf3G3A JnRLD/9EGd9KZ/Tj7Icy70EINkAG/rdfxW+EXWV6I9tI7aqUVeByxYSzHqj8FOidkSGNCh4jARc +uXnybahYfPpBWVV41kZfAhAIpxzSoq6s8NuNmkX6T8LHkps1oWxj6pDoKaoFfCMdsAhNUK1xcK UiU2qHZHzc1qKNWo1sAcHnPjme+swZST7xHSQ8SF2E13eDaQvKKEpdPeGtSNgPEV8yLj58EN7a0 iP8n1qZPDs7IoEuCGekv4cGmTTaSzUDc0R7Za2m+3bdHl4DcF9E+nOig6tbTybEZi1aNNjPdNL+ s+j9/MzDWmw9GMUxIetw7H9laEtIav7YYaf6G8aRv+wTndvPDcfVqBcvfdYnZNx0/rgJSm4e1K+ QhoQGun8o9/gzP/Y0vAq9j6Fqo2XYbAy9jfvjwol3QlvCJMu54iuM/U5nr6GkAWJ4k7d9jZiVFx W2aBOpvnHsbXQd8exwGC8sDd5XFNezCGfQ+qK0pWvD3xzZtJ8mgiQFrhnx7KZDh2+fYU33Hzy8K 6beObhLWjwE4DYbXYUH8YXOE31yPMSY5K6435NP9Zhlwr4oB1bNxjmDgCqJC73O+PFfJuj6UzKl fpEuOHPJVmLtuWUTjz2a/oXMxNT4xkygpO3lIq/qJUoDhiJqrHWI4WM1E4GV4EiRdSAkrIFp856 Z9rPTNG+P+HSMvw== 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_BLOCKED,SPF_HELO_NONE,SPF_PASS 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: 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, 29 Sep 2023 11:08:05 -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 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 mlxsw_sp_counter_pool. [1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci Cc: Ido Schimmel Cc: Petr Machata Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Signed-off-by: Kees Cook --- drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c index ee59c79156e4..50e591420bd9 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_cnt.c @@ -24,7 +24,7 @@ struct mlxsw_sp_counter_pool { spinlock_t counter_pool_lock; /* Protects counter pool allocations */ atomic_t active_entries_count; unsigned int sub_pools_count; - struct mlxsw_sp_counter_sub_pool sub_pools[]; + struct mlxsw_sp_counter_sub_pool sub_pools[] __counted_by(sub_pools_count); }; static const struct mlxsw_sp_counter_sub_pool mlxsw_sp_counter_sub_pools[] = { -- 2.34.1