1. 17 1月, 2023 1 次提交
  2. 22 11月, 2022 1 次提交
    • Z
      HID: core: fix shift-out-of-bounds in hid_report_raw_event · ec61b419
      ZhangPeng 提交于
      Syzbot reported shift-out-of-bounds in hid_report_raw_event.
      
      microsoft 0003:045E:07DA.0001: hid_field_extract() called with n (128) >
      32! (swapper/0)
      ======================================================================
      UBSAN: shift-out-of-bounds in drivers/hid/hid-core.c:1323:20
      shift exponent 127 is too large for 32-bit type 'int'
      CPU: 0 PID: 0 Comm: swapper/0 Not tainted
      6.1.0-rc4-syzkaller-00159-g4bbf3422 #0
      Hardware name: Google Compute Engine/Google Compute Engine, BIOS
      Google 10/26/2022
      Call Trace:
       <IRQ>
       __dump_stack lib/dump_stack.c:88 [inline]
       dump_stack_lvl+0x1e3/0x2cb lib/dump_stack.c:106
       ubsan_epilogue lib/ubsan.c:151 [inline]
       __ubsan_handle_shift_out_of_bounds+0x3a6/0x420 lib/ubsan.c:322
       snto32 drivers/hid/hid-core.c:1323 [inline]
       hid_input_fetch_field drivers/hid/hid-core.c:1572 [inline]
       hid_process_report drivers/hid/hid-core.c:1665 [inline]
       hid_report_raw_event+0xd56/0x18b0 drivers/hid/hid-core.c:1998
       hid_input_report+0x408/0x4f0 drivers/hid/hid-core.c:2066
       hid_irq_in+0x459/0x690 drivers/hid/usbhid/hid-core.c:284
       __usb_hcd_giveback_urb+0x369/0x530 drivers/usb/core/hcd.c:1671
       dummy_timer+0x86b/0x3110 drivers/usb/gadget/udc/dummy_hcd.c:1988
       call_timer_fn+0xf5/0x210 kernel/time/timer.c:1474
       expire_timers kernel/time/timer.c:1519 [inline]
       __run_timers+0x76a/0x980 kernel/time/timer.c:1790
       run_timer_softirq+0x63/0xf0 kernel/time/timer.c:1803
       __do_softirq+0x277/0x75b kernel/softirq.c:571
       __irq_exit_rcu+0xec/0x170 kernel/softirq.c:650
       irq_exit_rcu+0x5/0x20 kernel/softirq.c:662
       sysvec_apic_timer_interrupt+0x91/0xb0 arch/x86/kernel/apic/apic.c:1107
      ======================================================================
      
      If the size of the integer (unsigned n) is bigger than 32 in snto32(),
      shift exponent will be too large for 32-bit type 'int', resulting in a
      shift-out-of-bounds bug.
      Fix this by adding a check on the size of the integer (unsigned n) in
      snto32(). To add support for n greater than 32 bits, set n to 32, if n
      is greater than 32.
      
      Reported-by: syzbot+8b1641d2f14732407e23@syzkaller.appspotmail.com
      Fixes: dde5845a ("[PATCH] Generic HID layer - code split")
      Signed-off-by: NZhangPeng <zhangpeng362@huawei.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      ec61b419
  3. 20 9月, 2022 3 次提交
  4. 08 9月, 2022 1 次提交
  5. 21 7月, 2022 1 次提交
  6. 11 5月, 2022 1 次提交
  7. 01 3月, 2022 5 次提交
  8. 02 12月, 2021 2 次提交
  9. 21 7月, 2021 1 次提交
    • U
      bus: Make remove callback return void · fc7a6209
      Uwe Kleine-König 提交于
      The driver core ignores the return value of this callback because there
      is only little it can do when a device disappears.
      
      This is the final bit of a long lasting cleanup quest where several
      buses were converted to also return void from their remove callback.
      Additionally some resource leaks were fixed that were caused by drivers
      returning an error code in the expectation that the driver won't go
      away.
      
      With struct bus_type::remove returning void it's prevented that newly
      implemented buses return an ignored error code and so don't anticipate
      wrong expectations for driver authors.
      
      Reviewed-by: Tom Rix <trix@redhat.com> (For fpga)
      Reviewed-by: NMathieu Poirier <mathieu.poirier@linaro.org>
      Reviewed-by: Cornelia Huck <cohuck@redhat.com> (For drivers/s390 and drivers/vfio)
      Acked-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> (For ARM, Amba and related parts)
      Acked-by: NMark Brown <broonie@kernel.org>
      Acked-by: Chen-Yu Tsai <wens@csie.org> (for sunxi-rsb)
      Acked-by: NPali Rohár <pali@kernel.org>
      Acked-by: Mauro Carvalho Chehab <mchehab@kernel.org> (for media)
      Acked-by: Hans de Goede <hdegoede@redhat.com> (For drivers/platform)
      Acked-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
      Acked-By: NVinod Koul <vkoul@kernel.org>
      Acked-by: Juergen Gross <jgross@suse.com> (For xen)
      Acked-by: Lee Jones <lee.jones@linaro.org> (For mfd)
      Acked-by: Johannes Thumshirn <jth@kernel.org> (For mcb)
      Acked-by: NJohan Hovold <johan@kernel.org>
      Acked-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org> (For slimbus)
      Acked-by: Kirti Wankhede <kwankhede@nvidia.com> (For vfio)
      Acked-by: NMaximilian Luz <luzmaximilian@gmail.com>
      Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> (For ulpi and typec)
      Acked-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> (For ipack)
      Acked-by: Geoff Levand <geoff@infradead.org> (For ps3)
      Acked-by: Yehezkel Bernat <YehezkelShB@gmail.com> (For thunderbolt)
      Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com> (For intel_th)
      Acked-by: Dominik Brodowski <linux@dominikbrodowski.net> (For pcmcia)
      Acked-by: Rafael J. Wysocki <rafael@kernel.org> (For ACPI)
      Acked-by: Bjorn Andersson <bjorn.andersson@linaro.org> (rpmsg and apr)
      Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> (For intel-ish-hid)
      Acked-by: Dan Williams <dan.j.williams@intel.com> (For CXL, DAX, and NVDIMM)
      Acked-by: William Breathitt Gray <vilhelm.gray@gmail.com> (For isa)
      Acked-by: Stefan Richter <stefanr@s5r6.in-berlin.de> (For firewire)
      Acked-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> (For hid)
      Acked-by: Thorsten Scherer <t.scherer@eckelmann.de> (For siox)
      Acked-by: Sven Van Asbroeck <TheSven73@gmail.com> (For anybuss)
      Acked-by: Ulf Hansson <ulf.hansson@linaro.org> (For MMC)
      Acked-by: Wolfram Sang <wsa@kernel.org> # for I2C
      Acked-by: NSudeep Holla <sudeep.holla@arm.com>
      Acked-by: NGeert Uytterhoeven <geert@linux-m68k.org>
      Acked-by: NDmitry Torokhov <dmitry.torokhov@gmail.com>
      Acked-by: NFinn Thain <fthain@linux-m68k.org>
      Signed-off-by: NUwe Kleine-König <u.kleine-koenig@pengutronix.de>
      Link: https://lore.kernel.org/r/20210713193522.1770306-6-u.kleine-koenig@pengutronix.deSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fc7a6209
  10. 27 5月, 2021 1 次提交
  11. 05 5月, 2021 2 次提交
  12. 08 4月, 2021 1 次提交
  13. 18 1月, 2021 1 次提交
    • W
      HID: make arrays usage and value to be the same · ed9be64e
      Will McVicker 提交于
      The HID subsystem allows an "HID report field" to have a different
      number of "values" and "usages" when it is allocated. When a field
      struct is created, the size of the usage array is guaranteed to be at
      least as large as the values array, but it may be larger. This leads to
      a potential out-of-bounds write in
      __hidinput_change_resolution_multipliers() and an out-of-bounds read in
      hidinput_count_leds().
      
      To fix this, let's make sure that both the usage and value arrays are
      the same size.
      
      Cc: stable@vger.kernel.org
      Signed-off-by: NWill McVicker <willmcvicker@google.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      ed9be64e
  14. 08 1月, 2021 1 次提交
    • R
      HID: core: detect and skip invalid inputs to snto32() · a0312af1
      Randy Dunlap 提交于
      Prevent invalid (0, 0) inputs to hid-core's snto32() function.
      
      Maybe it is just the dummy device here that is causing this, but
      there are hundreds of calls to snto32(0, 0). Having n (bits count)
      of 0 is causing the current UBSAN trap with a shift value of
      0xffffffff (-1, or n - 1 in this function).
      
      Either of the value to shift being 0 or the bits count being 0 can be
      handled by just returning 0 to the caller, avoiding the following
      complex shift + OR operations:
      
      	return value & (1 << (n - 1)) ? value | (~0U << n) : value;
      
      Fixes: dde5845a ("[PATCH] Generic HID layer - code split")
      Signed-off-by: NRandy Dunlap <rdunlap@infradead.org>
      Reported-by: syzbot+1e911ad71dd4ea72e04a@syzkaller.appspotmail.com
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
      Cc: linux-input@vger.kernel.org
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      a0312af1
  15. 01 10月, 2020 1 次提交
  16. 23 9月, 2020 1 次提交
    • X
      HID: core: fix kerneldoc warnings in hid-core.c · 5f94e9c8
      Xiaofei Tan 提交于
      Fix following warnings caused by mismatch bewteen function parameters
      and comments.
      drivers/hid/hid-core.c:931: warning: Function parameter or member 'hid' not described in 'hid_parse_report'
      drivers/hid/hid-core.c:931: warning: Excess function parameter 'device' description in 'hid_parse_report'
      drivers/hid/hid-core.c:961: warning: Function parameter or member 'hid' not described in 'hid_validate_values'
      drivers/hid/hid-core.c:961: warning: Excess function parameter 'device' description in 'hid_validate_values'
      drivers/hid/hid-core.c:1452: warning: Function parameter or member 'report' not described in 'hid_match_report'
      drivers/hid/hid-core.c:1452: warning: Excess function parameter 'report_type' description in 'hid_match_report'
      drivers/hid/hid-core.c:2132: warning: Function parameter or member 'drv' not described in 'new_id_store'
      drivers/hid/hid-core.c:2132: warning: Excess function parameter 'driver' description in 'new_id_store'
      Signed-off-by: NXiaofei Tan <tanxiaofei@huawei.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      5f94e9c8
  17. 01 9月, 2020 1 次提交
  18. 12 2月, 2020 1 次提交
    • J
      HID: core: fix off-by-one memset in hid_report_raw_event() · 5ebdffd2
      Johan Korsnes 提交于
      In case a report is greater than HID_MAX_BUFFER_SIZE, it is truncated,
      but the report-number byte is not correctly handled. This results in a
      off-by-one in the following memset, causing a kernel Oops and ensuing
      system crash.
      
      Note: With commit 8ec321e9 ("HID: Fix slab-out-of-bounds read in
      hid_field_extract") I no longer hit the kernel Oops as we instead fail
      "controlled" at probe if there is a report too long in the HID
      report-descriptor. hid_report_raw_event() is an exported symbol, so
      presumabely we cannot always rely on this being the case.
      
      Fixes: 966922f2 ("HID: fix a crash in hid_report_raw_event()
                           function.")
      Signed-off-by: NJohan Korsnes <jkorsnes@cisco.com>
      Cc: Armando Visconti <armando.visconti@st.com>
      Cc: Jiri Kosina <jkosina@suse.cz>
      Cc: Alan Stern <stern@rowland.harvard.edu>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      5ebdffd2
  19. 11 12月, 2019 1 次提交
    • A
      HID: Fix slab-out-of-bounds read in hid_field_extract · 8ec321e9
      Alan Stern 提交于
      The syzbot fuzzer found a slab-out-of-bounds bug in the HID report
      handler.  The bug was caused by a report descriptor which included a
      field with size 12 bits and count 4899, for a total size of 7349
      bytes.
      
      The usbhid driver uses at most a single-page 4-KB buffer for reports.
      In the test there wasn't any problem about overflowing the buffer,
      since only one byte was received from the device.  Rather, the bug
      occurred when the HID core tried to extract the data from the report
      fields, which caused it to try reading data beyond the end of the
      allocated buffer.
      
      This patch fixes the problem by rejecting any report whose total
      length exceeds the HID_MAX_BUFFER_SIZE limit (minus one byte to allow
      for a possible report index).  In theory a device could have a report
      longer than that, but if there was such a thing we wouldn't handle it
      correctly anyway.
      
      Reported-and-tested-by: syzbot+09ef48aa58261464b621@syzkaller.appspotmail.com
      Signed-off-by: NAlan Stern <stern@rowland.harvard.edu>
      CC: <stable@vger.kernel.org>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      8ec321e9
  20. 18 11月, 2019 1 次提交
    • B
      HID: Improve Windows Precision Touchpad detection. · 2dbc6f11
      Blaž Hrastnik 提交于
      Per Microsoft spec, usage 0xC5 (page 0xFF) returns a blob containing
      data used to verify the touchpad as a Windows Precision Touchpad.
      
         0x85, REPORTID_PTPHQA,    //    REPORT_ID (PTPHQA)
          0x09, 0xC5,              //    USAGE (Vendor Usage 0xC5)
          0x15, 0x00,              //    LOGICAL_MINIMUM (0)
          0x26, 0xff, 0x00,        //    LOGICAL_MAXIMUM (0xff)
          0x75, 0x08,              //    REPORT_SIZE (8)
          0x96, 0x00, 0x01,        //    REPORT_COUNT (0x100 (256))
          0xb1, 0x02,              //    FEATURE (Data,Var,Abs)
      
      However, some devices, namely Microsoft's Surface line of products
      instead implement a "segmented device certification report" (usage 0xC6)
      which returns the same report, but in smaller chunks.
      
          0x06, 0x00, 0xff,        //     USAGE_PAGE (Vendor Defined)
          0x85, REPORTID_PTPHQA,   //     REPORT_ID (PTPHQA)
          0x09, 0xC6,              //     USAGE (Vendor usage for segment #)
          0x25, 0x08,              //     LOGICAL_MAXIMUM (8)
          0x75, 0x08,              //     REPORT_SIZE (8)
          0x95, 0x01,              //     REPORT_COUNT (1)
          0xb1, 0x02,              //     FEATURE (Data,Var,Abs)
          0x09, 0xC7,              //     USAGE (Vendor Usage)
          0x26, 0xff, 0x00,        //     LOGICAL_MAXIMUM (0xff)
          0x95, 0x20,              //     REPORT_COUNT (32)
          0xb1, 0x02,              //     FEATURE (Data,Var,Abs)
      
      By expanding Win8 touchpad detection to also look for the segmented
      report, all Surface touchpads are now properly recognized by
      hid-multitouch.
      Signed-off-by: NBlaž Hrastnik <blaz@mxxn.io>
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      2dbc6f11
  21. 12 11月, 2019 1 次提交
    • C
      HID: core: check whether Usage Page item is after Usage ID items · 1cb0d2ae
      Candle Sun 提交于
      Upstream commit 58e75155 ("HID: core: move Usage Page concatenation
      to Main item") adds support for Usage Page item after Usage ID items
      (such as keyboards manufactured by Primax).
      
      Usage Page concatenation in Main item works well for following report
      descriptor patterns:
      
          USAGE_PAGE (Keyboard)                   05 07
          USAGE_MINIMUM (Keyboard LeftControl)    19 E0
          USAGE_MAXIMUM (Keyboard Right GUI)      29 E7
          LOGICAL_MINIMUM (0)                     15 00
          LOGICAL_MAXIMUM (1)                     25 01
          REPORT_SIZE (1)                         75 01
          REPORT_COUNT (8)                        95 08
          INPUT (Data,Var,Abs)                    81 02
      
      -------------
      
          USAGE_MINIMUM (Keyboard LeftControl)    19 E0
          USAGE_MAXIMUM (Keyboard Right GUI)      29 E7
          LOGICAL_MINIMUM (0)                     15 00
          LOGICAL_MAXIMUM (1)                     25 01
          REPORT_SIZE (1)                         75 01
          REPORT_COUNT (8)                        95 08
          USAGE_PAGE (Keyboard)                   05 07
          INPUT (Data,Var,Abs)                    81 02
      
      But it makes the parser act wrong for the following report
      descriptor pattern(such as some Gamepads):
      
          USAGE_PAGE (Button)                     05 09
          USAGE (Button 1)                        09 01
          USAGE (Button 2)                        09 02
          USAGE (Button 4)                        09 04
          USAGE (Button 5)                        09 05
          USAGE (Button 7)                        09 07
          USAGE (Button 8)                        09 08
          USAGE (Button 14)                       09 0E
          USAGE (Button 15)                       09 0F
          USAGE (Button 13)                       09 0D
          USAGE_PAGE (Consumer Devices)           05 0C
          USAGE (Back)                            0a 24 02
          USAGE (HomePage)                        0a 23 02
          LOGICAL_MINIMUM (0)                     15 00
          LOGICAL_MAXIMUM (1)                     25 01
          REPORT_SIZE (1)                         75 01
          REPORT_COUNT (11)                       95 0B
          INPUT (Data,Var,Abs)                    81 02
      
      With Usage Page concatenation in Main item, parser recognizes all the
      11 Usages as consumer keys, it is not the HID device's real intention.
      
      This patch checks whether Usage Page is really defined after Usage ID
      items by comparing usage page using status.
      
      Usage Page concatenation on currently defined Usage Page will always
      do in local parsing when Usage ID items encountered.
      
      When Main item is parsing, concatenation will do again with last
      defined Usage Page if this page has not been used in the previous
      usages concatenation.
      Signed-off-by: NCandle Sun <candle.sun@unisoc.com>
      Signed-off-by: NNianfu Bai <nianfu.bai@unisoc.com>
      Benjamin Tissoires <benjamin.tissoires@redhat.com>
      Signed-off-by: NJiri Kosina <jkosina@suse.cz>
      1cb0d2ae
  22. 01 10月, 2019 1 次提交
  23. 18 9月, 2019 1 次提交
    • J
      HID: core: fix dmesg flooding if report field larger than 32bit · 0af10eed
      Joshua Clayton 提交于
      Only warn once of oversize hid report value field
      
      On HP spectre x360 convertible the message:
      hid-sensor-hub 001F:8087:0AC2.0002: hid_field_extract() called with n (192) > 32! (kworker/1:2)
      is continually printed many times per second, crowding out all else.
      Protect dmesg by printing the warning only one time.
      
      The size of the hid report field data structure should probably be increased.
      The data structure is treated as a u32 in Linux, but an unlimited number
      of bits in the USB hid spec, so there is some rearchitecture needed now that
      devices are sending more than 32 bits.
      Signed-off-by: NJoshua Clayton <stillcompiling@gmail.com>
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      0af10eed
  24. 05 6月, 2019 3 次提交
  25. 31 5月, 2019 1 次提交
  26. 24 4月, 2019 1 次提交
  27. 05 4月, 2019 1 次提交
    • H
      HID: core: Do not call request_module() in async context · 4ceabaf7
      Hans de Goede 提交于
      request_module() may not be called form async context and in some cases
      hid devices may be added from an async context. One example of this
      happening is under hyperv, where this was triggering a WARN_ON in
      request_module():
      
      [   11.174497]  hid_add_device+0xee/0x2b0 [hid]
      [   11.174499]  mousevsc_probe+0x223/0x2eb [hid_hyperv]
      [   11.174501]  vmbus_probe+0x3a/0x90
      [   11.174504]  really_probe+0x229/0x420
      [   11.174506]  driver_probe_device+0x115/0x130
      [   11.174507]  __driver_attach_async_helper+0x87/0x90
      [   11.174509]  async_run_entry_fn+0x37/0x150
      
      This commit skips the request_module(), falling back to the old behavior
      of letting userspace deal with this, in case we are called from an async
      context.
      
      Cc: Lili Deng <v-lide@microsoft.com>
      Reported-by: NLili Deng <v-lide@microsoft.com>
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      4ceabaf7
  28. 02 4月, 2019 2 次提交
    • H
      HID: core: Call request_module before doing device_add · a025a18f
      Hans de Goede 提交于
      Recent kernels allow the generic-hid driver to be used as fallback for
      devices with a specialized driver, when the hiddev is not listed in
      hid_have_special_driver. Over time we are removing more and more
      devices from the hid_have_special_driver table as devices get tested
      to support this setup.
      
      Before this commit the following happens when a HID device which has a
      special-driver and is no longer listed in hid_have_special_driver, gets
      enumerated:
      
      1) device_add() gets called
      2) bus_add_device() looks for a matching already registered hid driver,
         and bind hid-generic to the new device
      3) kobject_uevent(&dev->kobj, KOBJ_ADD) gets called notifying userspace of
         the new hid_dev. udev calls modprobe based on the modalias in the uevent
      4) The special driver gets loaded by modprobe
      5) __hid_bus_reprobe_drivers() unbinds hid-generic and binds the new driver
      
      There are a couple of downsides to this:
      
      a) The probing messages printend when a HID driver bounds show up twice in
      dmesg, which is confusing for the user
      
      b) The (un)binding typically causes one or more evdev device-nodes to get
      (un)registered firing of udev events to which e.g. the xserver responds by
      (un)registering xinput devices and reporting this to interested clients.
      IOW the i. bind generic, ii. unbind generic, iii. bind special driver dance
      sets in motion a whole chain of events each step, while we really only want
      the events from step iii. to be reported to userspace.
      
      This commits introduces a request_module call before the device_add()
      call, so that the special-driver is loaded when step 2) looks for a
      matching driver and we directly bind the specialized driver.
      
      Note the request_module call translates to an execve("/sbin/modprobe", ...)
      and we now do this for each HID device added. So this is not entirely free,
      but adding HID devices is not something which happens 100s of times a
      second, so this should be fine.
      Signed-off-by: NHans de Goede <hdegoede@redhat.com>
      [bentiss: fixed typo in commit message found by checkpatch.pl]
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      a025a18f
    • N
      HID: core: move Usage Page concatenation to Main item · 58e75155
      Nicolas Saenz Julienne 提交于
      As seen on some USB wireless keyboards manufactured by Primax, the HID
      parser was using some assumptions that are not always true. In this case
      it's s the fact that, inside the scope of a main item, an Usage Page
      will always precede an Usage.
      
      The spec is not pretty clear as 6.2.2.7 states "Any usage that follows
      is interpreted as a Usage ID and concatenated with the Usage Page".
      While 6.2.2.8 states "When the parser encounters a main item it
      concatenates the last declared Usage Page with a Usage to form a
      complete usage value." Being somewhat contradictory it was decided to
      match Window's implementation, which follows 6.2.2.8.
      
      In summary, the patch moves the Usage Page concatenation from the local
      item parsing function to the main item parsing function.
      Signed-off-by: NNicolas Saenz Julienne <nsaenzjulienne@suse.de>
      Reviewed-by: NTerry Junge <terry.junge@poly.com>
      Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@redhat.com>
      58e75155
  29. 18 3月, 2019 1 次提交