power: sequencing: fix an invalid pointer dereference in error path
PATCH v2 1/1 power: sequencing: fix an invalid pointer dereference in error path
From: Bartosz Golaszewski <[email protected]>
We may end up calling pwrseq_target_free() on a partially initialized target object whose unit is either NULL or an ERR_PTR(). Avoid dereferencing invalid memory by adding an appropriate check to pwrseq_target_free().
---
- check for ERR_PTR() in addition to checking for NULL
- only add the check to pwrseq_target_free() as anywhere else unit is always set and if it's not then it's another bug that needs fixing
drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/sequencing/core.c +2 -1
@@ -212,7 +212,8 @@ pwrseq_target_new(const struct pwrseq_target_data *data)static void pwrseq_target_free (struct pwrseq_target *target) { -pwrseq_unit_put (target->unit); +if (!IS_ERR_OR_NULL (target->unit)) +pwrseq_unit_put (target->unit);kfree_const (target->name);kfree (target); }
Signature · 1 line
2.43.0
Quoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We may end up calling
pwrseq_target_free()on a partially initialized target object whose unit is either NULL or anERR_PTR(). Avoid dereferencing invalid memory by adding an appropriate check topwrseq_target_free().
Quoted 9 lines
Fixes 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")Reported-by Dan Carpenter <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>---
- check forERR_PTR()in addition to checking for NULL
- only add the check topwrseq_target_free()as anywhere else unit is always set and if it's not then it's another bug that needs fixing
regards,
dan carpenter
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 6 lines · Bartosz Golaszewski
We may end up calling
pwrseq_target_free()on a partially initialized target object whose unit is either NULL or anERR_PTR(). Avoid dereferencing invalid memory by adding an appropriate check topwrseq_target_free().
Applied, thanks!
[1/1] power: sequencing: fix an invalid pointer dereference in error path
commit: a19ce320c379e0519b68178c596e43d1d5dda03b
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>