linux-stable/drivers
Gustavo A. R. Silva 01afbfb395 qed/red_ll2: Fix undefined behavior bug in struct qed_ll2_info
commit eea03d18af upstream.

The flexible structure (a structure that contains a flexible-array member
at the end) `qed_ll2_tx_packet` is nested within the second layer of
`struct qed_ll2_info`:

struct qed_ll2_tx_packet {
	...
        /* Flexible Array of bds_set determined by max_bds_per_packet */
        struct {
                struct core_tx_bd *txq_bd;
                dma_addr_t tx_frag;
                u16 frag_len;
        } bds_set[];
};

struct qed_ll2_tx_queue {
	...
	struct qed_ll2_tx_packet cur_completing_packet;
};

struct qed_ll2_info {
	...
	struct qed_ll2_tx_queue tx_queue;
        struct qed_ll2_cbs cbs;
};

The problem is that member `cbs` in `struct qed_ll2_info` is placed just
after an object of type `struct qed_ll2_tx_queue`, which is in itself
an implicit flexible structure, which by definition ends in a flexible
array member, in this case `bds_set`. This causes an undefined behavior
bug at run-time when dynamic memory is allocated for `bds_set`, which
could lead to a serious issue if `cbs` in `struct qed_ll2_info` is
overwritten by the contents of `bds_set`. Notice that the type of `cbs`
is a structure full of function pointers (and a cookie :) ):

include/linux/qed/qed_ll2_if.h:
107 typedef
108 void (*qed_ll2_complete_rx_packet_cb)(void *cxt,
109                                       struct qed_ll2_comp_rx_data *data);
110
111 typedef
112 void (*qed_ll2_release_rx_packet_cb)(void *cxt,
113                                      u8 connection_handle,
114                                      void *cookie,
115                                      dma_addr_t rx_buf_addr,
116                                      bool b_last_packet);
117
118 typedef
119 void (*qed_ll2_complete_tx_packet_cb)(void *cxt,
120                                       u8 connection_handle,
121                                       void *cookie,
122                                       dma_addr_t first_frag_addr,
123                                       bool b_last_fragment,
124                                       bool b_last_packet);
125
126 typedef
127 void (*qed_ll2_release_tx_packet_cb)(void *cxt,
128                                      u8 connection_handle,
129                                      void *cookie,
130                                      dma_addr_t first_frag_addr,
131                                      bool b_last_fragment, bool b_last_packet);
132
133 typedef
134 void (*qed_ll2_slowpath_cb)(void *cxt, u8 connection_handle,
135                             u32 opaque_data_0, u32 opaque_data_1);
136
137 struct qed_ll2_cbs {
138         qed_ll2_complete_rx_packet_cb rx_comp_cb;
139         qed_ll2_release_rx_packet_cb rx_release_cb;
140         qed_ll2_complete_tx_packet_cb tx_comp_cb;
141         qed_ll2_release_tx_packet_cb tx_release_cb;
142         qed_ll2_slowpath_cb slowpath_cb;
143         void *cookie;
144 };

Fix this by moving the declaration of `cbs` to the  middle of its
containing structure `qed_ll2_info`, preventing it from being
overwritten by the contents of `bds_set` at run-time.

This bug was introduced in 2017, when `bds_set` was converted to a
one-element array, and started to be used as a Variable Length Object
(VLO) at run-time.

