USB: serial/usb_wwan, fix tty NULL dereference
Subsystems (2)
PATCH 1/1 USB: serial/usb_wwan, fix tty NULL dereference
tty_port_tty_get may return without any problems NULL. Handle this case and do not oops in usb_wwan_indat_callback by dereferencing it.
The oops:
Unable to handle kernel paging request for data at address 0x000000d8 Faulting instruction address: 0xc0175b3c Oops: Kernel access of bad area, sig: 11 [#1] PowerPC 40x Platform last sysfs file: /sys/devices/pci0000:00/0000:00:00.0/0000:01:00.0/0000:02:09.2/usb1/idVendor Modules linked in: NIP: c0175b3c LR: c0175e7c CTR: c0215c90 REGS: c77f7d50 TRAP: 0300 Not tainted (2.6.37-rc5) MSR: 00021030 <ME,CE,IR,DR> CR: 88482028 XER: 2000005f DEAR: 000000d8, ESR: 00000000
TASK = c7141b90[1149] 'wvdial' THREAD: c2750000
GPR00: 00021030 c77f7e00 c7141b90 00000000 0000000e 00000000 0000000e c0410680
GPR08: c683db00 00000000 00000001 c03c81f8 88482028 10073ef4 ffffffb9 ffffff94
GPR16: 00000000 fde036c0 00200200 00100100 00000001 ffffff8d c34fabcc 00000000
GPR24: c71120d4 00000000 00000000 0000000e 00021030 00000000 00000000 0000000e NIP [c0175b3c] tty_buffer_request_room+0x2c/0x194
LR [c0175e7c] tty_insert_flip_string_fixed_flag+0x3c/0xb0
Call Trace:
[c77f7e00] [00000003] 0x3 (unreliable)
[c77f7e30] [c0175e7c] tty_insert_flip_string_fixed_flag+0x3c/0xb0 [c77f7e60] [c0215df4] usb_wwan_indat_callback+0x164/0x170
...
References: https://bugzilla.kernel.org/show_bug.cgi?id=24582
--- drivers/usb/serial/usb_wwan.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
drivers/usb/serial/usb_wwan.c +9 -6
@@ -295,12 +295,15 @@ static void usb_wwan_indat_callback(struct urb *urb) __func__, status, endpoint); }else { tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty); - }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); +if (tty) { +if (urb->actual_length) { +tty_insert_flip_string (tty, data, + urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__); +tty_kref_put (tty); + }/* Resubmit urb so we continue receiving */ if (status != -ESHUTDOWN ) {
Signature · 1 line
1.7.3.4
Hello.
Quoted 48 lines · Jiri Slaby
tty_port_tty_getmay return without any problems NULL. Handle this case and do not oops inusb_wwan_indat_callbackby dereferencing it.The oops:
Unable to handle kernel paging request for data at address 0x000000d8 Faulting instruction address: 0xc0175b3c Oops: Kernel access of bad area, sig: 11 [#1] PowerPC 40x Platform last sysfs file: /sys/devices/pci0000:00/0000:00:00.0/0000:01:00.0/0000:02:09.2/usb1/idVendor Modules linked in: NIP: c0175b3c LR: c0175e7c CTR: c0215c90 REGS: c77f7d50 TRAP: 0300 Not tainted (2.6.37-rc5) MSR: 00021030 <ME,CE,IR,DR> CR: 88482028 XER: 2000005f DEAR: 000000d8, ESR: 00000000TASK = c7141b90[1149] 'wvdial' THREAD:
c2750000
GPR00: 00021030c77f7e00c7141b90000000000000000e000000000000000ec0410680
GPR08:c683db0000000000 00000001c03c81f88848202810073ef4ffffffb9ffffff94
GPR16: 00000000fde036c000200200 00100100 00000001ffffff8dc34fabcc00000000
GPR24:c71120d400000000 000000000000000e00021030 00000000 000000000000000eNIP [c0175b3c]tty_buffer_request_room+0x2c/0x194
LR [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0Call Trace:[
c77f7e00] [00000003]0x3(unreliable)
[c77f7e30] [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0[c77f7e60] [c0215df4]usb_wwan_indat_callback+0x164/0x170
...References: https://bugzilla.kernel.org/show_bug.cgi?id=24582
Cc Amit Shah <[email protected]>Cc baoyb <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jiri Slaby <[email protected]>--- drivers/usb/serial/usb_wwan.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)drivers/usb/serial/usb_wwan.c +0
-3@@ -295,12 +295,15 @@ static void usb_wwan_indat_callback(struct urb *urb) __func__, status, endpoint); }else { tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty);
drivers/usb/serial/usb_wwan.c static void usb_wwan_indat_callback(struct urb *urb) · line 304
Quoted 10 lines
drivers/usb/serial/usb_wwan.c +7
-3- }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); +if (tty) { +if (urb->actual_length) { +tty_insert_flip_string (tty, data, + urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__);
Should be {} on the *else* branch too, according to Documentation/CodingStyle...
WBR, Sergei
Quoted 6 lines · Sergei Shtylyov
Hello.
Quoted 2 lines · Jiri Slaby
tty_port_tty_getmay return without any problems NULL. Handle this case and do not oops inusb_wwan_indat_callbackby dereferencing it.
Thanks for looking at this!
Quoted 49 lines
Quoted 49 lines
The oops:
Unable to handle kernel paging request for data at address 0x000000d8 Faulting instruction address: 0xc0175b3c Oops: Kernel access of bad area, sig: 11 [#1] PowerPC 40x Platform last sysfs file: /sys/devices/pci0000:00/0000:00:00.0/0000:01:00.0/0000:02:09.2/usb1/idVendor Modules linked in: NIP: c0175b3c LR: c0175e7c CTR: c0215c90 REGS: c77f7d50 TRAP: 0300 Not tainted (2.6.37-rc5) MSR: 00021030 <ME,CE,IR,DR> CR: 88482028 XER: 2000005f DEAR: 000000d8, ESR: 00000000TASK = c7141b90[1149] 'wvdial' THREAD:
c2750000
GPR00: 00021030c77f7e00c7141b90000000000000000e000000000000000ec0410680
GPR08:c683db0000000000 00000001c03c81f88848202810073ef4ffffffb9ffffff94
GPR16: 00000000fde036c000200200 00100100 00000001ffffff8dc34fabcc00000000
GPR24:c71120d400000000 000000000000000e00021030 00000000 000000000000000eNIP [c0175b3c]tty_buffer_request_room+0x2c/0x194
LR [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0Call Trace:[
c77f7e00] [00000003]0x3(unreliable)
[c77f7e30] [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0[c77f7e60] [c0215df4]usb_wwan_indat_callback+0x164/0x170
...References: https://bugzilla.kernel.org/show_bug.cgi?id=24582
Cc Amit Shah <[email protected]>Cc baoyb <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jiri Slaby <[email protected]>---
drivers/usb/serial/usb_wwan.c| 15 +++++++++------1 files changed, 9 insertions(+), 6 deletions(-)drivers/usb/serial/usb_wwan.c +1
-6@@ -295,12 +295,15 @@ static void usb_wwan_indat_callback(struct urb *urb) __func__, status, endpoint); }else { tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty); - }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); +if (tty) {
Quoted 8 lines
drivers/usb/serial/usb_wwan.c static void usb_wwan_indat_callback(struct urb *urb) · line 304
Quoted 6 lines
drivers/usb/serial/usb_wwan.c +6
-0+if (urb->actual_length) { +tty_insert_flip_string (tty, data, + urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__);Should be {} on the *else* branch too, according to
Documentation/CodingStyle...
If you're fixing that, might as well return in the 'if' above so that this entire 'else' block becomes non-indented.
Amit
Signature · 1 line
http://log.amitshah.net/
Quoted 68 lines · Amit Shah
Quoted 6 lines · Sergei Shtylyov
Hello.
Quoted 2 lines · Jiri Slaby
tty_port_tty_getmay return without any problems NULL. Handle this case and do not oops inusb_wwan_indat_callbackby dereferencing it.Thanks for looking at this!
Quoted 49 lines
Quoted 49 lines
The oops:
Unable to handle kernel paging request for data at address 0x000000d8 Faulting instruction address: 0xc0175b3c Oops: Kernel access of bad area, sig: 11 [#1] PowerPC 40x Platform last sysfs file: /sys/devices/pci0000:00/0000:00:00.0/0000:01:00.0/0000:02:09.2/usb1/idVendor Modules linked in: NIP: c0175b3c LR: c0175e7c CTR: c0215c90 REGS: c77f7d50 TRAP: 0300 Not tainted (2.6.37-rc5) MSR: 00021030 <ME,CE,IR,DR> CR: 88482028 XER: 2000005f DEAR: 000000d8, ESR: 00000000TASK = c7141b90[1149] 'wvdial' THREAD:
c2750000
GPR00: 00021030c77f7e00c7141b90000000000000000e000000000000000ec0410680
GPR08:c683db0000000000 00000001c03c81f88848202810073ef4ffffffb9ffffff94
GPR16: 00000000fde036c000200200 00100100 00000001ffffff8dc34fabcc00000000
GPR24:c71120d400000000 000000000000000e00021030 00000000 000000000000000eNIP [c0175b3c]tty_buffer_request_room+0x2c/0x194
LR [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0Call Trace:[
c77f7e00] [00000003]0x3(unreliable)
[c77f7e30] [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0[c77f7e60] [c0215df4]usb_wwan_indat_callback+0x164/0x170
...References: https://bugzilla.kernel.org/show_bug.cgi?id=24582
Cc Amit Shah <[email protected]>Cc baoyb <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jiri Slaby <[email protected]>---
drivers/usb/serial/usb_wwan.c| 15 +++++++++------1 files changed, 9 insertions(+), 6 deletions(-)drivers/usb/serial/usb_wwan.c +1
-6@@ -295,12 +295,15 @@ static void usb_wwan_indat_callback(struct urb *urb) __func__, status, endpoint); }else { tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty); - }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); +if (tty) {Quoted 8 lines
drivers/usb/serial/usb_wwan.c static void usb_wwan_indat_callback(struct urb *urb) · line 304
Quoted 6 lines
drivers/usb/serial/usb_wwan.c +6
-0+if (urb->actual_length) { +tty_insert_flip_string (tty, data, + urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__);Should be {} on the *else* branch too, according to
Documentation/CodingStyle...
Quoted 1 line
If you're fixing that, might as well return in the 'if' above
No, the urb has to be resubmitted.
regards,
Signature · 1 line
js
Quoted 3 lines · Jiri Slaby
Quoted 1 line
If you're fixing that, might as well return in the 'if' above
No, the urb has to be resubmitted.
Ah; I meant the following, but it hardly matters..
drivers/usb/serial/usb_wwan.c +18 -19
@@ -293,25 +293,24 @@ static void usb_wwan_indat_callback(struct urb *urb)if (status) {dbg ("%s: nonzero status: %d on endpoint %02x." , __func__, status, endpoint); - }else { - tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty); - }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); - -/* Resubmit urb so we continue receiving */ -if (status != -ESHUTDOWN ) { - err =usb_submit_urb (urb,GFP_ATOMIC ); -if (err && err != -EPERM ) -printk (KERN_ERR "%s: resubmit read urb failed. " -"(%d)" , __func__, err); -else -usb_mark_last_busy (port->serial->dev); - } - +return ; + } + tty =tty_port_tty_get (&port->port); +if (urb->actual_length) { +tty_insert_flip_string (tty, data, urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__); +tty_kref_put (tty); + +/* Resubmit urb so we continue receiving */ +if (status != -ESHUTDOWN ) { + err =usb_submit_urb (urb,GFP_ATOMIC ); +if (err && err != -EPERM ) +printk (KERN_ERR "%s: resubmit read urb failed. " +"(%d)" , __func__, err); +else +usb_mark_last_busy (port->serial->dev); } }
Amit
Signature · 1 line
http://log.amitshah.net/
Quoted 56 lines · Sergei Shtylyov
Hello.
Quoted 52 lines · Jiri Slaby
tty_port_tty_getmay return without any problems NULL. Handle this case and do not oops inusb_wwan_indat_callbackby dereferencing it.The oops:
Unable to handle kernel paging request for data at address 0x000000d8 Faulting instruction address: 0xc0175b3c Oops: Kernel access of bad area, sig: 11 [#1] PowerPC 40x Platform last sysfs file: /sys/devices/pci0000:00/0000:00:00.0/0000:01:00.0/0000:02:09.2/usb1/idVendor Modules linked in: NIP: c0175b3c LR: c0175e7c CTR: c0215c90 REGS: c77f7d50 TRAP: 0300 Not tainted (2.6.37-rc5) MSR: 00021030 <ME,CE,IR,DR> CR: 88482028 XER: 2000005f DEAR: 000000d8, ESR: 00000000TASK = c7141b90[1149] 'wvdial' THREAD:
c2750000
GPR00: 00021030c77f7e00c7141b90000000000000000e000000000000000ec0410680
GPR08:c683db0000000000 00000001c03c81f88848202810073ef4ffffffb9ffffff94
GPR16: 00000000fde036c000200200 00100100 00000001ffffff8dc34fabcc00000000
GPR24:c71120d400000000 000000000000000e00021030 00000000 000000000000000eNIP [c0175b3c]tty_buffer_request_room+0x2c/0x194
LR [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0Call Trace:[
c77f7e00] [00000003]0x3(unreliable)
[c77f7e30] [c0175e7c]tty_insert_flip_string_fixed_flag+0x3c/0xb0[c77f7e60] [c0215df4]usb_wwan_indat_callback+0x164/0x170
...References: https://bugzilla.kernel.org/show_bug.cgi?id=24582
Cc Amit Shah <[email protected]>Cc baoyb <[email protected]>Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Jiri Slaby <[email protected]>---
drivers/usb/serial/usb_wwan.c| 15 +++++++++------1 files changed, 9 insertions(+), 6 deletions(-)drivers/usb/serial/usb_wwan.c +1
-6@@ -295,12 +295,15 @@ static void usb_wwan_indat_callback(struct urb *urb) __func__, status, endpoint); }else { tty =tty_port_tty_get (&port->port); -if (urb->actual_length) { -tty_insert_flip_string (tty, data, urb->actual_length); -tty_flip_buffer_push (tty); - }else -dbg ("%s: empty read urb received" , __func__); -tty_kref_put (tty); +if (tty) {
Quoted 8 lines
drivers/usb/serial/usb_wwan.c static void usb_wwan_indat_callback(struct urb *urb) · line 304
Quoted 6 lines
drivers/usb/serial/usb_wwan.c +6
-0+if (urb->actual_length) { +tty_insert_flip_string (tty, data, + urb->actual_length); +tty_flip_buffer_push (tty); + }else +dbg ("%s: empty read urb received" , __func__);Should be {} on the *else* branch too, according to
Documentation/CodingStyle...
It's not an issue, it is fine as-is.
Jiri, thanks for the fix, I'll queue it up soon.
greg k-h