Patch "usbip: Fix potential format overflow in userspace tools" has been added to the 3.18-stable tree
Subsystems (2)
This is a note to let you know that I've just added the patch titled
usbip: Fix potential format overflow in userspace tools
to the 3.18-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary
The filename of the patch is:
usbip-fix-potential-format-overflow-in-userspace-tools.patch
and it can be found in the queue-3.18 subdirectory.
If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.
Quoted 1 line
From
e5dfa3f902b9a642ae8c6997d57d7c41e384a90bMon Sep 17 00:00:00 2001
From: Jonathan Dieter <[email protected]>
Date: Mon, 27 Feb 2017 10:31:03 +0200
Subject: usbip: Fix potential format overflow in userspace tools
From: Jonathan Dieter <[email protected]>
commit e5dfa3f902b9a642ae8c6997d57d7c41e384a90b upstream.
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_ 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 usbi {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 usbi }/* 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));
Patches currently in stable-queue which might be from [email protected] are
queue-3.18/usbip-fix-potential-format-overflow-in-userspace-tools.patch