Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp1907874lqo; Mon, 13 May 2024 01:56:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXPTnoIznijL9KxCexMWHBj1UmT2QFZ09G6NlSnt0mBa3w5F0wOzLe3xFQuEaD7xd2yf8+zD922OGsnKBXcVIMnhul68FVVcGMRgktiXA== X-Google-Smtp-Source: AGHT+IGRmcJFoKUvpFwusefUHM9MHHdfE6ZYV6S3RcacPkMhSSK5IiAYMyLZ+SM9p8G2L7oFefBK X-Received: by 2002:a05:6a20:729b:b0:1ad:9adf:febf with SMTP id adf61e73a8af0-1afde120efcmr9878839637.31.1715590578681; Mon, 13 May 2024 01:56:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715590578; cv=pass; d=google.com; s=arc-20160816; b=jQh2uMiQAsA8SQLooSvh0n/QfqIXB2sQ+lfGTLHjvo4+F1TiJe3C6jEXPk6S5S+fMF /LQpjLISHFD85paGIMYX2G6PqiD0BH6yVKjjKMRMI/sjWf3DvcOKMfJiDri7OFug+iqA VrwfRD8l+u84rU5gk4QjAr4mIBy14ZPcwQjvn+ZCadNHRKdHeUDOsunjaGKJAz++eqoF L52UHbSwY7CCnmYJWyaqXIj8PSXyYyu85Trs5Jy3PHbNWIUN1zHz0a/n/CGXXQGugpBJ Pdh1bZeIDK8iX3OnQWeqcxhikb2kkEazljhnpr6fVOXgG5B5xcog6cQ9KXp+/s+x9e1I 7SeQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NnE+noIeQK8qDXdBa3EV3V4grVDvGqPA5k6QPcDTM7g=; fh=dKPpHSebdZtuHQY/QIzKqfDsQgi1F8CQtsSHLWcE7xE=; b=QX+N2Pkp7PgX7wazo6nC98nvG4yfAZ32kkIMetR6g9LIu4ZKRDpbzdNFhdpKn52yEn dD6oLZ/4Wc0Pr00CsHvDGRHylq4zpw3X2YjdiNfccoYt/GTfh51cvHndKSErhwaMZUyn GCISsOXeAnWIBQwbhgr+Sa3igwNrGxD0tHOMw1IZQg1/yyYGX1FLuUHZ2Iv32sDYDzY3 4x1uHBtiW3R/Vghld9j3HzLmUfVb/FylFDT4zczgZzK32j4qROlobHSz3f0CHpFSgkdw AxGH8dsw5Eq6tXkraXkgP1/rdwxn27ojpY9ibhvbtoN2bWALie1CnOH/NsIbcOD7FvA5 NTSw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5kz7xcE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-177364-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-63411530b1asi8676475a12.522.2024.05.13.01.56.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 01:56:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177364-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5kz7xcE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-177364-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177364-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 4E245B226A8 for ; Mon, 13 May 2024 08:50:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DF0C147C93; Mon, 13 May 2024 08:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f5kz7xcE" 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 A57FD146A60; Mon, 13 May 2024 08:49:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590185; cv=none; b=Z0GGZW27O1fw+3hwknv37azaKZQvFHFxjt7mky3GzfFTv7LWeEA63/c/rd33fMNaz5aI0j5OP3MHh5j+vXyiNiTtT/fUystGTZVT3S4thVPiDo+6JsgUjRw7JtpKyYgKpz9FXKi8vLyagFr0uOERnryZzvQ1D4huJNAYwsjen6I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715590185; c=relaxed/simple; bh=pqlWwJSnxCSApFWf+ztJT4c7t6r3Hc8iW0XoiL6wxdA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FoWz3VONz5V5fcouW5+rzMs55YL9Lg/ep/zfAz9TH6IBXbQxKyRMRV6Z3ijRYzu8tH1ZSpKoNuWxKv5dHOMUnHemW1fgYNBkILNZDWV9iwFPdn9BzWv43ygD9/q+9FGASV7rYau/uEp/oL7iwMZbM/rX5GTzkZWuRvtOKpysf7c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f5kz7xcE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23705C113CC; Mon, 13 May 2024 08:49:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715590185; bh=pqlWwJSnxCSApFWf+ztJT4c7t6r3Hc8iW0XoiL6wxdA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=f5kz7xcE1JuAlXTQx6ICnJobXlPEp3jb5/Pok2Z+JaHVqoStZ72IeRM4Pri008gV3 2Eje3UHILieLxm2tCiZQEdUTaxtpBq7m37eqkGOXVErZT2kLtEHjn3AJhzPLhFJ1YD KXpU3510h2KbImijQjYdEU0W8LWO7K4HPDFUiTTSlzTLfPCRJTjvKEtiYHKtMJS/n/ TY8ZqCgnSvG6bVqufSozIQsdqxq8XrGqZyX1AU3Y2RZKvNML19srIs+MyLjlmOsrCB X5EY4QUNDd+5X28oqh6Bv94IgQRzAD4NGo3OOFLO9e9xQtHQV2YlcuxWn3SKi96b6S 1KyE2gQ0hhRZQ== Date: Mon, 13 May 2024 09:49:39 +0100 From: Simon Horman To: Erick Archer Cc: Taras Chornyi , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kees Cook , "Gustavo A. R. Silva" , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH] net: prestera: Add flex arrays to some structs Message-ID: <20240513084939.GA2787@kernel.org> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sun, May 12, 2024 at 06:10:27PM +0200, Erick Archer wrote: > The "struct prestera_msg_vtcam_rule_add_req" uses a dynamically sized > set of trailing elements. Specifically, it uses an array of structures > of type "prestera_msg_acl_action actions_msg". > > The "struct prestera_msg_flood_domain_ports_set_req" also uses a > dynamically sized set of trailing elements. Specifically, it uses an > array of structures of type "prestera_msg_acl_action actions_msg". > > So, use the preferred way in the kernel declaring flexible arrays [1]. > > At the same time, 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). In this case, it is important to note > that the attribute used is specifically __counted_by_le since the > counters are of type __le32. > > The logic does not need to change since the counters for the flexible > arrays are asigned before any access to the arrays. > > The order in which the structure prestera_msg_vtcam_rule_add_req and the > structure prestera_msg_flood_domain_ports_set_req are defined must be > changed to avoid incomplete type errors. > > Also, avoid the open-coded arithmetic in memory allocator functions [2] > using the "struct_size" macro. > > Moreover, the new structure members also allow us to avoid the open- > coded arithmetic on pointers. So, take advantage of this refactoring > accordingly. > > This code was detected with the help of Coccinelle, and audited and > modified manually. > > Link: https://www.kernel.org/doc/html/next/process/deprecated.html#zero-length-and-one-element-arrays [1] > Link: https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments [2] > Signed-off-by: Erick Archer Reviewed-by: Simon Horman