Skip to contentSkip to conversation

clk: microchip: fix potential UAF in auxdev release callback

PATCH Applied Conor Dooley 2 participants 2 messages Apr 13, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 clk: microchip: fix potential UAF in auxdev release callback

From: Conor Dooley <[email protected]>

Similar to commit 1c11289b34ab ("peci: cpu: Fix use-after-free in adev_release()"), the auxiliary device is not torn down in the correct order. If auxiliary_device_add() fails, the release callback will be called twice, resulting in a UAF. Due to timing, the auxdev code in this driver "took inspiration" from the aforementioned commit, and thus its bugs too!

Moving auxiliary_device_uninit() to the unregister callback instead avoids the issue.

Fixes b56bae2dd6fd ("clk: microchip: mpfs: add reset controller")

---
Stephen,
Claudiu is on leave at the moment, and although I can push stuff to the at-91 tree etc, it's probably simpler if you just take this yourself?

CC Stephen Boyd <[email protected]>
CC Conor Dooley <[email protected]>
CC Daire McNamara <[email protected]>
CC Michael Turquette <[email protected]>
CC Stephen Boyd <[email protected]>
CC Claudiu Beznea <[email protected]>
---
 drivers/clk/microchip/clk-mpfs.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/clk/microchip/clk-mpfs.c +1 -2
index 4f0a19db7ed7..cc5d7dee59f0 100644
@@ -374,14 +374,13 @@ static void mpfs_reset_unregister_adev(void *_adev)
 	struct auxiliary_device *adev = _adev;
 
 	auxiliary_device_delete(adev);
+	auxiliary_device_uninit(adev);
 }
 
 static void mpfs_reset_adev_release(struct device *dev)
 {
 	struct auxiliary_device *adev = to_auxiliary_dev(dev);
 
-	auxiliary_device_uninit(adev);
-
 	kfree(adev);
 }
 
Signature · 1 line
2.39.2
maintainer Applied
#1 lore raw

Quoting Conor Dooley (2023-04-13 15:20:45)

Quoted 9 lines

From: Conor Dooley <[email protected]>

Similar to commit 1c11289b34ab ("peci: cpu: Fix use-after-free in adev_release()"), the auxiliary device is not torn down in the correct order. If auxiliary_device_add() fails, the release callback will be called twice, resulting in a UAF. Due to timing, the auxdev code in this driver "took inspiration" from the aforementioned commit, and thus its bugs too!

Quoted 7 lines

Moving auxiliary_device_uninit() to the unregister callback instead avoids the issue.

Fixes b56bae2dd6fd ("clk: microchip: mpfs: add reset controller")

---

Applied to clk-next