linux/drivers/usb
Nathan Chancellor a15e17acce usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video()
When building s390 allmodconfig after commit 9b91a65230 ("usb: gadget:
uvc: increase worker prio to WQ_HIGHPRI"), the following error occurs:

  In file included from ../include/linux/string.h:253,
                   from ../include/linux/bitmap.h:11,
                   from ../include/linux/cpumask.h:12,
                   from ../include/linux/smp.h:13,
                   from ../include/linux/lockdep.h:14,
                   from ../include/linux/rcupdate.h:29,
                   from ../include/linux/rculist.h:11,
                   from ../include/linux/pid.h:5,
                   from ../include/linux/sched.h:14,
                   from ../include/linux/ratelimit.h:6,
                   from ../include/linux/dev_printk.h:16,
                   from ../include/linux/device.h:15,
                   from ../drivers/usb/gadget/function/f_uvc.c:9:
  In function ‘fortify_memset_chk’,
      inlined from ‘uvc_register_video’ at ../drivers/usb/gadget/function/f_uvc.c:424:2:
  ../include/linux/fortify-string.h:301:25: error: call to ‘__write_overflow_field’ declared with attribute warning: detected write beyond size of field (1st parameter); maybe use struct_group()? [-Werror=attribute-warning]
    301 |                         __write_overflow_field(p_size_field, size);
        |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This points to the memset() in uvc_register_video(). It is clear that
the argument to sizeof() is incorrect, as uvc->vdev (a 'struct
video_device') is being zeroed out but the size of uvc->video (a 'struct
uvc_video') is being used as the third arugment to memset().

pahole shows that prior to commit 9b91a65230 ("usb: gadget: uvc:
increase worker prio to WQ_HIGHPRI"), 'struct video_device' and
'struct ucv_video' had the same size, meaning that the argument to
sizeof() is incorrect semantically but there is no visible issue:

  $ pahole -s build/drivers/usb/gadget/function/f_uvc.o | grep -E "(uvc_video|video_device)\s+"
  video_device    1400    4
  uvc_video       1400    3

After that change, uvc_video becomes slightly larger, meaning that the
memset() will overwrite by 8 bytes:

  $ pahole -s build/drivers/usb/gadget/function/f_uvc.o | grep -E "(uvc_video|video_device)\s+"
  video_device    1400    4
  uvc_video       1408    3

Fix the arugment to sizeof() so that there is no overwrite.

Cc: stable@vger.kernel.org
Fixes: e4ce9ed835 ("usb: gadget: uvc: ensure the vdev is unset")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20220928201921.3152163-1-nathan@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-09-30 13:58:51 +02:00
..
atm usb: move from strlcpy with unused retval to strscpy 2022-08-19 11:08:54 +02:00
c67x00 USB: c67x00: remove unnecessary check of res 2022-05-12 11:36:46 +02:00
cdns3 usb: cdns3: remove dead code 2022-09-27 10:36:36 +02:00
chipidea usb: chipidea: make configs for glue drivers visible with EXPERT 2022-09-08 13:32:50 +02:00
class usb: cdc-wdm: Use skb_put_data() instead of skb_put/memcpy pair 2022-09-27 10:36:33 +02:00
common usb: ulpi: use DEFINE_SHOW_ATTRIBUTE to simplify ulpi_regs 2022-09-27 10:36:54 +02:00
core usb: add quirks for Lenovo OneLink+ Dock 2022-09-30 13:54:23 +02:00
dwc2 usb: dwc2: Remove redundant license text 2022-09-22 15:52:29 +02:00
dwc3 Revert "usb: dwc3: Don't switch OTG -> peripheral if extcon is present" 2022-09-30 13:56:38 +02:00
early usb: early: xhci-dbc: Fix xdbc number parsing 2022-03-15 18:20:34 +01:00
gadget usb: gadget: uvc: Fix argument to sizeof() in uvc_register_video() 2022-09-30 13:58:51 +02:00
host usb: host: ehci-exynos: switch to using gpiod API 2022-09-30 13:57:10 +02:00
image usb/image: fix repeated words in comments 2022-07-27 14:33:53 +02:00
isp1760 usb: isp1760: Fix out-of-bounds array access 2022-05-19 18:10:59 +02:00
misc usb: idmouse: fix an uninit-value in idmouse_open 2022-09-27 10:37:09 +02:00
mon usb: mon: make mmapped memory read only 2022-09-22 15:52:29 +02:00
mtu3 usb: mtu3: fix failed runtime suspend in host only mode 2022-09-30 13:55:48 +02:00
musb usb: musb: sunxi: Switch to use dev_err_probe() helper 2022-09-27 10:36:07 +02:00
phy USB: PHY: JZ4770: Switch to use dev_err_probe() helper 2022-09-27 10:37:00 +02:00
renesas_usbhs usb: renesas: Fix refcount leak bug 2022-06-21 16:39:03 +02:00
roles
serial Merge 6.0-rc7 into usb-next 2022-09-26 10:38:21 +02:00
storage Revert "usb: storage: Add quirk for Samsung Fit flash" 2022-09-22 15:52:31 +02:00
typec usb: typec: ucsi_ccg: Disable UCSI ALT support on Tegra 2022-09-30 13:55:32 +02:00
usbip usbip: add USBIP_URB_* URB transfer flags 2022-08-31 09:07:53 +02:00
Kconfig usb: remove reference to deleted config STB03xxx 2021-08-18 15:32:19 +02:00
Makefile usb: host: remove line for obsolete config USB_HWA_HCD 2021-08-18 15:32:19 +02:00
usb-skeleton.c usb: usb-skeleton: Update min() to min_t() 2021-10-05 12:56:48 +02:00