usb: storage: sierra_ms: reject short SWoC info transfers
Subsystems (3)
PATCH RESEND 1/1 usb: storage: sierra_ms: reject short SWoC info transfers
From: Syed Labeeq Sajid Bukhari <[email protected]>
sierra_get_swoc_info() requests sizeof(struct swoc_info) (60) bytes from the device via usb_control_msg(), but its callers only treat a negative return value as failure. A device that answers the vendor-specific GetSwocInfo request with a short IN transfer is therefore accepted, leaving the tail of the freshly allocated (kmalloc(), non-zeroing) swoc_info buffer uninitialized.
truinst_show() subsequently prints swocInfo->rev, swocInfo->LinuxSKU and swocInfo->LinuxVer from that buffer into the world-readable (0444) "truinst" sysfs attribute. An emulated/malicious USB device (VID 0x1199, PID 0x0fff) can exploit this to disclose up to 5 bytes of stale kernel heap memory (kmalloc-64) to unprivileged userspace, once per sysfs read, indefinitely. On kernels built without init_on_alloc this leaks recently freed heap contents.
Only accept the transfer when the full structure was received. sierra_ms_init() already retries failed queries, so well-behaved devices are unaffected.
---
Resend: the first posting was whitespace-mangled by a webmail client; no code changes.
drivers/usb/storage/sierra_ms.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/usb/storage/sierra_ms.c +6 -0
@@ -76,6 +76,12 @@ (void *) swocInfo,/* void *data */ sizeof (struct swoc_info ),/* __u16 size */ USB_CTRL_SET_TIMEOUT); /* int timeout */ +/* +* A short IN transfer leaves the tail of swocInfo uninitialized; +* only a full transfer is valid. +*/ +if (result !=sizeof (struct swoc_info )) +return -EIO ; swocInfo->LinuxSKU =le16_to_cpu (swocInfo->LinuxSKU); swocInfo->LinuxVer =le16_to_cpu (swocInfo->LinuxVer);
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 35 lines · syedlabeeq
From: Syed Labeeq Sajid Bukhari <[email protected]>
sierra_get_swoc_info()requestssizeof(struct swoc_info)(60) bytes from the device viausb_control_msg(), but its callers only treat a negative return value as failure. A device that answers the vendor-specific GetSwocInfo request with a short IN transfer is therefore accepted, leaving the tail of the freshly allocated (kmalloc(), non-zeroing)swoc_infobuffer uninitialized.
truinst_show()subsequently printsswocInfo->rev,swocInfo->LinuxSKUandswocInfo->LinuxVerfrom that buffer into the world-readable (0444) "truinst" sysfs attribute. An emulated/malicious USB device (VID0x1199, PID0x0fff) can exploit this to disclose up to 5 bytes of stale kernel heap memory (kmalloc-64) to unprivileged userspace, once per sysfs read, indefinitely. On kernels built withoutinit_on_allocthis leaks recently freed heap contents.Only accept the transfer when the full structure was received.
sierra_ms_init()already retries failed queries, so well-behaved devices are unaffected.Fixes 32fe5e393455 ("USB Storage Sierra: TRU-Install feature update")Signed-off-by Syed Labeeq Sajid Bukhari <[email protected]>---
Resend: the first posting was whitespace-mangled by a webmail client; no code changes.drivers/usb/storage/sierra_ms.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/usb/storage/sierra_ms.c +0
-0
drivers/usb/storage/sierra_ms.c line 84
Quoted 9 lines
drivers/usb/storage/sierra_ms.c +6
-0@@ -76,6 +76,12 @@ (void *) swocInfo,/* void *data */ sizeof (struct swoc_info ),/* __u16 size */ USB_CTRL_SET_TIMEOUT); /* int timeout */ +/* +* A short IN transfer leaves the tail of swocInfo uninitialized; +* only a full transfer is valid. +*/ +if (result !=sizeof (struct swoc_info )) +return -EIO ;
Don't you need a blank line before this comment?
And did you forget an Assisted-by: tag?
thanks,
greg k-h
Good catch on both. i hv sent v2 with the blank line and the Assisted-by tag.
Thanks,
Syed Labeeq
Quoted 54 lines · Greg KH
Quoted 35 lines · syedlabeeq
From: Syed Labeeq Sajid Bukhari <[email protected]>
sierra_get_swoc_info()requestssizeof(struct swoc_info)(60) bytes from the device viausb_control_msg(), but its callers only treat a negative return value as failure. A device that answers the vendor-specific GetSwocInfo request with a short IN transfer is therefore accepted, leaving the tail of the freshly allocated (kmalloc(), non-zeroing)swoc_infobuffer uninitialized.
truinst_show()subsequently printsswocInfo->rev,swocInfo->LinuxSKUandswocInfo->LinuxVerfrom that buffer into the world-readable (0444) "truinst" sysfs attribute. An emulated/malicious USB device (VID0x1199, PID0x0fff) can exploit this to disclose up to 5 bytes of stale kernel heap memory (kmalloc-64) to unprivileged userspace, once per sysfs read, indefinitely. On kernels built withoutinit_on_allocthis leaks recently freed heap contents.Only accept the transfer when the full structure was received.
sierra_ms_init()already retries failed queries, so well-behaved devices are unaffected.Fixes 32fe5e393455 ("USB Storage Sierra: TRU-Install feature update")Signed-off-by Syed Labeeq Sajid Bukhari <[email protected]>---
Resend: the first posting was whitespace-mangled by a webmail client; no code changes.drivers/usb/storage/sierra_ms.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/usb/storage/sierra_ms.c +0
-0drivers/usb/storage/sierra_ms.c line 84
Quoted 9 lines
drivers/usb/storage/sierra_ms.c +6
-0@@ -76,6 +76,12 @@ (void *) swocInfo,/* void *data */ sizeof (struct swoc_info ),/* __u16 size */ USB_CTRL_SET_TIMEOUT); /* int timeout */ +/* +* A short IN transfer leaves the tail of swocInfo uninitialized; +* only a full transfer is valid. +*/ +if (result !=sizeof (struct swoc_info )) +return -EIO ;Don't you need a blank line before this comment?
And did you forget an Assisted-by: tag?
thanks,
greg k-h