Skip to contentSkip to conversation

usb-storage: onetouch: Fix potential use-after-free on input failure

PATCH In review Guangshuo Li 3 participants 3 messages Nov 11

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 usb-storage: onetouch: Fix potential use-after-free on input failure

If input_register_device() fails, onetouch_connect_input() frees the onetouch state but leaves it installed in ss->extra. USB-storage cleanup then calls onetouch_release_input() on the freed state.

Install the extra state and callbacks only after input registration succeeds.

This issue was found by our static analysis tool under development.

Fixes 17efe155253e ("USB: onetouch - handle errors from input_register_device()")
---
 drivers/usb/storage/onetouch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/storage/onetouch.c +4 -4
index 49d281f7bef6..e09b3c6b9a6a 100644
@@ -237,16 +237,16 @@ static int onetouch_connect_input(struct us_data *ss)
 	onetouch->irq->transfer_dma = onetouch->data_dma;
 	onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
+	error = input_register_device(onetouch->dev);
+	if (error)
+		goto fail3;
+
 	ss->extra_destructor = onetouch_release_input;
 	ss->extra = onetouch;
 #ifdef CONFIG_PM
 	ss->suspend_resume_hook = usb_onetouch_pm_hook;
 #endif
 
-	error = input_register_device(onetouch->dev);
-	if (error)
-		goto fail3;
-
 	return 0;
 
  fail3:	usb_free_urb(onetouch->irq);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

If input_register_device() fails, onetouch_connect_input() frees the onetouch state but leaves it installed in ss->extra. USB-storage cleanup then calls onetouch_release_input() on the freed state.

Quoted 8 lines

Install the extra state and callbacks only after input registration succeeds.

This issue was found by our static analysis tool under development.

Fixes 17efe155253e ("USB: onetouch - handle errors from input_register_device()")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Acked-by on v1 1/1
#2 lore raw
In reply to Guangshuo Li
Quoted 7 lines · Guangshuo Li

If input_register_device() fails, onetouch_connect_input() frees the onetouch state but leaves it installed in ss->extra. USB-storage cleanup then calls onetouch_release_input() on the freed state.

Install the extra state and callbacks only after input registration succeeds.

Quoted 6 lines

This issue was found by our static analysis tool under development.

Fixes 17efe155253e ("USB: onetouch - handle errors from input_register_device()")

---

Quoted 33 lines
 drivers/usb/storage/onetouch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/usb/storage/onetouch.c +4 -4
index 49d281f7bef6..e09b3c6b9a6a 100644
@@ -237,16 +237,16 @@ static int onetouch_connect_input(struct us_data *ss)
 	onetouch->irq->transfer_dma = onetouch->data_dma;
 	onetouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
 
+	error = input_register_device(onetouch->dev);
+	if (error)
+		goto fail3;
+
 	ss->extra_destructor = onetouch_release_input;
 	ss->extra = onetouch;
 #ifdef CONFIG_PM
 	ss->suspend_resume_hook = usb_onetouch_pm_hook;
 #endif
 
-	error = input_register_device(onetouch->dev);
-	if (error)
-		goto fail3;
-
 	return 0;
 
  fail3:	usb_free_urb(onetouch->irq);

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.43.0