Skip to content

Commit c4ea7d8

Browse files
lgs2513kuba-moo
authored andcommitted
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: a69839d ("net: mana: Add support for auxiliary device") Cc: [email protected] Reviewed-by: Long Li <[email protected]> Signed-off-by: Guangshuo Li <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 815980f commit c4ea7d8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/net/ethernet/microsoft/mana/mana_en.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,7 @@ static int add_adev(struct gdma_dev *gd, const char *name)
34253425
struct auxiliary_device *adev;
34263426
struct mana_adev *madev;
34273427
int ret;
3428+
int id;
34283429

34293430
madev = kzalloc_obj(*madev);
34303431
if (!madev)
@@ -3434,7 +3435,8 @@ static int add_adev(struct gdma_dev *gd, const char *name)
34343435
ret = mana_adev_idx_alloc();
34353436
if (ret < 0)
34363437
goto idx_fail;
3437-
adev->id = ret;
3438+
id = ret;
3439+
adev->id = id;
34383440

34393441
adev->name = name;
34403442
adev->dev.parent = gd->gdma_context->dev;
@@ -3460,7 +3462,7 @@ static int add_adev(struct gdma_dev *gd, const char *name)
34603462
auxiliary_device_uninit(adev);
34613463

34623464
init_fail:
3463-
mana_adev_idx_free(adev->id);
3465+
mana_adev_idx_free(id);
34643466

34653467
idx_fail:
34663468
kfree(madev);

0 commit comments

Comments
 (0)