Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2272256rdb; Tue, 3 Oct 2023 16:21:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHnUXFBOzLq/yAsholhoqoOvq7rGnJok6DBbpvQXFh9giK83Z3RU5YfxOwpNcAMZYCoqbNC X-Received: by 2002:a17:902:e74e:b0:1bc:3908:14d with SMTP id p14-20020a170902e74e00b001bc3908014dmr7029129plf.2.1696375305521; Tue, 03 Oct 2023 16:21:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696375305; cv=none; d=google.com; s=arc-20160816; b=Mf/lNIk0HH6XOp2F3qUexjPbzYKmeTLUE/PaEpZjlBQlhVOcrlLSQM6Pzml5w3o2Fi 8ZQIucICpmfnE+buq8eivFA0Vme7PoxuTuIcnGDWBXRncHWfX2krCk1wdRVgdJuY+UvB QCJ24J/hzdN108MSptZ6mfv0bLWnAGdqBjnVV2prt+cP54UE4NB6HNNejvjJ4nSrz6sY OY3FGiyXIhjd+EYFAvS1YzcXjwrKhuuhgdbNDePVQXXG4MrULUqzAqKyOLK7wYBQ75Hl hajgUA2cb4MkNst+jM/4SlzHWYl7xhhx5lCBq/hia7yYYUH01uy0koM3MnMjjfErDLEi De1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+NEDkCvEYEdfp18YGZL4PXY8c/uK5lT9K+U1l2rQw9o=; fh=jVxJYofHTXhHvy0ZGtBuLFS8X3F1FmMY0c2Fp7VOn9o=; b=wZe5EWIqt9DkIdAAEmsOFwmkt63l6ROdT+Q7JAYIHuCdHWJ51rKfowUROPem8JZvkV miKvbXeo3JsxeDi3nKleRtvXya7J5fdW9wGi0oVrx+2rBb0v/uJAjY02UYo7HDl8wQ3l v3IIMZ/oGmDu8RHRcvdHJsQsuluTHMrUfZrD1TG1dQeYIyB4HCKFVL5w7CcmyFD14Ne4 7cKdslCO8nC/05GOMfKjjSw3EP25IWmrXpsOTYtaLLCOa1IAqgoCzkwVy517wwlJ0Vk6 wvyO/mD8koZHx+3gFwcb9qQJcaGGmBPAX50Gx53NJM9xGJV6y6CbJCEe+xKTYDZauzis 44Sw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="KwtW/htc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id a21-20020a63e855000000b005859d13f276si2327116pgk.569.2023.10.03.16.21.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:21:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="KwtW/htc"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id D47838127262; Tue, 3 Oct 2023 16:21:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235508AbjJCXVY (ORCPT + 99 others); Tue, 3 Oct 2023 19:21:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229805AbjJCXVX (ORCPT ); Tue, 3 Oct 2023 19:21:23 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 513C3B4 for ; Tue, 3 Oct 2023 16:21:19 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-533c8f8f91dso2570774a12.0 for ; Tue, 03 Oct 2023 16:21:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696375278; x=1696980078; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+NEDkCvEYEdfp18YGZL4PXY8c/uK5lT9K+U1l2rQw9o=; b=KwtW/htcSF8wCE1h1q9KJuNnION/f7zBC5ccXE8vL6QPJ5nnQICxb9+2b0a3tinhmF kwJXD7NdV4pnskp8PpnlUbaojPNdi/wZQtz0o02DaGyd5wnmc4lhkmUj9X1Ou3yktij+ qIOoMehggHBFBiUshyuh1jbFaZ6K3Y8esKhKvBYDXyuL1QyF0IJtVXiviJ3+qE2rGb3x PpQ+eV36T/POgtKQK7r3mXgUTqT8HsQv2RInH3VjF3G+KDd1lBj04nF9acIt3V8cOhGS +6VYUI7xVuTOJILbCyL1jxI4xCB26dClhtwqVI/Qx07ZDOx2W4Q1edjzgG/kiptL3ETp aWGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696375278; x=1696980078; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+NEDkCvEYEdfp18YGZL4PXY8c/uK5lT9K+U1l2rQw9o=; b=QFZgaw7Lu2y4JbibgPry6f0Ktxj916GwUXOZngs+hnhiMPdbA61e5ePMCfP6Xs9cxq +RNpM2OthAce7W6cJI9bKd+wSZKoR+OA36eksXObUsRHBTXk7jTbAnnhrtkVLHtqbTev eCV3o0uBsihFKRflBzr2c7lIqHpE5Mj6PDgPC3003sPLthq8yhEp3V3IfSpHwxgh/pd5 wDZRA/nuOB7LYx8o2PouDOfzDOMN5OzYdzLjQsWJZQ58tw6OPUDnLBJDKGN3iQ7SLY32 8xHuW5PRvRPskvHpP9taCT88LXp1XMSvYHdtiJrrMOGLxtu9MaFRaxvdnwe0oOTYLW8y 1xpA== X-Gm-Message-State: AOJu0Yym/c3mvPpUd/4EMUOWexjhbCsejHit2xHJmCi4bXxCtR8FNkod RBrmyqhLWeYUkYKrLbh4n9jLFMvHGOr+bc5I+wgf4A== X-Received: by 2002:a17:906:3ca1:b0:9ae:55f5:180a with SMTP id b1-20020a1709063ca100b009ae55f5180amr594658ejh.9.1696375277697; Tue, 03 Oct 2023 16:21:17 -0700 (PDT) MIME-Version: 1.0 References: <20231003231718.work.679-kees@kernel.org> In-Reply-To: <20231003231718.work.679-kees@kernel.org> From: Justin Stitt Date: Tue, 3 Oct 2023 16:21:05 -0700 Message-ID: Subject: Re: [PATCH] net/mlx5: Annotate struct mlx5_fc_bulk with __counted_by To: Kees Cook Cc: Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-rdma@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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.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 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 16:21:40 -0700 (PDT) On Tue, Oct 3, 2023 at 4:17=E2=80=AFPM Kees Cook wr= ote: > > Prepare for the coming implementation by GCC and Clang of the __counted_b= y > 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 > --- > 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/driv= ers/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); > }; This looks good. `bulk->bulk_len` is assigned before flexible array member `fcs` is accessed= . bulk->bulk_len =3D bulk_len; for (i =3D 0; i < bulk_len; i++) { mlx5_fc_init(&bulk->fcs[i], bulk, base_id + i); set_bit(i, bulk->bitmask); } Reviewed-by: Justin Stitt > > static void mlx5_fc_init(struct mlx5_fc *counter, struct mlx5_fc_bulk *b= ulk, > -- > 2.34.1 > > Thanks Justin