dmaengine: idxd: fix double free in idxd_setup_groups() error path
Subsystems (3)
PATCH 1/1 dmaengine: idxd: fix double free in idxd_setup_groups() error path
When an error happens after device_initialize(), idxd_setup_groups() calls put_device(conf_dev).
The device release callback idxd_conf_group_release() frees group, but the current error paths then call kfree(group) again, causing a double free.
Keep the cleanup in idxd_conf_group_release() after put_device() and avoid freeing group again in idxd_setup_groups().
--- drivers/dma/idxd/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/dma/idxd/init.c +2 -2
@@ -374,7 +374,7 @@ static int idxd_setup_groups(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"group%d.%d" , idxd->id, group->id);if (rc <0 ) {put_device (conf_dev); -kfree (group); + goto err; }
@@ -399,7 +399,7 @@ static int idxd_setup_groups(struct idxd_device *idxd)while (--i >=0 ) { group = idxd->groups[i];put_device (group_confdev (group)); -kfree (group); + }kfree (idxd->groups);
Signature · 1 line
2.43.0
Quoted 9 lines · Guangshuo Li
When an error happens after
device_initialize(),idxd_setup_groups()callsput_device(conf_dev).The device release callback
idxd_conf_group_release()frees group, but the current error paths then call kfree(group) again, causing a double free.Keep the cleanup in
idxd_conf_group_release()afterput_device()and avoid freeing group again inidxd_setup_groups().
Yes, I think it is a double free.
Sorry, I missed the idxd_conf_group_release path.
Quoted 22 lines
Fixes aa6f4f945b10 ("dmaengine: idxd: fix memory leak in error handling path of idxd_setup_groups")Signed-off-by Guangshuo Li <[email protected]>--- drivers/dma/idxd/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/dma/idxd/init.c +1
-1@@ -374,7 +374,7 @@ static int idxd_setup_groups(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"group%d.%d" , idxd->id, group->id);if (rc <0 ) {put_device (conf_dev); -kfree (group); + goto err; }
drivers/dma/idxd/init.c static int idxd_setup_groups(struct idxd_device *idxd) · line 402
Quoted 5 lines
drivers/dma/idxd/init.c +1
-1@@ -399,7 +399,7 @@ static int idxd_setup_groups(struct idxd_device *idxd)while (--i >=0 ) { group = idxd->groups[i];put_device (group_confdev (group)); -kfree (group); +
Nit: please remove the blank lines left behind by both deletions.
With those addressed:
Thanks.
Shuai
Quoted 31 lines · Guangshuo Li
When an error happens after
device_initialize(),idxd_setup_groups()callsput_device(conf_dev).The device release callback
idxd_conf_group_release()frees group, but the current error paths then call kfree(group) again, causing a double free.Keep the cleanup in
idxd_conf_group_release()afterput_device()and avoid freeing group again inidxd_setup_groups().Fixes aa6f4f945b10 ("dmaengine: idxd: fix memory leak in error handling path of idxd_setup_groups")Signed-off-by Guangshuo Li <[email protected]>--- drivers/dma/idxd/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/dma/idxd/init.c +1
-1@@ -374,7 +374,7 @@ static int idxd_setup_groups(struct idxd_device *idxd) rc =dev_set_name (conf_dev,"group%d.%d" , idxd->id, group->id);if (rc <0 ) {put_device (conf_dev); -kfree (group); + goto err; }
drivers/dma/idxd/init.c static int idxd_setup_groups(struct idxd_device *idxd) · line 405
Quoted 8 lines
drivers/dma/idxd/init.c +1
-1@@ -399,7 +399,7 @@ static int idxd_setup_groups(struct idxd_device *idxd)while (--i >=0 ) { group = idxd->groups[i];put_device (group_confdev (group)); -kfree (group); + }kfree (idxd->groups);
Note that idxd_clean_groups() and idxd_clean_engines() have the same pattern. It should be fixed in the same patch as well.
Thanks.
Shuai