iscsi_boot_sysfs: Fix a memory leak in iscsi_boot_destroy_kset()
PATCH 1/1 iscsi_boot_sysfs: Fix a memory leak in iscsi_boot_destroy_kset()
From: "Ethan Zhao" <[email protected]>
Load and unload iscsi_ibft module will cause kernel memory leak, fix it in scsi/iscsi_boot_sysfs.c iscsi_boot_destroy_kset().
--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)
drivers/scsi/iscsi_boot_sysfs.c +1 -0
@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset);
Signature · 1 line
1.8.3.4 (Apple Git-47)
Quoted 5 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fix it inscsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().
Is there a stack trace?
Quoted 19 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/iscsi_boot_sysfs.c +1
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset);Signature · 1 line
1.8.3.4 (Apple Git-47)
Konrad,
boot_kset was allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()
but wasn't freed when module unloaded byibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()
Thanks,
Ethan
Quoted 27 lines · Konrad Rzeszutek Wilk
Quoted 5 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fix it inscsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Quoted 19 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/iscsi_boot_sysfs.c +1
-1@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Quoted 31 lines · Ethan Zhao
Konrad,
boot_ksetwas allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()but wasn't freed when module unloaded by
ibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()Thanks,
EthanQuoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fixit
Quoted 9 lines
Quoted 2 lines
in
scsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Quoted 5 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)
Quoted 16 lines
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/scsi/iscsi_boot_sysfs.cQuoted 4 lines
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct
Quoted 4 lines
index 14c1c8f..680bf6f 100644
drivers/scsi/iscsi_boot_sysfs.c +0
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct
iscsi_boot_kset*boot_kset)Quoted 9 lines
Quoted 9 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-1iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Right. In the past we did not do that b/c certain drivers (like broadcom) would allocate on the kset their name and try to free (the driver would after freeing the ibft). So you would end up with this patch a double free ( and it might be fixed by now but I can't recall).
My question was - did you observer a crash or bug. Hence the question about stack trace? How did you see this?
Thank you.
Quoted 49 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Ethan Zhao
Konrad,
boot_ksetwas allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()but wasn't freed when module unloaded by
ibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()Thanks,
EthanQuoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fixit
Quoted 9 lines
Quoted 2 lines
in
scsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Quoted 5 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)Quoted 16 lines
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/scsi/iscsi_boot_sysfs.cQuoted 4 lines
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct
Quoted 4 lines
index 14c1c8f..680bf6f 100644
drivers/scsi/iscsi_boot_sysfs.c +0
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct
iscsi_boot_kset*boot_kset)Quoted 9 lines
Quoted 9 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-1iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Quoted 2 lines
Right. In the past we did not do that b/c certain drivers (like broadcom) would allocate on the kset their name and try to free (the driver would after freeing the ibft). So you would end up with this patch a double free ( and it might be fixed by now but I can't recall).
Do you mean the name string that is passed into kset_create_and_add? If so that should not happen now. There does not seem to be any user freeing that string.
There used to be bug where at the initiator/target/ethernet level there was a double free because iscsi_boot_sysfs and be2iscsi were both freeing the struct associated with the initiator/target/ethernet. That is fixed in f457a46f179df41b0f6d80dee33b6e629945f276.
Quoted 50 lines · Mike Christie
Quoted 49 lines · Konrad Rzeszutek Wilk
Quoted 47 lines · Ethan Zhao
Konrad,
boot_ksetwas allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()but wasn't freed when module unloaded by
ibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()Thanks,
EthanQuoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fixit
Quoted 10 lines
Quoted 2 lines
in
scsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Review
Quoted 6 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/drivers/scsi/iscsi_boot_sysfs.cQuoted 4 lines
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct
Quoted 4 lines
index 14c1c8f..680bf6f 100644
drivers/scsi/iscsi_boot_sysfs.c +0
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct
iscsi_boot_kset*boot_kset)Quoted 9 lines
Quoted 9 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-1iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Quoted 4 lines
Quoted 2 lines
Right. In the past we did not do that b/c certain drivers (like broadcom) would allocate on the kset their name and try to free (the driver would after freeing the ibft). So you would end up with this patch a double free ( and it might be fixed by now but I can't recall).
Do you mean the name string that is passed into
kset_create_and_add?
Yes.
Quoted 8 lines
If so that should not happen now. There does not seem to be any user freeing that string.
There used to be bug where at the initiator/target/ethernet level there was a double free because
iscsi_boot_sysfsand be2iscsi were both freeing the struct associated with the initiator/target/ethernet. That is fixed inf457a46f179df41b0f6d80dee33b6e629945f276.
That is the one!
Quoted 2 lines
Quoted 60 lines · Konrad Rzeszutek Wilk
Quoted 50 lines · Mike Christie
Quoted 49 lines · Konrad Rzeszutek Wilk
Quoted 47 lines · Ethan Zhao
Konrad,
boot_ksetwas allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()but wasn't freed when module unloaded by
ibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()Thanks,
EthanQuoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fixit
Quoted 10 lines
Quoted 2 lines
in
scsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Review
Quoted 6 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/drivers/scsi/iscsi_boot_sysfs.cQuoted 4 lines
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct
Quoted 4 lines
index 14c1c8f..680bf6f 100644
drivers/scsi/iscsi_boot_sysfs.c +0
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct
iscsi_boot_kset*boot_kset)Quoted 9 lines
Quoted 9 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-1iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Quoted 4 lines
Quoted 2 lines
Right. In the past we did not do that b/c certain drivers (like broadcom) would allocate on the kset their name and try to free (the driver would after freeing the ibft). So you would end up with this patch a double free ( and it might be fixed by now but I can't recall).
Do you mean the name string that is passed into
kset_create_and_add?Yes.
Quoted 3 lines
If so that should not happen now. There does not seem to be any user freeing that string.
Quoted 7 lines
Quoted 5 lines
There used to be bug where at the initiator/target/ethernet level there was a double free because
iscsi_boot_sysfsand be2iscsi were both freeing the struct associated with the initiator/target/ethernet. That is fixed inf457a46f179df41b0f6d80dee33b6e629945f276.That is the one!
With that in mind, do you want to carry this patch to Linus (or James) or should I do it?
Quoted 2 lines
Quoted 2 lines
Quoted 49 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Ethan Zhao
Konrad,
boot_ksetwas allocated when module loaded byibft_init()
iscsi_boot_create_kset()
kzalloc()but wasn't freed when module unloaded by
ibft_exit()
ibft_cleanup()
iscsi_boot_destroy_kset()Thanks,
EthanQuoted 4 lines · Konrad Rzeszutek Wilk
Quoted 3 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fixit
Quoted 9 lines
Quoted 2 lines
in
scsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Is there a stack trace?
Quoted 5 lines
Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)Quoted 16 lines
Quoted 1 line
Review
Quoted 1 line
(quoted diff) +0
-0
b/drivers/scsi/iscsi_boot_sysfs.cQuoted 4 lines
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct
Quoted 4 lines
index 14c1c8f..680bf6f 100644
drivers/scsi/iscsi_boot_sysfs.c +0
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct
iscsi_boot_kset*boot_kset)Quoted 9 lines
Quoted 9 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-1iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset); --1.8.3.4 (Apple Git-47)
Quoted 3 lines
Right. In the past we did not do that b/c certain drivers (like broadcom) would allocate on the kset their name and try to free (the driver would after freeing the ibft). So you would end up with this patch a double free ( and it might be fixed by now but I can't recall).
My question was - did you observer a crash or bug. Hence the question about stack trace? How did you see this?
That is quite simple, just like fuzzy test, load and unload a module millions of times with a script in low memory size machine, in the meanwhile, monitor OOM etc.
Thanks,
Ethan
Quoted 3 lines
Thank you.
Quoted 15 lines · Ethan Zhao
From: "Ethan Zhao" <[email protected]>
Load and unload
iscsi_ibftmodule will cause kernel memory leak, fix it inscsi/iscsi_boot_sysfs.ciscsi_boot_destroy_kset().Signed-off-by Ethan Zhao <[email protected]>--- drivers/scsi/iscsi_boot_sysfs.c | 1 + 1 file changed, 1 insertion(+)drivers/scsi/iscsi_boot_sysfs.c +0
-0
drivers/scsi/iscsi_boot_sysfs.c void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset) · line 495
Quoted 6 lines
drivers/scsi/iscsi_boot_sysfs.c +1
-0@@ -490,5 +490,6 @@ void iscsi_boot_destroy_kset(struct iscsi_boot_kset *boot_kset)iscsi_boot_remove_kobj (boot_kobj);kset_unregister (boot_kset->kset); +kfree (boot_kset); }EXPORT_SYMBOL_GPL (iscsi_boot_destroy_kset);
Thanks. Patch looks ok.
It is probably best to just kill the iscsi_boot_kset use and use the kset directly. To do that, we would need to make kset's list a klist and add some iterators then modify iscsi_boot_sysfs.c and iscsi_ibft.c to use them instead of using the iscsi_boot_kset->kobj_list. I will work on a patch to do this. But for now your patch is ok.