power: sequencing: fix NULL-pointer dereference in error path
PATCH 1/1 power: sequencing: fix NULL-pointer dereference in error path
From: Bartosz Golaszewski <[email protected]>
We may call pwrseq_target_free() on a target without the final unit assigned yet. In this case pwrseq_unit_put() will dereference a NULL-pointer. Add a check to the latter function.
--- drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/power/sequencing/core.c +2 -1
@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);static void pwrseq_unit_put (struct pwrseq_unit *unit) { -kref_put (&unit->ref, pwrseq_unit_release); +if (unit) +kref_put (&unit->ref, pwrseq_unit_release); }/**
Signature · 1 line
2.43.0
Quoted 19 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We may call
pwrseq_target_free()on a target without the final unit assigned yet. In this casepwrseq_unit_put()will dereference a NULL-pointer. Add a check to the latter function.Fixes 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")Reported-by Dan Carpenter <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/sequencing/core.c +0
-0
drivers/power/sequencing/core.c static void pwrseq_unit_release(struct kref *ref); · line 122
Quoted 5 lines
drivers/power/sequencing/core.c +1
-1@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);static void pwrseq_unit_put (struct pwrseq_unit *unit) { -kref_put (&unit->ref, pwrseq_unit_release); +if (unit)
I was wondering where you would put the check. But it needs to be:
if (!IS_ERR_OR_NULL(unit))
regards,
dan carpenter
Quoted 6 lines
drivers/power/sequencing/core.c +1
-0+kref_put (&unit->ref, pwrseq_unit_release); }/** Signature · 1 line
2.43.0
Quoted 29 lines · Dan Carpenter
Quoted 19 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We may call
pwrseq_target_free()on a target without the final unit assigned yet. In this casepwrseq_unit_put()will dereference a NULL-pointer. Add a check to the latter function.Fixes 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")Reported-by Dan Carpenter <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/sequencing/core.c +0
-0drivers/power/sequencing/core.c static void pwrseq_unit_release(struct kref *ref); · line 122
Quoted 5 lines
drivers/power/sequencing/core.c +1
-1@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);static void pwrseq_unit_put (struct pwrseq_unit *unit) { -kref_put (&unit->ref, pwrseq_unit_release); +if (unit)I was wondering where you would put the check. But it needs to be:
Quoted 5 lines
if (!IS_ERR_OR_NULL(unit))regards,
dan carpenter
Am I missing something? pwrseq_unit_new() can only return NULL on error.
Bart
Quoted 6 lines
Quoted 6 lines
drivers/power/sequencing/core.c +1
-1+kref_put (&unit->ref, pwrseq_unit_release); }/** -- 2.43.0
Quoted 30 lines · Bartosz Golaszewski
Quoted 29 lines · Dan Carpenter
Quoted 19 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We may call
pwrseq_target_free()on a target without the final unit assigned yet. In this casepwrseq_unit_put()will dereference a NULL-pointer. Add a check to the latter function.Fixes 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")Reported-by Dan Carpenter <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/sequencing/core.c +0
-0drivers/power/sequencing/core.c static void pwrseq_unit_release(struct kref *ref); · line 122
Quoted 5 lines
drivers/power/sequencing/core.c +1
-1@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);static void pwrseq_unit_put (struct pwrseq_unit *unit) { -kref_put (&unit->ref, pwrseq_unit_release); +if (unit)I was wondering where you would put the check. But it needs to be:
Quoted 8 lines
Quoted 5 lines
if (!IS_ERR_OR_NULL(unit))regards,
dan carpenterAm I missing something?
pwrseq_unit_new()can only return NULL on error.
It's not pwrseq_unit_new() but pwrseq_unit_setup() that's the issue. The target->unit = pwrseq_unit_setup() assignment in pwrseq_do_setup_targets().
regards,
dan carpenter
Quoted 41 lines · Dan Carpenter
Quoted 30 lines · Bartosz Golaszewski
Quoted 29 lines · Dan Carpenter
Quoted 19 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
We may call
pwrseq_target_free()on a target without the final unit assigned yet. In this casepwrseq_unit_put()will dereference a NULL-pointer. Add a check to the latter function.Fixes 249ebf3f65f8 ("power: sequencing: implement the pwrseq core")Reported-by Dan Carpenter <[email protected]>Signed-off-by Bartosz Golaszewski <[email protected]>--- drivers/power/sequencing/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/power/sequencing/core.c +0
-0drivers/power/sequencing/core.c static void pwrseq_unit_release(struct kref *ref); · line 122
Quoted 5 lines
drivers/power/sequencing/core.c +1
-1@@ -119,7 +119,8 @@ static void pwrseq_unit_release(struct kref *ref);static void pwrseq_unit_put (struct pwrseq_unit *unit) { -kref_put (&unit->ref, pwrseq_unit_release); +if (unit)I was wondering where you would put the check. But it needs to be:
Quoted 8 lines
Quoted 5 lines
if (!IS_ERR_OR_NULL(unit))regards,
dan carpenterAm I missing something?
pwrseq_unit_new()can only return NULL on error.
Quoted 7 lines
It's not
pwrseq_unit_new()butpwrseq_unit_setup()that's the issue. Thetarget->unit=pwrseq_unit_setup()assignment inpwrseq_do_setup_targets().regards,
dan carpenter
Indeed. Thanks.
Bart