From patchwork Fri Oct 27 22:20:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saeed Mahameed X-Patchwork-Id: 13439214 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A7389C25B47 for ; Fri, 27 Oct 2023 22:20:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbjJ0WU1 (ORCPT ); Fri, 27 Oct 2023 18:20:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbjJ0WU0 (ORCPT ); Fri, 27 Oct 2023 18:20:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45BA71A5 for ; Fri, 27 Oct 2023 15:20:24 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C325DC433C9; Fri, 27 Oct 2023 22:20:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698445223; bh=etudxdGtBrISOhVFfZeRsNdQQI6GSAO3tH9FQxYSOVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YiAq1o9EmI/OECSxftjHInU+e/9EI4XfytocB8uZA8GdpyMj7hiCglCme0/R8oBm5 HOd8O1w70GxC4zy+KbUtglkS/6yi2LPxanMTgg28cSK9QRv/ectdX2enFJuN00orLG knS4zsRja9Brcaxx583es7nfEXviiLu6ltZ3DoxYBq16409cspE6KSaYGhDl1yVSB+ 9s9VGRtFSQ/pQAG33Q46sOJ+byT7pzlmObmCb9/ZvbUlxHertccnebU6CT9o1vZHhx odXC2EwYqNHreU+97EUHkvQhd0sCxaCKlzltcoPalonGhZpHPoscV9PYWgtSw6Mlk6 +wPbqCdgy6vqQ== 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 08/11] net/mlx5: Annotate struct mlx5_fc_bulk with __counted_by Date: Fri, 27 Oct 2023 15:20:03 -0700 Message-ID: <20231027222006.115999-9-saeed@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20231027222006.115999-1-saeed@kernel.org> References: <20231027222006.115999-1-saeed@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.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,