mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net-next] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE()
@ 2026-09-17 21:14 Kees Cook
  2026-09-18  2:02 ` Ratheesh Kannoth
  0 siblings, 1 reply; 2+ messages in thread
From: Kees Cook @ 2026-09-17 21:14 UTC (permalink / raw)
  To: Sunil Goutham
  Cc: Kees Cook, Kees Cook, Ratheesh Kannoth, Geetha sowjanya,
	Subbaraya Sundeep, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
	linux-hardening

From: Kees Cook <kees+treewide@kernel.org>

In preparation for making the devm_kmalloc family of allocators type
aware, we need to make sure that the returned type from the allocation
matches the type of the variable being assigned. (Before, the allocator
would always return "void *", which can be implicitly cast to any
pointer type.)

This is allocating room for a copy of ikpu_action_entries, which is an
array of struct npc_kpu_profile_action, but it asked for a single object
the size of the whole array, which would make the allocation type a
pointer to the array rather than the "struct npc_kpu_profile_action *"
being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting
allocation size is the same.

Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0:
drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.o

Assisted-by: LLM coccinelle
Signed-off-by: Kees Cook <kees+treewide@kernel.org>
---
Cc: Sunil Goutham <sgoutham@marvell.com>
Cc: Ratheesh Kannoth <rkannoth@marvell.com>
Cc: Geetha sowjanya <gakula@marvell.com>
Cc: Subbaraya Sundeep <sbhatta@marvell.com>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: <netdev@vger.kernel.org>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
index c34f8d86cc8a..42a601976db3 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
@@ -1959,8 +1959,9 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu,
 	fw = rvu->kpu_fwdata;
 
 	/* Binary blob contains ikpu actions entries at start of data[0] */
-	profile->ikpu2 = devm_kcalloc(rvu->dev, 1,
-				      sizeof(ikpu_action_entries),
+	profile->ikpu2 = devm_kcalloc(rvu->dev,
+				      ARRAY_SIZE(ikpu_action_entries),
+				      sizeof(*profile->ikpu2),
 				      GFP_KERNEL);
 	if (!profile->ikpu2)
 		return -ENOMEM;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE()
  2026-09-17 21:14 [PATCH net-next] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE() Kees Cook
@ 2026-09-18  2:02 ` Ratheesh Kannoth
  0 siblings, 0 replies; 2+ messages in thread
From: Ratheesh Kannoth @ 2026-09-18  2:02 UTC (permalink / raw)
  To: Kees Cook
  Cc: Sunil Goutham, Kees Cook, Geetha sowjanya, Subbaraya Sundeep,
	Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, netdev, linux-kernel, linux-hardening

On 2026-09-18 at 02:44:10, Kees Cook (kees@kernel.org) wrote:
> From: Kees Cook <kees+treewide@kernel.org>
>
> In preparation for making the devm_kmalloc family of allocators type
> aware, we need to make sure that the returned type from the allocation
> matches the type of the variable being assigned. (Before, the allocator
> would always return "void *", which can be implicitly cast to any
> pointer type.)
>
> This is allocating room for a copy of ikpu_action_entries, which is an
> array of struct npc_kpu_profile_action, but it asked for a single object
> the size of the whole array, which would make the allocation type a
> pointer to the array rather than the "struct npc_kpu_profile_action *"
> being assigned. Allocate ARRAY_SIZE-many entries instead. The resulting
> allocation size is the same.
>
> --- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_npc.c
> @@ -1959,8 +1959,9 @@ static int npc_apply_custom_kpu_from_fs(struct rvu *rvu,
>  	fw = rvu->kpu_fwdata;
>
>  	/* Binary blob contains ikpu actions entries at start of data[0] */
> -	profile->ikpu2 = devm_kcalloc(rvu->dev, 1,
> -				      sizeof(ikpu_action_entries),
> +	profile->ikpu2 = devm_kcalloc(rvu->dev,
> +				      ARRAY_SIZE(ikpu_action_entries),
> +				      sizeof(*profile->ikpu2),
>  				      GFP_KERNEL);
Reviewed-by: Ratheesh Kannoth <rkannoth@marvell.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-18  2:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-17 21:14 [PATCH net-next] octeontx2-af: Allocate ikpu2 with ARRAY_SIZE() Kees Cook
2026-09-18  2:02 ` Ratheesh Kannoth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®