Backports for security and critical bug fixes
Subsystems (3)
cover Backports for security and critical bug fixes
As I started backporting security fixes, found a few problems that prevent tools to build on newer gcc releases, deadlock bug, and another bug that prevents client from being able to use imported devices.
This patch series consists of security fixes and fixes to critical bugs.
Andrew Goodbody (1):
usb: usbip: Fix possible deadlocks reported by lockdep
Shuah Khan (8):
usbip: fix stub_rx: get_pipe() to validate endpoint number
usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input
usbip: prevent vhci_hcd driver from leaking a socket pointer address
usbip: Fix potential format overflow in userspace tools
usbip: vhci_hcd: clear just the USB_PORT_STAT_POWER bit
usbip: prevent leaking socket pointer address in messages
usbip: stub: stop printing kernel pointer addresses in messages
usbip: vhci: stop printing kernel pointer addresses in messages
drivers/usb/usbip/stub_dev.c | 3 +- drivers/usb/usbip/stub_main.c | 5 +- drivers/usb/usbip/stub_rx.c | 53 +++++++++++---- drivers/usb/usbip/stub_tx.c | 4 +- drivers/usb/usbip/usbip_common.c | 15 ++--- drivers/usb/usbip/usbip_common.h | 1 + drivers/usb/usbip/usbip_event.c | 5 +- drivers/usb/usbip/vhci_hcd.c | 102 +++++++++++++++-------------- drivers/usb/usbip/vhci_rx.c | 53 ++++++++------- drivers/usb/usbip/vhci_sysfs.c | 45 +++++++------ drivers/usb/usbip/vhci_tx.c | 17 +++-- tools/usb/usbip/libsrc/usbip_common.c | 9 ++- tools/usb/usbip/libsrc/usbip_host_driver.c | 27 ++++++-- tools/usb/usbip/libsrc/vhci_driver.c | 8 +-- 14 files changed, 205 insertions(+), 142 deletions(-)
Signature · 1 line
2.14.1
PATCH 1/9 usbip: fix stub_rx: get_pipe() to validate endpoint number
Upstream commit 635f545a7e8b ("usbip: fix stub_rx: get_pipe() to validate endpoint number")
get_pipe() routine doesn't validate the input endpoint number and uses to reference ep_in and ep_out arrays. Invalid endpoint number can trigger BUG(). Range check the epnum and returning error instead of calling BUG().
Change caller stub_recv_cmd_submit() to handle the get_pipe() error return.
--- drivers/usb/usbip/stub_rx.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
drivers/usb/usbip/stub_rx.c +10 -6
@@ -347,15 +347,15 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir)struct usb_host_endpoint *ep;struct usb_endpoint_descriptor *epd =NULL ; +if (epnum <0 || epnum >15 ) + goto err_ret; +if (dir ==USBIP_DIR_IN ) ep = udev->ep_in[epnum &0x7f ];else ep = udev->ep_out[epnum &0x7f ]; -if (!ep) { -dev_err (&sdev->interface->dev,"no such endpoint?, %d\n" , - epnum); -BUG (); - } +if (!ep) + goto err_ret; epd = &ep->desc;if (usb_endpoint_xfer_control (epd)) {
@@ -386,9 +386,10 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir)return usb_rcvisocpipe (udev, epnum); } +err_ret:/* NOT REACHED */ dev_err (&sdev->interface->dev,"get pipe, epnum %d\n" , epnum); -return 0 ; +return -1 ; }static void masking_bogus_flags (struct urb *urb)
@@ -454,6 +455,9 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,struct usb_device *udev = sdev->udev;int pipe =get_pipe (sdev, pdu->base.ep, pdu->base.direction); +if (pipe ==-1 ) +return ; + priv =stub_priv_alloc (sdev, pdu);if (!priv)return ;
PATCH 2/9 usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input
In reply to Shuah KhanUpstream commit c6688ef9f297 ("usbip: fix stub_rx: harden CMD_SUBMIT path to handle malicious input")
Harden CMD_SUBMIT path to handle malicious input that could trigger large memory allocations. Add checks to validate transfer_buffer_length and number_of_packets to protect against bad input requesting for unbounded memory allocations. Validate early in get_pipe() and return failure.
--- drivers/usb/usbip/stub_rx.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-)
drivers/usb/usbip/stub_rx.c +27 -3
@@ -341,11 +341,13 @@ static struct stub_priv *stub_priv_alloc(struct stub_device *sdev,return priv; } -static int get_pipe (struct stub_device *sdev,int epnum,int dir) +static int get_pipe (struct stub_device *sdev,struct usbip_header *pdu) {struct usb_device *udev = sdev->udev;struct usb_host_endpoint *ep;struct usb_endpoint_descriptor *epd =NULL ; +int epnum = pdu->base.ep; +int dir = pdu->base.direction;if (epnum <0 || epnum >15 ) goto err_ret;
@@ -358,6 +360,7 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir) goto err_ret; epd = &ep->desc; +if (usb_endpoint_xfer_control (epd)) {if (dir ==USBIP_DIR_OUT )return usb_sndctrlpipe (udev, epnum);
@@ -380,6 +383,27 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir) }if (usb_endpoint_xfer_isoc (epd)) { +/* validate packet size and number of packets */ +unsigned int maxp, packets, bytes; + +#define USB_EP_MAXP_MULT_SHIFT 11 +#define USB_EP_MAXP_MULT_MASK (3 << USB_EP_MAXP_MULT_SHIFT) +#define USB_EP_MAXP_MULT (m) \ + (((m) & USB_EP_MAXP_MULT_MASK) >> USB_EP_MAXP_MULT_SHIFT) + + maxp =usb_endpoint_maxp (epd); + maxp *= (USB_EP_MAXP_MULT ( +__le16_to_cpu (epd->wMaxPacketSize)) +1 ); + bytes = pdu->u.cmd_submit.transfer_buffer_length; + packets =DIV_ROUND_UP (bytes, maxp); + +if (pdu->u.cmd_submit.number_of_packets <0 || + pdu->u.cmd_submit.number_of_packets > packets) { +dev_err (&sdev->udev->dev, +"CMD_SUBMIT: isoc invalid num packets %d\n" , + pdu->u.cmd_submit.number_of_packets); +return -1 ; + }if (dir ==USBIP_DIR_OUT )return usb_sndisocpipe (udev, epnum);else
@@ -388,7 +412,7 @@ static int get_pipe(struct stub_device *sdev, int epnum, int dir) err_ret:/* NOT REACHED */ -dev_err (&sdev->interface->dev,"get pipe, epnum %d\n" , epnum); +dev_err (&sdev->udev->dev,"CMD_SUBMIT: invalid epnum %d\n" , epnum);return -1 ; }
@@ -453,7 +477,7 @@ static void stub_recv_cmd_submit(struct stub_device *sdev,struct stub_priv *priv;struct usbip_device *ud = &sdev->ud;struct usb_device *udev = sdev->udev; -int pipe =get_pipe (sdev, pdu->base.ep, pdu->base.direction); +int pipe =get_pipe (sdev, pdu);if (pipe ==-1 )return ;
PATCH 3/9 usbip: prevent vhci_hcd driver from leaking a socket pointer address
In reply to Shuah Khancommit 2f2d0088eb93 ("usbip: prevent vhci_hcd driver from leaking a socket pointer address")
When a client has a USB device attached over IP, the vhci_hcd driver is locally leaking a socket pointer address via the
/sys/devices/platform/vhci_hcd/status file (world-readable) and in debug output when "usbip --debug port" is run.
Fix it to not leak. The socket pointer address is not used at the moment and it was made visible as a convenient way to find IP address from socket pointer address by looking up /proc/net/{tcp,tcp6}.
As this opens a security hole, the fix replaces socket pointer address with sockfd.
--- drivers/usb/usbip/usbip_common.h | 1 + drivers/usb/usbip/vhci_sysfs.c | 26 +++++++++++++++----------- tools/usb/usbip/libsrc/vhci_driver.c | 8 ++++---- 3 files changed, 20 insertions(+), 15 deletions(-)
drivers/usb/usbip/usbip_common.h +1 -0
@@ -261,6 +261,7 @@ struct usbip_device {/* lock for status */ spinlock_t lock; +int sockfd;struct socket *tcp_socket;struct task_struct *tcp_rx;
drivers/usb/usbip/vhci_sysfs.c +15 -11
@@ -39,16 +39,20 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,/* * output example: -* prt sta spd dev socket local_busid -* 000 004 000 000 c5a7bb80 1-2.3 -* 001 004 000 000 d8cee980 2-3.4 +* prt sta spd dev sockfd local_busid +* 0000 004 000 00000000 000003 1-2.3 +* 0001 004 000 00000000 000004 2-3.4 * -* IP address can be retrieved from a socket pointer address by looking -* up /proc/net/{tcp,tcp6}. Also, a userland program may remember a -* port number and its peer IP address. +* Output includes socket fd instead of socket pointer address to +* avoid leaking kernel memory address in: +* /sys/devices/platform/vhci_hcd.0/status and in debug output. +* The socket pointer address is not used at the moment and it was +* made visible as a convenient way to find IP address from socket +* pointer address by looking up /proc/net/{tcp,tcp6}. As this opens +* a security hole, the change is made to use sockfd instead. */ out +=sprintf (out, -"prt sta spd bus dev socket local_busid\n" ); +"prt sta spd dev sockfd local_busid\n" );for (i =0 ; i <VHCI_NPORTS ; i++) {struct vhci_device *vdev =port_to_vdev (i);
@@ -59,12 +63,11 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,if (vdev->ud.status ==VDEV_ST_USED ) { out +=sprintf (out,"%03u %08x " , vdev->speed, vdev->devid); - out +=sprintf (out,"%16p " , vdev->ud.tcp_socket); + out +=sprintf (out,"%06u " , vdev->ud.sockfd); out +=sprintf (out,"%s" ,dev_name (&vdev->udev->dev)); - }else { - out +=sprintf (out,"000 000 000 0000000000000000 0-0" ); - } + }else + out +=sprintf (out,"000 00000000 000000 0-0" ); out +=sprintf (out,"\n" );spin_unlock (&vdev->ud.lock);
@@ -223,6 +226,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, vdev->devid = devid; vdev->speed = speed; + vdev->ud.sockfd = sockfd; vdev->ud.tcp_socket = socket; vdev->ud.status =VDEV_ST_NOTASSIGNED ;
tools/usb/usbip/libsrc/vhci_driver.c +4 -4
@@ -55,12 +55,12 @@ static int parse_status(const char *value)while (*c !='\0' ) {int port, status, speed, devid; -unsigned long socket; +int sockfd;char lbusid[SYSFS_BUS_ID_SIZE ]; - ret =sscanf (c,"%d %d %d %x %lx %31s\n" , + ret =sscanf (c,"%d %d %d %x %u %31s\n" , &port, &status, &speed, - &devid, &socket, lbusid); + &devid, &sockfd, lbusid);if (ret <5 ) {dbg ("sscanf failed: %d" , ret);
@@ -69,7 +69,7 @@ static int parse_status(const char *value)dbg ("port %d status %d speed %d devid %x" , port, status, speed, devid); -dbg ("socket %lx lbusid %s" , socket, lbusid); +dbg ("sockfd %u lbusid %s" , sockfd, lbusid);/* if a device is connected, look at it */
PATCH 4/9 usbip: Fix potential format overflow in userspace tools
In reply to Shuah KhanUpstream commit e5dfa3f902b9 ("usbip: Fix potential format overflow in userspace tools")
The usbip userspace tools call sprintf()/snprintf() and don't check for the return value which can lead the paths to overflow, truncating the final file in the path.
More urgently, GCC 7 now warns that these aren't checked with -Wformat-overflow, and with -Werror enabled in configure.ac, that makes these tools unbuildable.
This patch fixes these problems by replacing sprintf() with snprintf() in one place and adding checks for the return value of snprintf().
--- tools/usb/usbip/libsrc/usbip_common.c | 9 ++++++++- tools/usb/usbip/libsrc/usbip_host_driver.c | 27 ++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-)
tools/usb/usbip/libsrc/usbip_common.c +8 -1
@@ -215,9 +215,16 @@ int read_usb_interface(struct usbip_usb_device *udev, int i, struct usbip_usb_interface *uinf) {char busid[SYSFS_BUS_ID_SIZE ]; +int size;struct udev_device *sif; -sprintf (busid,"%s:%d.%d" , udev->busid, udev->bConfigurationValue, i); + size =snprintf (busid,sizeof (busid),"%s:%d.%d" , + udev->busid, udev->bConfigurationValue, i); +if (size <0 || (unsigned int )size >=sizeof (busid)) { +err ("busid length %i >= %lu or < 0" , size, + (unsigned long )sizeof (busid)); +return -1 ; + } sif =udev_device_new_from_subsystem_sysname (udev_context,"usb" , busid);if (!sif) {
tools/usb/usbip/libsrc/usbip_host_driver.c +22 -5
@@ -39,13 +39,19 @@ struct udev *udev_context;static int32_t read_attr_usbip_status (struct usbip_usb_device *udev) {char status_attr_path[SYSFS_PATH_MAX ]; +int size;int fd;int length;char status;int value =0 ; -snprintf (status_attr_path,SYSFS_PATH_MAX ,"%s/usbip_status" , - udev->path); + size =snprintf (status_attr_path,SYSFS_PATH_MAX ,"%s/usbip_status" , + udev->path); +if (size <0 || (unsigned int )size >=sizeof (status_attr_path)) { +err ("usbip_status path length %i >= %lu or < 0" , size, + (unsigned long )sizeof (status_attr_path)); +return -1 ; + } fd =open (status_attr_path,O_RDONLY );if (fd <0 ) {
@@ -225,6 +231,7 @@ int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd) {char attr_name[] ="usbip_sockfd" ;char sockfd_attr_path[SYSFS_PATH_MAX ]; +int size;char sockfd_buff[30 ];int ret;
@@ -244,10 +251,20 @@ int usbip_host_export_device(struct usbip_exported_device *edev, int sockfd) }/* only the first interface is true */ -snprintf (sockfd_attr_path,sizeof (sockfd_attr_path),"%s/%s" , - edev->udev.path, attr_name); + size =snprintf (sockfd_attr_path,sizeof (sockfd_attr_path),"%s/%s" , + edev->udev.path, attr_name); +if (size <0 || (unsigned int )size >=sizeof (sockfd_attr_path)) { +err ("exported device path length %i >= %lu or < 0" , size, + (unsigned long )sizeof (sockfd_attr_path)); +return -1 ; + } -snprintf (sockfd_buff,sizeof (sockfd_buff),"%d\n" , sockfd); + size =snprintf (sockfd_buff,sizeof (sockfd_buff),"%d\n" , sockfd); +if (size <0 || (unsigned int )size >=sizeof (sockfd_buff)) { +err ("socket length %i >= %lu or < 0" , size, + (unsigned long )sizeof (sockfd_buff)); +return -1 ; + } ret =write_sysfs_attribute (sockfd_attr_path, sockfd_buff,strlen (sockfd_buff));
PATCH 5/9 usb: usbip: Fix possible deadlocks reported by lockdep
In reply to Shuah KhanFrom: Andrew Goodbody <[email protected]>
Upstream commit 21619792d1ec ("usb: usbip: Fix possible deadlocks reported by lockdep")
Change spin_lock calls to spin_lock_irqsave to prevent attmpted recursive lock taking in interrupt context.
This patch fixes Bug 109351
https://bugzilla.kernel.org/show_bug.cgi?id=109351
--- drivers/usb/usbip/usbip_event.c | 5 ++- drivers/usb/usbip/vhci_hcd.c | 88 ++++++++++++++++++++++++----------------- drivers/usb/usbip/vhci_rx.c | 30 ++++++++------ drivers/usb/usbip/vhci_sysfs.c | 19 +++++---- drivers/usb/usbip/vhci_tx.c | 14 ++++--- 5 files changed, 91 insertions(+), 65 deletions(-)
drivers/usb/usbip/usbip_event.c +3 -2
@@ -117,11 +117,12 @@ EXPORT_SYMBOL_GPL(usbip_event_add);int usbip_event_happened (struct usbip_device *ud) {int happened =0 ; +unsigned long flags; -spin_lock (&ud->lock); +spin_lock_irqsave (&ud->lock, flags);if (ud->event !=0 ) happened =1 ; -spin_unlock (&ud->lock); +spin_unlock_irqrestore (&ud->lock, flags);return happened; }
drivers/usb/usbip/vhci_hcd.c +52 -36
321 lines not on this page · raw message
drivers/usb/usbip/vhci_rx.c +17 -13
@@ -72,10 +72,11 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev, {struct usbip_device *ud = &vdev->ud;struct urb *urb; +unsigned long flags; -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags); urb =pickup_urb_and_free_priv (vdev, pdu->base.seqnum); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);if (!urb) {pr_err ("cannot find a urb of seqnum %u\n" , pdu->base.seqnum);
@@ -104,9 +105,9 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,usbip_dbg_vhci_rx ("now giveback urb %p\n" , urb); -spin_lock (&the_controller->lock); +spin_lock_irqsave (&the_controller->lock, flags);usb_hcd_unlink_urb_from_ep (vhci_to_hcd (the_controller), urb); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);usb_hcd_giveback_urb (vhci_to_hcd (the_controller), urb, urb->status);
@@ -117,8 +118,9 @@ static struct vhci_unlink *dequeue_pending_unlink(struct vhci_device *vdev, struct usbip_header *pdu) {struct vhci_unlink *unlink, *tmp; +unsigned long flags; -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags);list_for_each_entry_safe (unlink, tmp, &vdev->unlink_rx, list) {pr_info ("unlink->seqnum %lu\n" , unlink->seqnum);
@@ -127,12 +129,12 @@ static struct vhci_unlink *dequeue_pending_unlink(struct vhci_device *vdev, unlink->seqnum);list_del (&unlink->list); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return unlink; } } -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return NULL ; }
@@ -142,6 +144,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev, {struct vhci_unlink *unlink;struct urb *urb; +unsigned long flags;usbip_dump_header (pdu);
@@ -152,9 +155,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,return ; } -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags); urb =pickup_urb_and_free_priv (vdev, unlink->unlink_seqnum); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);if (!urb) {/*
@@ -171,9 +174,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev, urb->status = pdu->u.ret_unlink.status;pr_info ("urb->status %d\n" , urb->status); -spin_lock (&the_controller->lock); +spin_lock_irqsave (&the_controller->lock, flags);usb_hcd_unlink_urb_from_ep (vhci_to_hcd (the_controller), urb); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);usb_hcd_giveback_urb (vhci_to_hcd (the_controller), urb, urb->status);
@@ -185,10 +188,11 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,static int vhci_priv_tx_empty (struct vhci_device *vdev) {int empty =0 ; +unsigned long flags; -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags); empty =list_empty (&vdev->priv_rx); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return empty; }
drivers/usb/usbip/vhci_sysfs.c +11 -8
@@ -32,10 +32,11 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, {char *s = out;int i =0 ; +unsigned long flags;BUG_ON (!the_controller || !out); -spin_lock (&the_controller->lock); +spin_lock_irqsave (&the_controller->lock, flags);/* * output example:
@@ -73,7 +74,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,spin_unlock (&vdev->ud.lock); } -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);return out - s; }
@@ -83,11 +84,12 @@ static DEVICE_ATTR_RO(status);static int vhci_port_disconnect (__u32 rhport) {struct vhci_device *vdev; +unsigned long flags;usbip_dbg_vhci_sysfs ("enter\n" );/* lock */ -spin_lock (&the_controller->lock); +spin_lock_irqsave (&the_controller->lock, flags); vdev =port_to_vdev (rhport);
@@ -97,14 +99,14 @@ static int vhci_port_disconnect(__u32 rhport)/* unlock */ spin_unlock (&vdev->ud.lock); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);return -EINVAL ; }/* unlock */ spin_unlock (&vdev->ud.lock); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);usbip_event_add (&vdev->ud,VDEV_EVENT_DOWN );
@@ -180,6 +182,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,int sockfd =0 ;__u32 rhport =0 , devid =0 , speed =0 ;int err; +unsigned long flags;/* * @rhport: port number of vhci_hcd
@@ -205,14 +208,14 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,/* now need lock until setting vdev status as used */ /* begin a lock */ -spin_lock (&the_controller->lock); +spin_lock_irqsave (&the_controller->lock, flags); vdev =port_to_vdev (rhport);spin_lock (&vdev->ud.lock);if (vdev->ud.status !=VDEV_ST_NULL ) {/* end of the lock */ spin_unlock (&vdev->ud.lock); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);sockfd_put (socket);
@@ -231,7 +234,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, vdev->ud.status =VDEV_ST_NOTASSIGNED ;spin_unlock (&vdev->ud.lock); -spin_unlock (&the_controller->lock); +spin_unlock_irqrestore (&the_controller->lock, flags);/* end the lock */ vdev->ud.tcp_rx =kthread_get_run (vhci_rx_loop, &vdev->ud,"vhci_rx" );
drivers/usb/usbip/vhci_tx.c +8 -6
@@ -47,16 +47,17 @@ static void setup_cmd_submit_pdu(struct usbip_header *pdup, struct urb *urb)static struct vhci_priv *dequeue_from_priv_tx (struct vhci_device *vdev) {struct vhci_priv *priv, *tmp; +unsigned long flags; -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags);list_for_each_entry_safe (priv, tmp, &vdev->priv_tx, list) {list_move_tail (&priv->list, &vdev->priv_rx); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return priv; } -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return NULL ; }
@@ -136,16 +137,17 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev)static struct vhci_unlink *dequeue_from_unlink_tx (struct vhci_device *vdev) {struct vhci_unlink *unlink, *tmp; +unsigned long flags; -spin_lock (&vdev->priv_lock); +spin_lock_irqsave (&vdev->priv_lock, flags);list_for_each_entry_safe (unlink, tmp, &vdev->unlink_tx, list) {list_move_tail (&unlink->list, &vdev->unlink_rx); -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return unlink; } -spin_unlock (&vdev->priv_lock); +spin_unlock_irqrestore (&vdev->priv_lock, flags);return NULL ; }
PATCH 6/9 usbip: vhci_hcd: clear just the USB_PORT_STAT_POWER bit
In reply to Shuah KhanUpstream commit 1c9de5bf4286 ("usbip: vhci-hcd: Add USB3 SuperSpeed support")
vhci_hcd clears all the bits port_status bits instead of clearing just the USB_PORT_STAT_POWER bit when it handles ClearPortFeature:USB_PORT_FEAT_POWER. This causes vhci_hcd attach to fail in a bad state, leaving device unusable by the client. The device is still attached and however client can't use it.
The problem was fixed as part of larger change to add USB3 Super Speed support.
This patch isolates the one line fix to clear the USB_PORT_STAT_POWER from the original patch.
--- drivers/usb/usbip/vhci_hcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/usb/usbip/vhci_hcd.c +1 -1
@@ -279,7 +279,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,case USB_PORT_FEAT_POWER :usbip_dbg_vhci_rh (" ClearPortFeature: USB_PORT_FEAT_POWER\n" ); - dum->port_status[rhport] =0 ; + dum->port_status[rhport] &= ~USB_PORT_STAT_POWER ; dum->resuming =0 ;break ;case USB_PORT_FEAT_C_RESET :
PATCH 7/9 usbip: prevent leaking socket pointer address in messages
In reply to Shuah KhanUpstream commit 90120d15f4c3 ("usbip: prevent leaking socket pointer address in messages")
usbip driver is leaking socket pointer address in messages. Remove the messages that aren't useful and print sockfd in the ones that are useful for debugging.
--- drivers/usb/usbip/stub_dev.c | 3 +-- drivers/usb/usbip/usbip_common.c | 15 ++++----------- drivers/usb/usbip/vhci_hcd.c | 2 +- 3 files changed, 6 insertions(+), 14 deletions(-)
drivers/usb/usbip/stub_dev.c +1 -2
@@ -163,8 +163,7 @@ static void stub_shutdown_connection(struct usbip_device *ud)* step 1? */ if (ud->tcp_socket) { -dev_dbg (&sdev->udev->dev,"shutdown tcp_socket %p\n" , - ud->tcp_socket); +dev_dbg (&sdev->udev->dev,"shutdown sockfd %d\n" , ud->sockfd);kernel_sock_shutdown (ud->tcp_socket,SHUT_RDWR ); }
drivers/usb/usbip/usbip_common.c +4 -11
@@ -317,18 +317,14 @@ int usbip_recv(struct socket *sock, void *buf, int size)struct msghdr msg;struct kvec iov;int total =0 ; -/* for blocks of if (usbip_dbg_flag_xmit) */ char *bp = buf;int osize = size; -usbip_dbg_xmit ("enter\n" ); - -if (!sock || !buf || !size) { -pr_err ("invalid arg, sock %p buff %p size %d\n" , sock, buf, - size); +if (!sock || !buf || !size)return -EINVAL ; - } + +usbip_dbg_xmit ("enter\n" ); do { sock->sk->sk_allocation = GFP_NOIO;
@@ -341,11 +337,8 @@ int usbip_recv(struct socket *sock, void *buf, int size) msg.msg_flags =MSG_NOSIGNAL ; result =kernel_recvmsg (sock, &msg, &iov,1 , size,MSG_WAITALL ); -if (result <=0 ) { -pr_debug ("receive sock %p buf %p size %u ret %d total %d\n" , - sock, buf, size, result, total); +if (result <=0 ) goto err; - } size -= result; buf += result;
drivers/usb/usbip/vhci_hcd.c +1 -1
@@ -782,7 +782,7 @@ static void vhci_shutdown_connection(struct usbip_device *ud)/* need this? see stub_dev.c */ if (ud->tcp_socket) { -pr_debug ("shutdown tcp_socket %p\n" , ud->tcp_socket); +pr_debug ("shutdown sockfd %d\n" , ud->sockfd);kernel_sock_shutdown (ud->tcp_socket,SHUT_RDWR ); }
PATCH 8/9 usbip: stub: stop printing kernel pointer addresses in messages
In reply to Shuah KhanUpstream commit 248a22044366 ("usbip: stub: stop printing kernel pointer addresses in messages")
Remove and/or change debug, info. and error messages to not print kernel pointer addresses.
--- drivers/usb/usbip/stub_main.c | 5 +++-- drivers/usb/usbip/stub_rx.c | 7 ++----- drivers/usb/usbip/stub_tx.c | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-)
drivers/usb/usbip/stub_main.c +3 -2
@@ -252,11 +252,12 @@ void stub_device_cleanup_urbs(struct stub_device *sdev)struct stub_priv *priv;struct urb *urb; -dev_dbg (&sdev->udev->dev,"free sdev %p\n" , sdev); +dev_dbg (&sdev->udev->dev,"Stub device cleaning up urbs\n" );while ((priv =stub_priv_pop (sdev))) { urb = priv->urb; -dev_dbg (&sdev->udev->dev,"free urb %p\n" , urb); +dev_dbg (&sdev->udev->dev,"free urb seqnum %lu\n" , + priv->seqnum);usb_kill_urb (urb);kmem_cache_free (stub_priv_cache, priv);
drivers/usb/usbip/stub_rx.c +2 -5
@@ -230,9 +230,6 @@ static int stub_recv_cmd_unlink(struct stub_device *sdev,if (priv->seqnum != pdu->u.cmd_unlink.seqnum)continue ; -dev_info (&priv->urb->dev->dev,"unlink urb %p\n" , - priv->urb); -/* * This matched urb is not completed yet (i.e., be in * flight in usb hcd hardware/driver). Now we are
@@ -271,8 +268,8 @@ static int stub_recv_cmd_unlink(struct stub_device *sdev, ret =usb_unlink_urb (priv->urb);if (ret != -EINPROGRESS )dev_err (&priv->urb->dev->dev, -"failed to unlink a urb %p, ret %d\n" , - priv->urb, ret); +"failed to unlink a urb # %lu, ret %d\n" , + priv->seqnum, ret);return 0 ; }
drivers/usb/usbip/stub_tx.c +2 -2
@@ -201,8 +201,8 @@ static int stub_send_ret_submit(struct stub_device *sdev)/* 1. setup usbip_header */ setup_ret_submit_pdu (&pdu_header, urb); -usbip_dbg_stub_tx ("setup txdata seqnum: %d urb: %p\n" , - pdu_header.base.seqnum, urb); +usbip_dbg_stub_tx ("setup txdata seqnum: %d\n" , + pdu_header.base.seqnum);usbip_header_correct_endian (&pdu_header,1 ); iov[iovnum].iov_base = &pdu_header;
PATCH 9/9 usbip: vhci: stop printing kernel pointer addresses in messages
In reply to Shuah KhanUpstream commit 8272d099d05f ("usbip: vhci: stop printing kernel pointer addresses in messages")
Remove and/or change debug, info. and error messages to not print kernel pointer addresses.
--- drivers/usb/usbip/vhci_hcd.c | 10 ---------- drivers/usb/usbip/vhci_rx.c | 23 +++++++++++------------ drivers/usb/usbip/vhci_tx.c | 3 ++- 3 files changed, 13 insertions(+), 23 deletions(-)
drivers/usb/usbip/vhci_hcd.c +0 -10
@@ -469,9 +469,6 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,struct vhci_device *vdev;unsigned long flags; -usbip_dbg_vhci_hc ("enter, usb_hcd %p urb %p mem_flags %d\n" , - hcd, urb, mem_flags); -/* patch to usb_sg_init() is in 2.5.60 */ BUG_ON (!urb->transfer_buffer && urb->transfer_buffer_length);
@@ -630,8 +627,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)struct vhci_device *vdev;unsigned long flags; -pr_info ("dequeue a urb %p\n" , urb); -spin_lock_irqsave (&the_controller->lock, flags); priv = urb->hcpriv;
@@ -659,7 +654,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)/* tcp connection is closed */ spin_lock (&vdev->priv_lock); -pr_info ("device %p seems to be disconnected\n" , vdev);list_del (&priv->list);kfree (priv); urb->hcpriv =NULL ;
@@ -671,8 +665,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)* vhci_rx will receive RET_UNLINK and give back the URB. * Otherwise, we give back it here. */ -pr_info ("gives back urb %p\n" , urb); -usb_hcd_unlink_urb_from_ep (hcd, urb);spin_unlock_irqrestore (&the_controller->lock, flags);
@@ -701,8 +693,6 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) unlink->unlink_seqnum = priv->seqnum; -pr_info ("device %p seems to be still connected\n" , vdev); -/* send cmd_unlink and try to cancel the pending URB in the * peer */ list_add_tail (&unlink->list, &vdev->unlink_tx);
drivers/usb/usbip/vhci_rx.c +11 -12
@@ -37,24 +37,23 @@ struct urb *pickup_urb_and_free_priv(struct vhci_device *vdev, __u32 seqnum) urb = priv->urb; status = urb->status; -usbip_dbg_vhci_rx ("find urb %p vurb %p seqnum %u\n" , - urb, priv, seqnum); +usbip_dbg_vhci_rx ("find urb seqnum %u\n" , seqnum);switch (status) {case -ENOENT :/* fall through */ case -ECONNRESET : -dev_info (&urb->dev->dev, -"urb %p was unlinked %ssynchronuously.\n" , urb, - status == -ENOENT ?"" :"a" ); +dev_dbg (&urb->dev->dev, +"urb seq# %u was unlinked %ssynchronuously\n" , + seqnum, status == -ENOENT ?"" :"a" );break ;case -EINPROGRESS :/* no info output */ break ;default : -dev_info (&urb->dev->dev, -"urb %p may be in a error, status %d\n" , urb, - status); +dev_dbg (&urb->dev->dev, +"urb seq# %u may be in a error, status %d\n" , + seqnum, status); }list_del (&priv->list);
@@ -79,8 +78,8 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,spin_unlock_irqrestore (&vdev->priv_lock, flags);if (!urb) { -pr_err ("cannot find a urb of seqnum %u\n" , pdu->base.seqnum); -pr_info ("max seqnum %d\n" , +pr_err ("cannot find a urb of seqnum %u max seqnum %d\n" , + pdu->base.seqnum,atomic_read (&the_controller->seqnum));usbip_event_add (ud,VDEV_EVENT_ERROR_TCP );return ;
@@ -103,7 +102,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,if (usbip_dbg_flag_vhci_rx)usbip_dump_urb (urb); -usbip_dbg_vhci_rx ("now giveback urb %p\n" , urb); +usbip_dbg_vhci_rx ("now giveback urb %u\n" , pdu->base.seqnum);spin_lock_irqsave (&the_controller->lock, flags);usb_hcd_unlink_urb_from_ep (vhci_to_hcd (the_controller), urb);
@@ -168,7 +167,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,pr_info ("the urb (seqnum %d) was already given back\n" , pdu->base.seqnum); }else { -usbip_dbg_vhci_rx ("now giveback urb %p\n" , urb); +usbip_dbg_vhci_rx ("now giveback urb %d\n" , pdu->base.seqnum);/* If unlink is successful, status is -ECONNRESET */ urb->status = pdu->u.ret_unlink.status;
drivers/usb/usbip/vhci_tx.c +2 -1
@@ -83,7 +83,8 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev)memset (&msg,0 ,sizeof (msg));memset (&iov,0 ,sizeof (iov)); -usbip_dbg_vhci_tx ("setup txdata urb %p\n" , urb); +usbip_dbg_vhci_tx ("setup txdata urb seqnum %lu\n" , + priv->seqnum);/* 1. setup usbip_header */ setup_cmd_submit_pdu (&pdu_header, urb);
Greg KH
maintainerQuoted 7 lines · Shuah Khan
As I started backporting security fixes, found a few problems that prevent tools to build on newer gcc releases, deadlock bug, and another bug that prevents client from being able to use imported devices.
This patch series consists of security fixes and fixes to critical bugs.
All now applied, thanks!
greg k-h