Skip to contentSkip to conversation

usb: typec: ucsi: Fix NULL pointer dereference

PATCH In review Heikki Krogerus 4 participants 5 messages Sep 6, 2023 – Sep 11, 2023

Subsystems (3)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

PATCH 1/1 usb: typec: ucsi: Fix NULL pointer dereference

Making sure the UCSI debugfs entry actually exists before attempting to remove it.

Fixes df0383ffad64 ("usb: typec: ucsi: Add debugfs for ucsi commands")
Cc Saranya Gopal <[email protected]>
---
 drivers/usb/typec/ucsi/debugfs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/debugfs.c +3 -0
index 0c7bf88d4a7f..f67733cecfdf 100644
@@ -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
#1 lore raw
Quoted 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")
Cc Saranya Gopal <[email protected]>
---
 drivers/usb/typec/ucsi/debugfs.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/usb/typec/ucsi/debugfs.c +0 -0
index 0c7bf88d4a7f..f67733cecfdf 100644

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

#2 lore raw
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")
Cc Saranya Gopal <[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 -0
index 0c7bf88d4a7f..f67733cecfdf 100644

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?

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

#3 lore raw
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")

Closes:
https://lore.kernel.org/linux-usb/[email protected]/

I could also reproduce it with 7733171926cc336ddf0c8f847eefaff569dbff86 on 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 -0
index 0c7bf88d4a7f..f67733cecfdf 100644

drivers/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

#4 lore raw
Quoted 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")

Closes:
https://lore.kernel.org/linux-usb/[email protected]/

I could also reproduce it with 7733171926cc336ddf0c8f847eefaff569dbff86 on 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 -0
index 0c7bf88d4a7f..f67733cecfdf 100644

drivers/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