Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: mana: fix use-after-free in add_adev() error path

If auxiliary_device_add() fails, add_adev() jumps to add_fail and calls
auxiliary_device_uninit(adev).

The auxiliary device has its release callback set to adev_release(),
which frees the containing struct mana_adev. Since adev is embedded in
struct mana_adev, the subsequent fall-through to init_fail and access
to adev->id may result in a use-after-free.

Fix this by saving the allocated auxiliary device id in a local
variable before calling auxiliary_device_add(), and use that saved id
in the cleanup path after auxiliary_device_uninit().

Fixes: a69839d4327d ("net: mana: Add support for auxiliary device")
Cc: stable@vger.kernel.org
Reviewed-by: Long Li <longli@microsoft.com>
Signed-off-by: Guangshuo Li <lgs201920130244@gmail.com>
Link: https://patch.msgid.link/20260323165730.945365-1-lgs201920130244@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Guangshuo Li and committed by
Jakub Kicinski
c4ea7d89 815980fe

+4 -2
+4 -2
drivers/net/ethernet/microsoft/mana/mana_en.c
··· 3425 3425 struct auxiliary_device *adev; 3426 3426 struct mana_adev *madev; 3427 3427 int ret; 3428 + int id; 3428 3429 3429 3430 madev = kzalloc_obj(*madev); 3430 3431 if (!madev) ··· 3435 3434 ret = mana_adev_idx_alloc(); 3436 3435 if (ret < 0) 3437 3436 goto idx_fail; 3438 - adev->id = ret; 3437 + id = ret; 3438 + adev->id = id; 3439 3439 3440 3440 adev->name = name; 3441 3441 adev->dev.parent = gd->gdma_context->dev; ··· 3462 3460 auxiliary_device_uninit(adev); 3463 3461 3464 3462 init_fail: 3465 - mana_adev_idx_free(adev->id); 3463 + mana_adev_idx_free(id); 3466 3464 3467 3465 idx_fail: 3468 3466 kfree(madev);