From patchwork Fri Sep 29 18:07:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13404736 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 BE9B966690 for ; Fri, 29 Sep 2023 18:07:51 +0000 (UTC) Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7709CC0 for ; Fri, 29 Sep 2023 11:07:49 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6934202b8bdso3273421b3a.1 for ; Fri, 29 Sep 2023 11:07:49 -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=oOLSGowyT8bp59dkGdiGtSiQE93Lo/hrKnsFucy41H4=; b=gh7W3iVJn11bb5eYM1M1fVlqbLwtiZIuAAOJVZnISy2HvMEB+zfMopBuJ4PGkgtHIM l9SCYIZN7MmTnN7vezdltKvpWefWPFnTBaCaUH+/t0TJl1YZyJgcLJXKulS16fdeUsLn bsTDJK3OOCdDgmutff8UgfcJXBtyLKHnCE1ng= 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=oOLSGowyT8bp59dkGdiGtSiQE93Lo/hrKnsFucy41H4=; b=BH6TGyGwXVJbPFKBKNmzwplvKjtVRcG+kHrLyIYPFkz0bmmZLhIRB9gyUd8Qx9siPT rtoW31O3/vGRJunN4uJx9QQo03YhlB0BtS2G/8u/Pi6zxAv4J5mqLKjpwp9FHM0C+BTP LaFO2fdPyzipRVW62Lg0k9Qa6b8a8H1Pb5l54II1d3l3JLp0znmknKDpXqaqlap+81Iq ZB2rswyS85HUlOnJTf4nGlLG2r3w/qjksxavMv/m8DStv3GJ/quyTqAkaGUglWvbImFl vKHdK8GzIMaRiPXmrFzu0XrcAhz0fZbXu6vnqDwY/KJ/WUK1NAhDhQsCWzENYIIN48Oz sMTw== X-Gm-Message-State: AOJu0YxYyYZsZFpoHJDRiXOeHWnfjTaH/dCgxains9kGiwaGDhu8leUk F9VNfxkzY5GWS+MbGss+MEKeXWRfNWvG2D7/1eU= X-Google-Smtp-Source: AGHT+IHt6XuabPSXjyyEobQ5AIUyk6V8GvupCIuIQkYjXOPloy1zy3GSr04SteVu6zvpk0axqF3tFg== X-Received: by 2002:a05:6a21:3b46:b0:157:be16:b6bc with SMTP id zy6-20020a056a213b4600b00157be16b6bcmr4419165pzb.59.1696010869260; 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 y24-20020a1709027c9800b001c3267ae31bsm17133941pll.301.2023.09.29.11.07.47 (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 2/5] mlxsw: core: Annotate struct mlxsw_env with __counted_by Date: Fri, 29 Sep 2023 11:07:41 -0700 Message-Id: <20230929180746.3005922-2-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> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1591; i=keescook@chromium.org; h=from:subject; bh=L0oxTPzJo9bLm3xCYvLC1IanmGV5YjHUG5FuRGU5Jf8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFxJvMgcoNzYyB72yjkUxJlGtHiv6i26l9q3H6 AWqAtX6Z4qJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRcSbwAKCRCJcvTf3G3A Ju3SD/0aUZX3WDL92XZp5/H8KPI87sDe7TXiou5k61Plb0QhqKrJm0EQvvtFmGQ8yngu0YzXBDM /QQNMEOQ2cHyyMTjGimcMw0tFZWAV7NLgHg6msaDMIsrspl5Oev6Z6e8CZODAqAveaOEP6an6Xv uPlhAv12ovRr/ARjStdeLWa06Q6buKRjbyekciSkT6E69f3tej6z3CcxbXt5n6KUbj6wzfMy+Ie Y6CPL/otBsl0Am4dZG02Cq4efJtZ9y+2rUAI7S/9YTRr8zHPEJEIwB6O1vTsn0wr1y5p1GuMvXg cz51ljKx7ftiT/KptN/6KB6m3vInGRUKZSDZsTtBUIkST+MhSL5HbM0OKHNe/fA0+3nrJBDIToR awf71Nh8sT8X5NhbYQJmRHRiWgn0cvoyIZ6FoDo6G2u5FYgetEpYI4gJbSFfwzhBl9BYzeSlRYg KCpcGhfNGVLxZHppj8PpwtslwJhLb+vPrZrLiqhWSZW209VA+l+fQUBdeGEoANXy4UStmAGhUcN oQ2LCzJ8YbW1ORVDuMlnzsaXZoMRhyIrUCbcZBZP5ON/h6tSYSyLH9Z8vphrEIr+7/XuDhHeUP8 qtvJvfjDXAEVGyjL6s84rvuAHdNLq9TNbMlrrXlb8cq7gOTdf1mtQq7zyud0Da7vFI+AyVBvYeH PkjUGZ7qVyTgCoQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 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=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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_env. [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 Reviewed-by: Ido Schimmel --- drivers/net/ethernet/mellanox/mlxsw/core_env.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlxsw/core_env.c b/drivers/net/ethernet/mellanox/mlxsw/core_env.c index d637c0348fa1..a129e0df1d07 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/core_env.c +++ b/drivers/net/ethernet/mellanox/mlxsw/core_env.c @@ -34,7 +34,7 @@ struct mlxsw_env { u8 num_of_slots; /* Including the main board. */ u8 max_eeprom_len; /* Maximum module EEPROM transaction length. */ struct mutex line_cards_lock; /* Protects line cards. */ - struct mlxsw_env_line_card *line_cards[]; + struct mlxsw_env_line_card *line_cards[] __counted_by(num_of_slots); }; static bool __mlxsw_env_linecard_is_active(struct mlxsw_env *mlxsw_env,