Fixes: f5823fe689 ("qed: Add ll2 option to limit the number of bds per packet")
Cc: stable@vger.kernel.org
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Reviewed-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/ZQ+Nz8DfPg56pIzr@work
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-10-10 22:00:38 +02:00
..
accessibility
acpi ACPI: x86: s2idle: Catch multiple ACPI_TYPE_PACKAGE objects 2023-09-23 11:11:00 +02:00
amba
android
ata ata: libata-scsi: Fix delayed scsi_rescan_device() execution 2023-10-10 22:00:35 +02:00
atm
auxdisplay
base
bcma
block rbd: take header_rwsem in rbd_dev_refresh() only when updating 2023-10-10 22:00:37 +02:00
bluetooth
bus bus: ti-sysc: Fix SYSC_QUIRK_SWSUP_SIDLE_ACT handling for uart wake-up 2023-10-06 14:56:48 +02:00
cdrom
char parisc: sba: Fix compile warning wrt list of SBA devices 2023-10-06 14:56:51 +02:00
clk clk: tegra: fix error return case for recalc_rate 2023-10-06 14:56:47 +02:00
clocksource clocksource/drivers/arm_arch_timer: Disable timer before programming CVAL 2023-09-19 12:28:04 +02:00
comedi
connector
counter
cpufreq cpufreq: brcmstb-avs-cpufreq: Fix -Warray-bounds bug 2023-09-13 09:43:04 +02:00
cpuidle
crypto crypto: stm32 - fix loop iterating through scatterlist for DMA 2023-09-13 09:43:04 +02:00
cxl
dax
dca
devfreq PM / devfreq: Fix leak in devfreq_dev_release() 2023-09-13 09:42:59 +02:00
dio
dma dmaengine: sh: rz-dmac: Fix destination and source data size setting 2023-09-19 12:28:04 +02:00
dma-buf dma-buf: Add unlocked variant of attachment-mapping functions 2023-09-23 11:11:08 +02:00
edac
eisa
extcon
firewire scsi: sd: Differentiate system and runtime start/stop management 2023-10-10 22:00:34 +02:00
firmware firmware: cirrus: cs_dsp: Only log list of algorithms in debug build 2023-10-06 14:56:56 +02:00
fpga
fsi
gnss
gpio gpio: pmic-eic-sprd: Add can_sleep flag for PMIC EIC chip 2023-10-06 14:56:50 +02:00
gpu drm/amd/display: Adjust the MST resume flow 2023-10-10 22:00:37 +02:00
greybus
hid HID: multitouch: Correct devm device reference for hidinput input_dev name 2023-09-13 09:42:57 +02:00
hsi
hte
hv Drivers: hv: vmbus: Don't dereference ACPI root object handle 2023-09-13 09:42:59 +02:00
hwmon hwmon: (nzxt-smart2) add another USB ID 2023-10-10 22:00:37 +02:00
hwspinlock hwspinlock: qcom: add missing regmap config for SFPB MMIO implementation 2023-09-19 12:28:05 +02:00
hwtracing
i2c i2c: i801: unregister tco_pdev in i801_probe() error path 2023-10-06 14:57:02 +02:00
i3c i3c: master: svc: fix probe failure when no i3c device exist 2023-09-13 09:43:01 +02:00
idle
iio
infiniband RDMA/efa: Fix wrong resources deallocation order 2023-09-13 09:42:57 +02:00
input Input: tca6416-keypad - fix interrupt enable disbalance 2023-09-19 12:27:59 +02:00
interconnect interconnect: Teach lockdep about icc_bw_lock order 2023-09-23 11:11:13 +02:00
iommu iommu/vt-d: Avoid memory allocation in iommu_suspend() 2023-10-10 22:00:38 +02:00
ipack
irqchip
isdn
leds leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead 2023-09-13 09:42:58 +02:00
macintosh
mailbox mailbox: qcom-ipcc: fix incorrect num_chans counting 2023-09-19 12:27:58 +02:00
mcb
md dm: fix a race condition in retrieve_deps 2023-10-06 14:56:32 +02:00
media media: uvcvideo: Fix OOB read 2023-10-06 14:57:04 +02:00
memory
memstick
message
mfd
misc misc: rtsx: Fix some platforms can not boot and move the l1ss judgment to probe 2023-10-06 14:57:00 +02:00
mmc mmc: sdhci-esdhc-imx: improve ESDHC_FLAG_ERR010450 2023-09-23 11:11:02 +02:00
most
mtd mtd: rawnand: brcmnand: Fix ECC level field setting for v7.2 controller 2023-09-19 12:28:06 +02:00
mux
net qed/red_ll2: Fix undefined behavior bug in struct qed_ll2_info 2023-10-10 22:00:38 +02:00
nfc
ntb ntb: Fix calculation ntb_transport_tx_free_entry() 2023-09-13 09:43:02 +02:00
nubus
nvdimm
nvme nvme-pci: always return an ERR_PTR from nvme_pci_alloc_dev 2023-10-06 14:56:59 +02:00
nvmem
of treewide: Fix probing of devices in DT overlays 2023-09-13 09:43:05 +02:00
opp
parisc parisc: iosapic.c: Fix sparse warnings 2023-10-06 14:56:51 +02:00
parport
pci PCI: fu740: Set the number of MSI vectors 2023-09-23 11:11:05 +02:00
pcmcia
peci
perf perf/imx_ddr: speed up overflow frequency of cycle 2023-09-23 11:11:00 +02:00
phy phy/rockchip: inno-hdmi: do not power on rk3328 post pll on reg write 2023-09-13 09:42:58 +02:00
pinctrl pinctrl: cherryview: fix address_space_handler() argument 2023-09-19 12:27:57 +02:00
platform platform/x86: asus-wmi: Support 2023 ROG X16 tablet mode 2023-10-06 14:56:53 +02:00
pnp
power power: supply: ab8500: Set typing and props 2023-10-06 14:57:06 +02:00
powercap
pps
ps3
ptp
pwm pwm: lpc32xx: Remove handling of PWM channels 2023-09-19 12:28:00 +02:00
rapidio
ras
regulator
remoteproc
reset
rpmsg rpmsg: glink: Add check for kstrdup 2023-09-13 09:42:58 +02:00
rtc
s390 scsi: zfcp: Fix a double put in zfcp_port_enqueue() 2023-10-10 22:00:38 +02:00
sbus
scsi scsi: Do not attempt to rescan suspended devices 2023-10-10 22:00:35 +02:00
sh
siox
slimbus
soc soc: imx8m: Enable OCOTP clock for imx8mm before reading registers 2023-10-06 14:56:49 +02:00
soundwire
spi spi: zynqmp-gqspi: fix clock imbalance on probe failure 2023-10-10 22:00:34 +02:00
spmi
ssb
staging
target scsi: target: core: Fix target_cmd_counter leak 2023-09-23 11:11:09 +02:00
tc
tee
thermal thermal/of: add missing of_node_put() 2023-10-06 14:56:53 +02:00
thunderbolt
tty serial: 8250_port: Check IRQ data before use 2023-10-06 14:57:01 +02:00
ufs scsi: ufs: core: Poll HCS.UCRDY before issuing a UIC command 2023-10-06 14:56:52 +02:00
uio
usb usb: chipidea: add workaround for chipidea PEC bug 2023-09-23 11:11:07 +02:00
vdpa
vfio vfio/mdev: Fix a null-ptr-deref bug for mdev_unregister_parent() 2023-10-06 14:56:45 +02:00
vhost vringh: don't use vringh_kiov_advance() in vringh_iov_xfer() 2023-10-10 22:00:38 +02:00
video fbdev/sh7760fb: Depend on FB=y 2023-10-06 14:56:58 +02:00
virt
virtio virtio_ring: fix avail_wrap_counter in virtqueue_add_packed 2023-09-13 09:42:59 +02:00
vlynq
w1
watchdog watchdog: intel-mid_wdt: add MODULE_ALIAS() to allow auto-load 2023-09-19 12:28:00 +02:00
xen
zorro
Kconfig
Makefile