CVE-2026-72343: net/mlx5e: Fix HV VHCA stats zero-sized buffer allocation
In the Linux kernel, the following vulnerability has been resolved:
net/mlx5e: Fix HV VHCA stats zero-sized buffer allocation
mlx5ehvvhcastatscreate() is called from mlx5enicenable(), before mlx5eopen(). At that point priv->statsnch is still zero, because it is only ever incremented in mlx5echannelstatsalloc(), which is reached only from mlx5eopenchannel().
mlx5ehvvhcastatsbufsize() therefore returns 0, and kvzalloc(0, GFPKERNEL) returns ZEROSIZEPTR ((void )16) rather than NULL. The "if (!buf)" guard does not catch this, and mlx5ehvvhcastatscreate() completes "successfully" with priv->statsagent.buf set to ZEROSIZEPTR.
Once channels are opened (priv->statsnch > 0) and the hypervisor enables stats reporting, mlx5ehvvhcastatswork() recomputes buflen using the new non-zero statsnch and calls memset(buf, 0, buflen) on ZEROSIZEPTR, faulting at address 0x10.
Allocate the buffer based on priv->maxnch, which is set in mlx5eprivinit() and is the upper bound on statsnch:
- Add a separate helper mlx5ehvvhcastatsbufmaxsize() that returns sizeof(perringstats) max(maxnch, statsnch), and use it for the kvzalloc() in mlx5ehvvhcastatscreate(). - Keep mlx5ehvvhcastatsbufsize() (which returns based on statsnch) for the worker's active payload size, so the wire format (block->rings = statsnch) and the amount of data filled by mlx5ehvvhcafillstats() are unchanged.
The max(maxnch, statsnch) guard handles the rare case where mlx5eattachnetdev() recomputes maxnch downward across a detach/resume cycle while priv->statsnch persists (mlx5edetachnetdev does not call mlx5eprivcleanup, so statsnch is only reset when the netdev is destroyed). Without the guard, the worker could compute buflen from statsnch and overrun the smaller buffer allocated based on the reduced maxnch.
Allocating a non-zero buffer also makes the kvzalloc() failure path in mlx5ehvvhcastatscreate() reachable for the first time: it returns early without (re)creating the agent. Clear priv->statsagent.{agent,buf} in mlx5ehvvhcastatsdestroy() after freeing them, so that if a later create() bails out on this path, a subsequent teardown does not double-free the stale agent/buffer left from a previous enable/disable cycle.
This mirrors the existing mlx5e pattern of preallocating arrays of size maxnch (e.g. priv->channelstats) and lazily populating entries up to statsnch on demand.