linux-stable/drivers/misc
Harshit Mogalapalli dae70a5756 VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host()
[ Upstream commit 19b070fefd ]

Syzkaller hit 'WARNING in dg_dispatch_as_host' bug.

memcpy: detected field-spanning write (size 56) of single field "&dg_info->msg"
at drivers/misc/vmw_vmci/vmci_datagram.c:237 (size 24)

WARNING: CPU: 0 PID: 1555 at drivers/misc/vmw_vmci/vmci_datagram.c:237
dg_dispatch_as_host+0x88e/0xa60 drivers/misc/vmw_vmci/vmci_datagram.c:237

Some code commentry, based on my understanding:

544 #define VMCI_DG_SIZE(_dg) (VMCI_DG_HEADERSIZE + (size_t)(_dg)->payload_size)
/// This is 24 + payload_size

memcpy(&dg_info->msg, dg, dg_size);
	Destination = dg_info->msg ---> this is a 24 byte
					structure(struct vmci_datagram)
	Source = dg --> this is a 24 byte structure (struct vmci_datagram)
	Size = dg_size = 24 + payload_size

{payload_size = 56-24 =32} -- Syzkaller managed to set payload_size to 32.

 35 struct delayed_datagram_info {
 36         struct datagram_entry *entry;
 37         struct work_struct work;
 38         bool in_dg_host_queue;
 39         /* msg and msg_payload must be together. */
 40         struct vmci_datagram msg;
 41         u8 msg_payload[];
 42 };

So those extra bytes of payload are copied into msg_payload[], a run time
warning is seen while fuzzing with Syzkaller.

One possible way to fix the warning is to split the memcpy() into
two parts -- one -- direct assignment of msg and second taking care of payload.

Gustavo quoted:
"Under FORTIFY_SOURCE we should not copy data across multiple members
in a structure."

Reported-by: syzkaller <syzkaller@googlegroups.com>
Suggested-by: Vegard Nossum <vegard.nossum@oracle.com>
Suggested-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/20240105164001.2129796-2-harshit.m.mogalapalli@oracle.com
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-04-13 13:07:29 +02:00
..
altera-stapl misc: add HAS_IOPORT dependencies 2023-05-29 15:05:00 +01:00
bcm-vk Char/Misc driver changes for 6.6-rc1 2023-09-01 09:53:54 -07:00
c2port driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
cardreader misc: rtsx: Fix some platforms can not boot and move the l1ss judgment to probe 2023-09-25 10:48:19 +02:00
cb710
cxl Char/Misc driver changes for 6.6-rc1 2023-09-01 09:53:54 -07:00
echo
eeprom misc: eeprom/idt_89hpesx: Use devm_kmemdup to replace devm_kmalloc + memcpy 2023-08-11 21:38:52 +02:00
genwqe misc: genwqe: make class_genwqe a static const structure 2023-08-11 21:41:33 +02:00
ibmasm ibm: convert to ctime accessor functions 2023-07-13 10:28:02 +02:00
lis3lv02d misc: lis3lv02d_i2c: Fix regulators getting en-/dis-abled twice on suspend/resume 2024-04-03 15:28:43 +02:00
lkdtm lkdtm: Add FAM_BOUNDS test for __counted_by 2023-08-17 16:46:35 -07:00
mchp_pci1xxxx misc: microchip: pci1xxxx: Fix some NULL vs IS_ERR() bugs 2023-08-12 12:58:56 +02:00
mei mei: me: add arrow lake point H DID 2024-04-03 15:28:43 +02:00
ocxl mmu_notifiers: rename invalidate_range notifier 2023-08-18 10:12:41 -07:00
pvpanic
sgi-gru mm: ptep_get() conversion 2023-06-19 16:19:25 -07:00
sgi-xp sgi-xp: simplify sysctl registration 2023-03-09 17:32:13 +01:00
ti-st misc: st_core: Do not call kfree_skb() under spin_lock_irqsave() 2023-11-20 11:59:26 +01:00
uacce uacce: vma_close clears q->qfrs when freeing qfrs 2023-05-31 19:00:26 +01:00
vmw_vmci VMCI: Fix memcpy() run-time warning in dg_dispatch_as_host() 2024-04-13 13:07:29 +02:00
ad525x_dpot-i2c.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
ad525x_dpot-spi.c
ad525x_dpot.c
ad525x_dpot.h
apds990x.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
apds9802als.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
atmel-ssc.c misc: atmel-ssc: Use devm_platform_get_and_ioremap_resource() 2023-08-04 15:38:45 +02:00
bh1770glc.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
cs5535-mfgpt.c
ds1682.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
dummy-irq.c
dw-xdata-pcie.c
enclosure.c drivers: remove struct module * setting from struct class 2023-03-17 15:16:27 +01:00
fastrpc.c misc: fastrpc: Pass proper arguments to scm call 2024-04-03 15:28:43 +02:00
gehc-achc.c
hi6421v600-irq.c misc: hi6421-spmi-pmic: Remove redundant dev_err() 2023-08-04 15:39:10 +02:00
hisi_hikey_usb.c
hmc6352.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
hpilo.c misc: hpilo: make ilo_class a static const structure 2023-08-11 21:41:36 +02:00
hpilo.h
ibmvmc.c ibm: convert to ctime accessor functions 2023-07-13 10:28:02 +02:00
ibmvmc.h
ics932s401.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
isl29003.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
isl29020.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
Kconfig misc: open-dice: make OPEN_DICE depend on HAS_IOMEM 2023-08-04 15:39:42 +02:00
kgdbts.c
lattice-ecp3-config.c
Makefile misc: tps6594-pfsm: Add driver for TI TPS6594 PFSM 2023-06-15 13:41:53 +02:00
open-dice.c misc: open-dice: Fix spurious lockdep warning 2024-03-01 13:34:51 +01:00
pch_phub.c
pci_endpoint_test.c misc: pci_endpoint_test: Add Device ID for R-Car S4-8 PCIe controller 2023-11-28 17:19:44 +00:00
phantom.c driver core: class: remove module * from class_create() 2023-03-17 15:16:33 +01:00
qcom-coincell.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00
smpro-errmon.c misc: smpro-errmon: Remove the unneeded include <linux/i2c.h> 2023-05-31 19:00:10 +01:00
smpro-misc.c misc: smpro-misc: Add Ampere's Altra SMpro misc driver 2022-11-10 19:03:03 +01:00
sram-exec.c mm: Introduce set_memory_rox() 2022-12-15 10:37:26 -08:00
sram.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00
sram.h misc: sram: Improve and simplify clk handling 2023-03-09 17:31:53 +01:00
tifm_7xx1.c misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() 2022-11-23 19:55:26 +01:00
tifm_core.c driver core: make struct bus_type.uevent() take a const * 2023-01-27 13:45:52 +01:00
tps6594-esm.c Merge 6.5-rc6 into char-misc-next 2023-08-13 22:14:51 +02:00
tps6594-pfsm.c misc: tps6594: Remove redundant dev_err_probe() for platform_get_irq_byname() 2023-08-12 12:58:40 +02:00
tsl2550.c misc: Switch i2c drivers back to use .probe() 2023-05-29 15:04:52 +01:00
vcpu_stall_detector.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00
vmw_balloon.c misc: vmw_balloon: fix memory leak with using debugfs_lookup() 2023-02-08 13:24:22 +01:00
xilinx_sdfec.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00
xilinx_tmr_inject.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00
xilinx_tmr_manager.c misc: Explicitly include correct DT includes 2023-08-04 15:39:04 +02:00