From patchwork Mon Nov 13 23:00:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13454517 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE7A73D96A for ; Mon, 13 Nov 2023 23:01:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ACF8XtS4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 37999C433C8; Mon, 13 Nov 2023 23:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1699916479; bh=etudxdGtBrISOhVFfZeRsNdQQI6GSAO3tH9FQxYSOVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ACF8XtS4k5zsww7jYZlJfiVzuhJDxRZciFjaXH/SIT/KPFFka48cTqnqU5hAGLooo GsVerjmqR6hR+ZW5Qrh9MiXIVw5ODGacKxze93bxw0s+W4uNKlMxnr1vMXJfEl3Hd9 mYR4dRuJ16wOXi+3sNFxiqn4/vdAHJ2SCZHwLMy0ZJC9xoT4z9cimmIOwvFrRQ7Ono 3ktMKSlePbCA2k1o7u57Sl4G/B+4R+RB4BXJCTXLdVesudN9dj3U90H0erXn0I744I oI8fcf2+TJT4aHkNUVT3YUiFgsPsy47AMzuuldgEqlMCX7KHXd9yX2PSjqXM6ARUv2 nSC/bv9hiVBxg== From: Saeed Mahameed To: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Eric Dumazet Cc: Saeed Mahameed , netdev@vger.kernel.org, Tariq Toukan , Kees Cook , Leon Romanovsky , linux-rdma@vger.kernel.org, Justin Stitt , "Gustavo A . R . Silva" , Leon Romanovsky Subject: [net-next 04/14] net/mlx5: Annotate struct mlx5_fc_bulk with __counted_by Date: Mon, 13 Nov 2023 15:00:41 -0800 Message-ID: <20231113230051.58229-5-saeed@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231113230051.58229-1-saeed@kernel.org> References: <20231113230051.58229-1-saeed@kernel.org> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Kees Cook 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 mlx5_fc_bulk. Cc: Saeed Mahameed Cc: Leon Romanovsky Cc: "David S. Miller" Cc: Eric Dumazet Cc: Jakub Kicinski Cc: Paolo Abeni Cc: netdev@vger.kernel.org Cc: linux-rdma@vger.kernel.org Link: https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci [1] Signed-off-by: Kees Cook Reviewed-by: Justin Stitt Reviewed-by: Gustavo A. R. Silva Reviewed-by: Leon Romanovsky Signed-off-by: Saeed Mahameed --- drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c index 17fe30a4c06c..0c26d707eed2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_counters.c @@ -539,7 +539,7 @@ struct mlx5_fc_bulk { u32 base_id; int bulk_len; unsigned long *bitmask; - struct mlx5_fc fcs[]; + struct mlx5_fc fcs[] __counted_by(bulk_len); }; static void mlx5_fc_init(struct mlx5_fc *counter, struct mlx5_fc_bulk *bulk,