usb: typec: ucsi: Fix NULL pointer dereference
Subsystems (3)
Heikki Krogerus
maintainerPATCH 1/1 usb: typec: ucsi: Fix NULL pointer dereference
Making sure the UCSI debugfs entry actually exists before attempting to remove it.
--- drivers/usb/typec/ucsi/debugfs.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/debugfs.c +3 -0
@@ -84,6 +84,9 @@ void ucsi_debugfs_register(struct ucsi *ucsi)void ucsi_debugfs_unregister (struct ucsi *ucsi) { +if (IS_ERR_OR_NULL (ucsi) || !ucsi->debugfs) +return ; +debugfs_remove_recursive (ucsi->debugfs->dentry);kfree (ucsi->debugfs); }
Signature · 1 line
2.40.1
Greg Kroah-Hartman
maintainerQuoted 19 lines · Heikki Krogerus
Making sure the UCSI debugfs entry actually exists before attempting to remove it.
Fixes df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")Reported-by Dave Hansen <[email protected]>Suggested-by Dave Hansen <[email protected]>Suggested-by Mario Limonciello <[email protected]>Cc Saranya Gopal <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>--- drivers/usb/typec/ucsi/debugfs.c | 3 +++ 1 file changed, 3 insertions(+)drivers/usb/typec/ucsi/debugfs.c +0
-0
drivers/usb/typec/ucsi/debugfs.c void ucsi_debugfs_register(struct ucsi *ucsi) · line 90
Quoted 7 lines
drivers/usb/typec/ucsi/debugfs.c +3
-0@@ -84,6 +84,9 @@ void ucsi_debugfs_register(struct ucsi *ucsi)void ucsi_debugfs_unregister (struct ucsi *ucsi) { +if (IS_ERR_OR_NULL (ucsi) || !ucsi->debugfs) +return ; +debugfs_remove_recursive (ucsi->debugfs->dentry);
Why are you saving the dentry at all? Why not just have debugfs look it up when you want to remove it based on the filename?
Anyway, not a big deal here, just a comment. I'll queue this up after -rc1 is out.
thanks,
greg k-h
Quoted 11 lines · Greg Kroah-Hartman
Quoted 10 lines · Heikki Krogerus
Making sure the UCSI debugfs entry actually exists before attempting to remove it.
Fixes df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")Reported-by Dave Hansen <[email protected]>Suggested-by Dave Hansen <[email protected]>Suggested-by Mario Limonciello <[email protected]>Cc Saranya Gopal <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>
I could also reproduce it with 7733171926cc336ddf0c8f847eefaff569dbff86 on two different laptops.
Quoted 20 lines
Quoted 9 lines
--- drivers/usb/typec/ucsi/debugfs.c | 3 +++ 1 file changed, 3 insertions(+)drivers/usb/typec/ucsi/debugfs.c +0
-0drivers/usb/typec/ucsi/debugfs.c void ucsi_debugfs_register(struct ucsi *ucsi) · line 90
Quoted 7 lines
drivers/usb/typec/ucsi/debugfs.c +3
-0@@ -84,6 +84,9 @@ void ucsi_debugfs_register(struct ucsi *ucsi)void ucsi_debugfs_unregister (struct ucsi *ucsi) { +if (IS_ERR_OR_NULL (ucsi) || !ucsi->debugfs) +return ; +debugfs_remove_recursive (ucsi->debugfs->dentry);Why are you saving the dentry at all? Why not just have debugfs look it up when you want to remove it based on the filename?
Quoted 2 lines
Anyway, not a big deal here, just a comment. I'll queue this up after -rc1 is out.
It might be worth sending before rc1 if it ends up being widespread.
Quoted 4 lines
thanks,
greg k-h
Quoted 37 lines · Mario Limonciello
Quoted 4 lines · Greg Kroah-Hartman
Quoted 3 lines · Heikki Krogerus
Making sure the UCSI debugfs entry actually exists before attempting to remove it.
Quoted 8 lines
Quoted 8 lines
Fixes df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")Reported-by Dave Hansen <[email protected]>Closes:
https://lore.kernel.org/linux-usb/[email protected]/Suggested-by Dave Hansen <[email protected]>Suggested-by Mario Limonciello <[email protected]>Cc Saranya Gopal <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>I could also reproduce it with
7733171926cc336ddf0c8f847eefaff569dbff86on two different laptops.Quoted 20 lines
Quoted 10 lines
---
drivers/usb/typec/ucsi/debugfs.c| 3 +++1 file changed, 3 insertions(+)drivers/usb/typec/ucsi/debugfs.c +0
-0drivers/usb/typec/ucsi/debugfs.c void ucsi_debugfs_register(struct ucsi *ucsi) · line 89
Quoted 6 lines
drivers/usb/typec/ucsi/debugfs.c +3
-0@@ -84,6 +84,9 @@ void ucsi_debugfs_register(struct ucsi *ucsi) void ucsi_debugfs_unregister(struct ucsi *ucsi) { + if (IS_ERR_OR_NULL(ucsi) || !ucsi->debugfs) + return; + debugfs_remove_recursive(ucsi->debugfs->dentry);Why are you saving the dentry at all? Why not just have debugfs look it up when you want to remove it based on the filename?
Quoted 4 lines
Quoted 2 lines
Anyway, not a big deal here, just a comment. I'll queue this up after -rc1 is out.
It might be worth sending before rc1 if it ends up being widespread.
FWIW, as someone that afaics just ran into the regression fixed by this patch with -rc1, I would have liked that patch to be in -rc1 as well...
Ciao, Thorsten
Greg Kroah-Hartman
maintainerQuoted 38 lines · Thorsten Leemhuis
Quoted 37 lines · Mario Limonciello
Quoted 4 lines · Greg Kroah-Hartman
Quoted 3 lines · Heikki Krogerus
Making sure the UCSI debugfs entry actually exists before attempting to remove it.
Quoted 8 lines
Quoted 8 lines
Fixes df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")Reported-by Dave Hansen <[email protected]>Closes:
https://lore.kernel.org/linux-usb/[email protected]/Suggested-by Dave Hansen <[email protected]>Suggested-by Mario Limonciello <[email protected]>Cc Saranya Gopal <[email protected]>Signed-off-by Heikki Krogerus <[email protected]>I could also reproduce it with
7733171926cc336ddf0c8f847eefaff569dbff86on two different laptops.Quoted 20 lines
Quoted 10 lines
---
drivers/usb/typec/ucsi/debugfs.c| 3 +++1 file changed, 3 insertions(+)drivers/usb/typec/ucsi/debugfs.c +0
-0drivers/usb/typec/ucsi/debugfs.c void ucsi_debugfs_register(struct ucsi *ucsi) · line 89
Quoted 6 lines
drivers/usb/typec/ucsi/debugfs.c +3
-0@@ -84,6 +84,9 @@ void ucsi_debugfs_register(struct ucsi *ucsi) void ucsi_debugfs_unregister(struct ucsi *ucsi) { + if (IS_ERR_OR_NULL(ucsi) || !ucsi->debugfs) + return; + debugfs_remove_recursive(ucsi->debugfs->dentry);Why are you saving the dentry at all? Why not just have debugfs look it up when you want to remove it based on the filename?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Anyway, not a big deal here, just a comment. I'll queue this up after -rc1 is out.
It might be worth sending before rc1 if it ends up being widespread.
FWIW, as someone that afaics just ran into the regression fixed by this patch with -rc1, I would have liked that patch to be in -rc1 as well...
It's now queued up and will go to Linus this week.
thanks,
greg k-h