linux-brain/drivers/media/pci
Gustavo A. R. Silva e617fa62f6 media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf()
commit 8d4abca95ecc82fc8c41912fa0085281f19cc29f upstream.

Fix an 11-year old bug in ngene_command_config_free_buf() while
addressing the following warnings caught with -Warray-bounds:

arch/alpha/include/asm/string.h:22:16: warning: '__builtin_memcpy' offset [12, 16] from the object at 'com' is out of the bounds of referenced subobject 'config' with type 'unsigned char' at offset 10 [-Warray-bounds]
arch/x86/include/asm/string_32.h:182:25: warning: '__builtin_memcpy' offset [12, 16] from the object at 'com' is out of the bounds of referenced subobject 'config' with type 'unsigned char' at offset 10 [-Warray-bounds]

The problem is that the original code is trying to copy 6 bytes of
data into a one-byte size member _config_ of the wrong structue
FW_CONFIGURE_BUFFERS, in a single call to memcpy(). This causes a
legitimate compiler warning because memcpy() overruns the length
of &com.cmd.ConfigureBuffers.config. It seems that the right
structure is FW_CONFIGURE_FREE_BUFFERS, instead, because it contains
6 more members apart from the header _hdr_. Also, the name of
the function ngene_command_config_free_buf() suggests that the actual
intention is to ConfigureFreeBuffers, instead of ConfigureBuffers
(which takes place in the function ngene_command_config_buf(), above).

Fix this by enclosing those 6 members of struct FW_CONFIGURE_FREE_BUFFERS
into new struct config, and use &com.cmd.ConfigureFreeBuffers.config as
the destination address, instead of &com.cmd.ConfigureBuffers.config,
when calling memcpy().

This also helps with the ongoing efforts to globally enable
-Warray-bounds and get us closer to being able to tighten the
FORTIFY_SOURCE routines on memcpy().

Link: https://github.com/KSPP/linux/issues/109
Fixes: dae52d009f ("V4L/DVB: ngene: Initial check-in")
Cc: stable@vger.kernel.org
Reported-by: kernel test robot <lkp@intel.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Link: https://lore.kernel.org/linux-hardening/20210420001631.GA45456@embeddedor/
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-28 13:31:00 +02:00
..
b2c2 treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
bt8xx media: subdev: disallow ioctl for saa6588/davinci 2021-07-19 08:53:17 +02:00
cobalt media: cobalt: fix race condition in setting HPD 2021-07-14 16:53:11 +02:00
cx18 media: don't do a 31 bit shift on a signed int 2019-08-26 14:11:10 -03:00
cx88 media: cx88: Fix some error handling path in 'cx8800_initdev()' 2019-12-31 16:43:55 +01:00
cx23885 media: cx23885: add more quirks for reset DMA on some AMD IOMMU 2021-03-11 14:06:50 +01:00
cx25821 media: cx25821: Fix a bug when reallocating some dma memory 2021-03-04 10:26:22 +01:00
ddbridge Linux 5.2-rc2 2019-05-28 11:21:51 -04:00
dm1105 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
dt3155 media: media/pci: don't set description for ENUM_FMT 2019-07-22 14:40:32 -04:00
intel media: ipu3-cio2: Fix mbus_code processing in cio2_subdev_set_fmt() 2021-03-04 10:26:46 +01:00
ivtv media: don't do a 31 bit shift on a signed int 2019-08-26 14:11:10 -03:00
mantis media: use the BIT() macro 2019-08-26 14:08:50 -03:00
meye media: media/pci: don't set description for ENUM_FMT 2019-07-22 14:40:32 -04:00
netup_unidvb media: netup_unidvb: Don't leak SPI master in probe error path 2020-12-30 11:51:31 +01:00
ngene media: ngene: Fix out-of-bounds bug in ngene_command_config_free_buf() 2021-07-28 13:31:00 +02:00
pluto2 treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 157 2019-05-30 11:26:37 -07:00
pt1 media: pci: Use dev_get_drvdata where possible 2019-07-25 06:45:10 -04:00
pt3 media: pci: Use dev_get_drvdata where possible 2019-07-25 06:45:10 -04:00
saa7134 media: subdev: disallow ioctl for saa6588/davinci 2021-07-19 08:53:17 +02:00
saa7146 media: saa7146: fix array overflow in vidioc_s_audio() 2020-12-30 11:51:17 +01:00
saa7164 media: media/saa7164: fix saa7164_encoder_register() memory leak bugs 2021-05-11 14:04:09 +02:00
smipcie media: smipcie: fix interrupt handling and IR timeout 2021-03-04 10:26:49 +01:00
solo6x10 media: solo6x10: fix missing snd_card_free in error handling case 2020-12-30 11:51:08 +01:00
sta2x11 media: drivers: media: pci: sta2x11: fix Kconfig dependency on GPIOLIB 2021-05-11 14:04:08 +02:00
ttpci media: pci: ttpci: av7110: fix possible buffer overflow caused by bad DMA value in debiirq() 2020-09-03 11:26:42 +02:00
tw68 media: drivers/media: don't set pix->priv = 0 2019-07-23 08:48:33 -04:00
tw686x media: media/pci: set device_caps in struct video_device 2019-06-24 14:57:12 -04:00
tw5864 media: tw5864: check status of tw5864_frameinterval_get 2020-11-05 11:43:16 +01:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile media: zoran: move to staging in preparation for removal 2018-05-25 15:21:36 -04:00