Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2273889rdb; Tue, 3 Oct 2023 16:26:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGx2909SkoCbW1tdsmvyrIk8hyQtePB7fmpUJBq4WavWjUWjyZaWqg9RM5eg6A1ZEYiLZrg X-Received: by 2002:a25:e682:0:b0:d81:4391:a59c with SMTP id d124-20020a25e682000000b00d814391a59cmr626568ybh.49.1696375615131; Tue, 03 Oct 2023 16:26:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696375615; cv=none; d=google.com; s=arc-20160816; b=Z+kiUhp2pi6iyjWBSE5xSTkTlTGlYyE9SgXiB1Gjn+fZXU6ij/yhUujSt6SeumOC/P 1JoF6i1mmAveBfkGxujU984L+Wa+V9Ij3hnQ1vDCaiSKBzcA6sa+kEYHmyOZ+0Ffkreq Lf7kE1yAf7EIVllnicUbGWMRXi010uM+aGrkOltIVDRi7b5RaCynNcHMAy0ohMab0fDq Bz0nV9zGFtcCkU3OV1NMa2QW2sNzqkqWLsSBv/wb0rMDWvOwNp33QTIedZs1xA+NHcV9 SBFs0dxT+ja19tcn8wMKscKvA0kpT0X5MNS90lI3uN430qW4/2YiuLBx15+qgipJS/07 Z4uA== 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=ZkOmFORPNdegsvUzletDdGNQTS/35DzAQHoVxYp5MXg=; fh=jVxJYofHTXhHvy0ZGtBuLFS8X3F1FmMY0c2Fp7VOn9o=; b=Vn2HBFiT1kRBiI6rN1XNUDFuZ68YkAuhfU7juesr1h2voCR+gx2JvC4b5c/cBkE71Z Sv+ILaaYZK6RRJZB40lsUPs+MP5j5iuwPmgYosn86wPjkGCmXuz9vBl+Od6efqro9ftP dc7O0ayu6x2EFNCmFOqfVtsPwzDZQvx38DKHs6rhKgSBCJr/pOoZp463Cz511+qSxUT4 +g3KborplBiQOOIquoWi14McJ7xDHcXaIm4vNT8TjJ/GAknENasoJ1WYRU0SMm5lPipc EbNUp/2k9YRFOC8kfH/hd8dawjAS5Ix4rtRlkdOML/QXM7icv993hgbuXqS4TLEq/nw0 zUeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g8BdXQY2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id l191-20020a6391c8000000b00585adc52bd5si2614170pge.730.2023.10.03.16.26.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 16:26:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=g8BdXQY2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id BCD20831301B; Tue, 3 Oct 2023 16:26:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235505AbjJCX0x (ORCPT + 99 others); Tue, 3 Oct 2023 19:26:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235111AbjJCX0w (ORCPT ); Tue, 3 Oct 2023 19:26:52 -0400 Received: from mail-ej1-x62a.google.com (mail-ej1-x62a.google.com [IPv6:2a00:1450:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ED3DAF for ; Tue, 3 Oct 2023 16:26:49 -0700 (PDT) Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-991c786369cso251934966b.1 for ; Tue, 03 Oct 2023 16:26:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696375608; x=1696980408; 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=ZkOmFORPNdegsvUzletDdGNQTS/35DzAQHoVxYp5MXg=; b=g8BdXQY2ymaa+Ax1z7Lecj0GB4zjvxggDOmeVtM/kQn/8YBjYIz0I07RM51X9bcp2x MZvnbvAQz6x5X9OlSeEJe9ec6+OQyqFNPktZvPfgDVieDIfOjLZAV+mWjAD3xSza3tnK d5q20wEOwJLmLUMru5coi3WCU1T5UgAoIk7GyDWXMkwu5JkkzwDoKMufZILEweUSBgn5 g26ShFblNyVG1xMHe1WgXzU8wXr3h7yi1UafE9HwEB/tbu9QcD2lrDEEzxpMidIFQsrc JIuRF4cGFXwlXPUGx4vTsZSRzb5ac7kwQBCm+svodMikpQx7VV0DnBG3rHGGFr+vSlxp FyBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696375608; x=1696980408; 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=ZkOmFORPNdegsvUzletDdGNQTS/35DzAQHoVxYp5MXg=; b=KORxgs0oZ46e1BGluOCs6J718wSRDFN1VWINiuMI9TzUpR+zciMchiEUYczhXyj0u9 3xQZVJvbR2igEz4wDPQCsHP59vvA54fN7F9+SL7NztnY/UxoWWnSJrvmFNqTXM3KzJ+T h0ldCwl1b5Kfb8BDDmy6vBkwiKv09fh3msUIfctLxdORIcjOWpkPvcEA8VlC1IyFmVni dv1ZiTuRVWwWVqFGkpDQWXECPuvZfOnLMrYzNMmB27MPlPxe2BBdqnIJ/uvQXT3PCWE/ qC2t+Jrwgv3KA1caQFM9FFrmIUqt8n3qVJb8fWzpOoo95c+Fcg1g5bki6kuHeYpumt2F 0Vaw== X-Gm-Message-State: AOJu0YxKfIUJENiB/Em7CFFu+f6Ump/zFtsUyf47u3DK6USH3MY/wO0u xP9eWXUZZJn+8aoBlCAxOGb+/KeoQaciheOIdu2B7A== X-Received: by 2002:a17:906:da8c:b0:9a2:139:f45d with SMTP id xh12-20020a170906da8c00b009a20139f45dmr657784ejb.43.1696375607793; Tue, 03 Oct 2023 16:26:47 -0700 (PDT) MIME-Version: 1.0 References: <20231003231730.work.166-kees@kernel.org> In-Reply-To: <20231003231730.work.166-kees@kernel.org> From: Justin Stitt Date: Tue, 3 Oct 2023 16:26:35 -0700 Message-ID: Subject: Re: [PATCH] net/mlx5: Annotate struct mlx5_flow_handle 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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 (howler.vger.email [0.0.0.0]); Tue, 03 Oct 2023 16:26:54 -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_flow_handle= . > > 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_core.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h b/drivers/= net/ethernet/mellanox/mlx5/core/fs_core.h > index 4aed1768b85f..78eb6b7097e1 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h > +++ b/drivers/net/ethernet/mellanox/mlx5/core/fs_core.h > @@ -181,7 +181,7 @@ struct mlx5_flow_rule { > > struct mlx5_flow_handle { > int num_rules; > - struct mlx5_flow_rule *rule[]; > + struct mlx5_flow_rule *rule[] __counted_by(num_rules); > }; Great patch! handle->num_rules is properly assigned to before handle->rule has any accesses. handle =3D alloc_handle((dest_num) ? dest_num : 1); then static struct mlx5_flow_handle *alloc_handle(int num_rules) { ... handle->num_rules =3D num_rules; then handle->rule[i] =3D rule; Reviewed-by: Justin Stitt > > /* Type of children is mlx5_flow_group */ > -- > 2.34.1 > > Thanks Justin