Skip to contentSkip to conversation

ep93xx: clock: Fix UAF in ep93xx_clk_register_gate()

PATCH New Alexander Sverdlin 1 participant 1 message Jan 30, 2022

Subsystems (4)
lore
Share & tools
lore

Alexander Sverdlin

author maintainer
#0 lore raw

PATCH v2 1/1 ep93xx: clock: Fix UAF in ep93xx_clk_register_gate()

arch/arm/mach-ep93xx/clock.c:154:2: warning: Use of memory after it is freed [clang-analyzer-unix.Malloc] arch/arm/mach-ep93xx/clock.c:151:2: note: Taking true branch
if (IS_ERR(clk))
^
arch/arm/mach-ep93xx/clock.c:152:3: note: Memory is released
kfree(psc);
^~~~~~~~~~
arch/arm/mach-ep93xx/clock.c:154:2: note: Use of memory after it is freed
return &psc->hw;
^ ~~~~~~~~

---
Changelog:
v2:
- Thanks to Nick for the hint to use ERR_CAST()

 arch/arm/mach-ep93xx/clock.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/arm/mach-ep93xx/clock.c +3 -1
index cc75087134d3..4aee14f18123 100644
@@ -148,8 +148,10 @@ static struct clk_hw *ep93xx_clk_register_gate(const char *name,
 	psc->lock = &clk_lock;
 
 	clk = clk_register(NULL, &psc->hw);
-	if (IS_ERR(clk))
+	if (IS_ERR(clk)) {
 		kfree(psc);
+		return ERR_CAST(clk);
+	}
 
 	return &psc->hw;
 }
Signature · 1 line
2.34.1