intel_th: avoid double free in error flow
Subsystems (2)
PATCH 1/1 intel_th: avoid double free in error flow
There is a possible double free issue in intel_th_subdevice_alloc:
651 err = intel_th_device_add_resources(thdev, res, subdev->nres);
652 if (err) {
653 put_device(&thdev->dev);
654 goto fail_put_device; ---> freed
655 }
...
687 fail_put_device:
688 put_device(&thdev->dev); ---> double freed
689
This patch fix it by removing the unnecessary put_device().
--- drivers/hwtracing/intel_th/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/hwtracing/intel_th/core.c +1 -3
@@ -649,10 +649,8 @@ static inline void intel_th_request_hub_module_flush(struct intel_th *th) } err =intel_th_device_add_resources (thdev, res, subdev->nres); -if (err) { -put_device (&thdev->dev); +if (err) goto fail_put_device; - }if (subdev->type ==INTEL_TH_OUTPUT ) {if (subdev->mknode)
Signature · 1 line
1.8.3.1
Alexander Shishkin
maintainerQuoted 12 lines · Wen Yang
There is a possible double free issue in
intel_th_subdevice_alloc:651 err =
intel_th_device_add_resources(thdev, res, subdev->nres);
652 if (err) {
653put_device(&thdev->dev);
654 gotofail_put_device; ---> freed
655 }
...
687fail_put_device:
688put_device(&thdev->dev); ---> double freed
689
Quoted 1 line
This patch fix it by removing the unnecessary
put_device().
Unnecessary is a too generous term here.
Quoted 5 lines
Fixes a753bfcfdb1f ("intel_th: Make the switch allocate its subdevices")Signed-off-by Wen Yang <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>
Quoted 9 lines
--- drivers/hwtracing/intel_th/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/hwtracing/intel_th/core.c +0
-0
drivers/hwtracing/intel_th/core.c static inline void intel_th_request_hub_module_flush(struct intel_th *th) · line 655
Quoted 8 lines
drivers/hwtracing/intel_th/core.c +1
-3@@ -649,10 +649,8 @@ static inline void intel_th_request_hub_module_flush(struct intel_th *th) } err =intel_th_device_add_resources (thdev, res, subdev->nres); -if (err) { -put_device (&thdev->dev); +if (err) goto fail_put_device; - }
What about the second instance of the same problem a few lines lower?
Thanks,
--
Alex
Quoted 35 lines · Alexander Shishkin
Quoted 12 lines · Wen Yang
There is a possible double free issue in
intel_th_subdevice_alloc:651 err =
intel_th_device_add_resources(thdev, res, subdev->nres);
652 if (err) {
653put_device(&thdev->dev);
654 gotofail_put_device; ---> freed
655 }
...
687fail_put_device:
688put_device(&thdev->dev); ---> double freed
689Quoted 1 line
This patch fix it by removing the unnecessary
put_device().Unnecessary is a too generous term here.
Quoted 5 lines
Fixes a753bfcfdb1f ("intel_th: Make the switch allocate its subdevices")Signed-off-by Wen Yang <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Cc stable@ is missing.Quoted 11 lines
--- drivers/hwtracing/intel_th/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)drivers/hwtracing/intel_th/core.c +0
-0@@ -649,10 +649,8 @@ static inline void intel_th_request_hub_module_flush(struct intel_th *th) }
Quoted 10 lines
drivers/hwtracing/intel_th/core.c static inline void intel_th_request_hub_module_flush(struct intel_th *th) · line 655
Quoted 6 lines
drivers/hwtracing/intel_th/core.c +1
-3err =intel_th_device_add_resources (thdev, res, subdev->nres); -if (err) { -put_device (&thdev->dev); +if (err) goto fail_put_device; - }What about the second instance of the same problem a few lines lower? Thanks,
--
Alex
Hi Alex,
Thank you for your comments.
Another example after a few lines lower:
err = device_add(&thdev->dev);
if (err) {
put_device(&thdev->dev);
goto fail_free_res;
}
device_add() has increased the reference count,
so when it returns an error, an additional call to put_device()
is needed here to reduce the reference count.
So the code in this place is correct.
--
Regards,
Wen
Alexander Shishkin
maintainerQuoted 10 lines · Wen Yang
Another example after a few lines lower:
err =
device_add(&thdev->dev);if (err) {
put_device(&thdev->dev);
gotofail_free_res;}
Quoted 7 lines
device_add()has increased the reference count,so when it returns an error, an additional call to
put_device()is needed here to reduce the reference count.
So the code in this place is correct.
No, device_add() drops its own extra reference in case of error (as it should), so in "if (err) ..." branch we still only have just one reference before it goes free.
Regards,
--
Alex
Quoted 18 lines · Alexander Shishkin
Quoted 16 lines · Wen Yang
Another example after a few lines lower:
err = device_add(&thdev->dev); if (err) { put_device(&thdev->dev); goto fail_free_res; }
device_add()has increased the reference count,so when it returns an error, an additional call to
put_device()is needed here to reduce the reference count.
Quoted 8 lines
Quoted 1 line
So the code in this place is correct.
No,
device_add()drops its own extra reference in case of error (as it should), so in "if (err) ..." branch we still only have just one reference before it goes free.Regards,
--
Alex
Well, ok, you are right.
We just checked the code and device_add() does release the reference count.
Thank you.
--
Regards,
Wen