From 3c35987b0584b3a83bdd752b709fbfd1cda59a72 Mon Sep 17 00:00:00 2001 From: Salvatore Bonaccorso Date: Thu, 30 Jun 2016 14:49:56 +0200 Subject: [PATCH] HID: hiddev: validate num_values for HIDIOCGUSAGES, HIDIOCSUSAGES commands (CVE-2016-5829) --- debian/changelog | 5 +++ ...ate-num_values-for-HIDIOCGUSAGES-HID.patch | 44 +++++++++++++++++++ debian/patches/series | 1 + 3 files changed, 50 insertions(+) create mode 100644 debian/patches/bugfix/all/HID-hiddev-validate-num_values-for-HIDIOCGUSAGES-HID.patch diff --git a/debian/changelog b/debian/changelog index 323cb730a..126691b55 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ linux (4.6.3-1) UNRELEASED; urgency=medium + [ Ben Hutchings ] * New upstream stable update: https://www.kernel.org/pub/linux/kernel/v4.x/ChangeLog-4.6.3 - scsi_lib: correctly retry failed zero length REQ_TYPE_FS commands @@ -67,6 +68,10 @@ linux (4.6.3-1) UNRELEASED; urgency=medium - [x86] Revert "drm/i915: Exit cherryview_irq_handler() after one pass" - gpio: make sure gpiod_to_irq() returns negative on NULL desc + [ Salvatore Bonaccorso ] + * HID: hiddev: validate num_values for HIDIOCGUSAGES, HIDIOCSUSAGES commands + (CVE-2016-5829) + -- Ben Hutchings Mon, 27 Jun 2016 00:31:11 +0200 linux (4.6.2-2) unstable; urgency=medium diff --git a/debian/patches/bugfix/all/HID-hiddev-validate-num_values-for-HIDIOCGUSAGES-HID.patch b/debian/patches/bugfix/all/HID-hiddev-validate-num_values-for-HIDIOCGUSAGES-HID.patch new file mode 100644 index 000000000..e5e4cece4 --- /dev/null +++ b/debian/patches/bugfix/all/HID-hiddev-validate-num_values-for-HIDIOCGUSAGES-HID.patch @@ -0,0 +1,44 @@ +From: Scott Bauer +Date: Thu, 23 Jun 2016 08:59:47 -0600 +Subject: HID: hiddev: validate num_values for HIDIOCGUSAGES, HIDIOCSUSAGES + commands +Origin: https://git.kernel.org/linus/93a2001bdfd5376c3dc2158653034c20392d15c5 + +This patch validates the num_values parameter from userland during the +HIDIOCGUSAGES and HIDIOCSUSAGES commands. Previously, if the report id was set +to HID_REPORT_ID_UNKNOWN, we would fail to validate the num_values parameter +leading to a heap overflow. + +Cc: stable@vger.kernel.org +Signed-off-by: Scott Bauer +Signed-off-by: Jiri Kosina +--- + drivers/hid/usbhid/hiddev.c | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c +index 2f1ddca..700145b 100644 +--- a/drivers/hid/usbhid/hiddev.c ++++ b/drivers/hid/usbhid/hiddev.c +@@ -516,13 +516,13 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd, + goto inval; + } else if (uref->usage_index >= field->report_count) + goto inval; +- +- else if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) && +- (uref_multi->num_values > HID_MAX_MULTI_USAGES || +- uref->usage_index + uref_multi->num_values > field->report_count)) +- goto inval; + } + ++ if ((cmd == HIDIOCGUSAGES || cmd == HIDIOCSUSAGES) && ++ (uref_multi->num_values > HID_MAX_MULTI_USAGES || ++ uref->usage_index + uref_multi->num_values > field->report_count)) ++ goto inval; ++ + switch (cmd) { + case HIDIOCGUSAGE: + uref->value = field->value[uref->usage_index]; +-- +2.8.1 + diff --git a/debian/patches/series b/debian/patches/series index 7315a6291..50cedefad 100644 --- a/debian/patches/series +++ b/debian/patches/series @@ -113,6 +113,7 @@ bugfix/all/percpu-fix-synchronization-between-chunk-map_extend_.patch bugfix/all/percpu-fix-synchronization-between-synchronous-map-e.patch bugfix/all/posix_acl-add-set_posix_acl.patch bugfix/all/nfsd-check-permissions-when-setting-acls.patch +bugfix/all/HID-hiddev-validate-num_values-for-HIDIOCGUSAGES-HID.patch # ABI maintenance debian/mips-siginfo-fix-abi-change-in-4.6.2.patch