# HG changeset patch # User Stanislas Leduc # Date 1685029766 0 # Node ID a58264a81dff6f07b6151b7e88e12cd02b05c629 # Parent 4b92affc463d03ce10c707f6940c47256cd5d64c Fix linux build with gcc > 6 diff -r 4b92affc463d -r a58264a81dff linux/receipt --- a/linux/receipt Thu May 25 10:56:33 2023 +0000 +++ b/linux/receipt Thu May 25 15:49:26 2023 +0000 @@ -234,7 +234,10 @@ aufs3-loopback.patch aufs3-mmap.patch EOT - + + # Patch for GCC > 6.x + patch -p1 < $stuff/linux-with-gcc8.patch + # Mrproper and lguest echo "Make kernel proper and then build lguest..." make mrproper diff -r 4b92affc463d -r a58264a81dff linux/stuff/linux-with-gcc8.patch --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linux/stuff/linux-with-gcc8.patch Thu May 25 15:49:26 2023 +0000 @@ -0,0 +1,101 @@ +Upstream 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(). + +Reviewed-by: Peter Senna Tschudin +Signed-off-by: Jonathan Dieter +Acked-by: Shuah Khan +Signed-off-by: Greg Kroah-Hartman +Signed-off-by: Shuah Khan + +diff --git a/tools/usb/usbip/libsrc/usbip_common.c b/tools/usb/usbip/libsrc/usbip_common.c +index ac73710..01dd4b2 100644 +--- a/drivers/staging/usbip/userspace/libsrc/usbip_common.c ++++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.c +@@ -215,9 +215,15 @@ + struct usbip_usb_interface *uinf) + { + char busid[SYSFS_BUS_ID_SIZE]; ++ unsigned 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 >= sizeof(busid)) { ++ err("busid length %u >= %lu", size, sizeof(busid)); ++ return -1; ++ } + + sif = udev_device_new_from_subsystem_sysname(udev_context, "usb", busid); + if (!sif) { +diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c +b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c +index 9d415228883d..c10379439668 100644 +--- a/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c ++++ b/drivers/staging/usbip/userspace/libsrc/usbip_host_driver.c +@@ -39,13 +39,19 @@ + static int32_t read_attr_usbip_status(struct usbip_usb_device *udev) + { + char status_attr_path[SYSFS_PATH_MAX]; ++ unsigned 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, sizeof(status_attr_path), ++ "%s/usbip_status", udev->path); ++ if (size >= sizeof(status_attr_path)) { ++ err("usbip_status path length %u >= %lu", size, ++ sizeof(status_attr_path)); ++ return -1; ++ } + + if ((fd = open(status_attr_path, O_RDONLY)) < 0) { + err("error opening attribute %s", status_attr_path); +@@ -224,6 +230,7 @@ + { + char attr_name[] = "usbip_sockfd"; + char sockfd_attr_path[SYSFS_PATH_MAX]; ++ unsigned int size; + char sockfd_buff[30]; + int ret; + +@@ -243,10 +250,19 @@ + } + + /* only the first interface is true */ +- snprintf(sockfd_attr_path, sizeof(sockfd_attr_path), "%s/%s", ++ size = snprintf(sockfd_attr_path, sizeof(sockfd_attr_path), "%s/%s", + edev->udev.path, attr_name); ++ if (size >= sizeof(sockfd_attr_path)) { ++ err("exported device path length %u >= %lu", size, ++ 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 >= sizeof(sockfd_buff)) { ++ err("socket length %u >= %lu", size, sizeof(sockfd_buff)); ++ return -1; ++ } + + ret = write_sysfs_attribute(sockfd_attr_path, sockfd_buff, + strlen(sockfd_buff)); +-- +2.14.1