linux-stable/drivers/mtd/spi-nor
Louis Rannou 61d44a4db2 mtd: spi-nor: Fix shift-out-of-bounds in spi_nor_set_erase_type
commit f0f0cfdc3a upstream.

spi_nor_set_erase_type() was used either to set or to mask out an erase
type. When we used it to mask out an erase type a shift-out-of-bounds
was hit:
UBSAN: shift-out-of-bounds in drivers/mtd/spi-nor/core.c:2237:24
shift exponent 4294967295 is too large for 32-bit type 'int'

The setting of the size_{shift, mask} and of the opcode are unnecessary
when the erase size is zero, as throughout the code just the erase size
is considered to determine whether an erase type is supported or not.
Setting the opcode to 0xFF was wrong too as nobody guarantees that 0xFF
is an unused opcode. Thus when masking out an erase type, just set the
erase size to zero. This will fix the shift-out-of-bounds.

Fixes: 5390a8df76 ("mtd: spi-nor: add support to non-uniform SFDP SPI NOR flash memories")
Cc: stable@vger.kernel.org
Reported-by: Alexander Stein <Alexander.Stein@tq-group.com>
Signed-off-by: Louis Rannou <lrannou@baylibre.com>
Tested-by: Alexander Stein <Alexander.Stein@tq-group.com>
Link: https://lore.kernel.org/r/20230203070754.50677-1-tudor.ambarus@linaro.org
[ta: refine changes, new commit message, fix compilation error]
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-03-10 09:40:05 +01:00
..
controllers spi: intel: Use correct mask for flash and protected regions 2022-11-26 09:24:32 +01:00
atmel.c
catalyst.c
core.c mtd: spi-nor: Fix shift-out-of-bounds in spi_nor_set_erase_type 2023-03-10 09:40:05 +01:00
core.h mtd: spi-nor: Fix shift-out-of-bounds in spi_nor_set_erase_type 2023-03-10 09:40:05 +01:00
eon.c
esmt.c
everspin.c
fujitsu.c
gigadevice.c
intel.c
issi.c
Kconfig
macronix.c mtd: spi-nor: enable locking support for MX25L12805D 2021-05-27 20:04:38 +05:30
Makefile mtd: spi-nor: add initial sysfs support 2021-06-15 23:18:32 +05:30
micron-st.c
otp.c mtd: spi-nor: otp: implement erase for Winbond and similar flashes 2021-06-09 23:34:16 +05:30
sfdp.c mtd: spi-nor: Fix shift-out-of-bounds in spi_nor_set_erase_type 2023-03-10 09:40:05 +01:00
sfdp.h
spansion.c mtd: spi-nor: spansion: Consider reserved bits in CFR5 register 2023-03-10 09:40:05 +01:00
sst.c
swp.c
sysfs.c mtd: spi-nor: hide jedec_id sysfs attribute if not present 2022-12-31 13:14:11 +01:00
winbond.c mtd: spi-nor: otp: implement erase for Winbond and similar flashes 2021-06-09 23:34:16 +05:30
xilinx.c mtd: spi-nor: Fix mtd size for s3an flashes 2022-03-08 19:12:33 +01:00
xmc.c