linux-stable/drivers/mtd
Linus Walleij 3c6facb357 mtd: cfi_cmdset_0001: Byte swap OTP info
commit 565fe15062 upstream.

Currently the offset into the device when looking for OTP
bits can go outside of the address of the MTD NOR devices,
and if that memory isn't readable, bad things happen
on the IXP4xx (added prints that illustrate the problem before
the crash):

cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x00000100
ixp4xx_copy_from copy from 0x00000100 to 0xc880dd78
cfi_intelext_otp_walk walk OTP on chip 0 start at reg_prot_offset 0x12000000
ixp4xx_copy_from copy from 0x12000000 to 0xc880dd78
8<--- cut here ---
Unable to handle kernel paging request at virtual address db000000
[db000000] *pgd=00000000
(...)

This happens in this case because the IXP4xx is big endian and
the 32- and 16-bit fields in the struct cfi_intelext_otpinfo are not
properly byteswapped. Compare to how the code in read_pri_intelext()
byteswaps the fields in struct cfi_pri_intelext.

Adding a small byte swapping loop for the OTP in read_pri_intelext()
and the crash goes away.

The problem went unnoticed for many years until I enabled
CONFIG_MTD_OTP on the IXP4xx as well, triggering the bug.

Cc: stable@vger.kernel.org
Reviewed-by: Nicolas Pitre <nico@fluxnic.net>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20231020-mtd-otp-byteswap-v4-1-0d132c06aa9d@linaro.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2023-11-28 17:15:08 +00:00
..
chips mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 17:15:08 +00:00
devices Core MTD changes: 2023-06-28 14:02:03 -07:00
hyperbus memory: renesas-rpc-if: Remove Runtime PM wrappers 2023-01-23 11:48:00 +01:00
lpddr mtd: lpddr_cmds: remove unused words variable 2023-03-28 14:59:21 +02:00
maps mtd: physmap-core: Restore map_rom fallback 2023-10-25 12:16:21 +02:00
nand mtd: rawnand: meson: check return value of devm_kasprintf() 2023-11-28 17:14:52 +00:00
parsers Raw NAND core changes: 2023-04-19 20:39:03 +02:00
spi-nor mtd: spi-nor: spansion: preserve CFR2V[7] when writing MEMLAT 2023-09-23 11:14:31 +02:00
tests treewide: use get_random_u32_below() instead of deprecated function 2022-11-18 02:15:15 +01:00
ubi ubi: Refuse attaching if mtd's erasesize is 0 2023-10-10 22:02:58 +02:00
Kconfig
Makefile
ftl.c
inftlcore.c mtd: inftlcore: fix repeated words in comments 2022-11-07 17:14:21 +01:00
inftlmount.c
mtd_blkdevs.c block: replace fmode_t with a block-specific type for block open flags 2023-06-12 08:04:05 -06:00
mtdblock.c mtd: block: use a simple bool to track open for write 2023-06-12 08:04:04 -06:00
mtdblock_ro.c mtdblock: tolerate corrected bit-flips 2023-03-22 17:02:19 +01:00
mtdchar.c mtdchar: mark bits of ioctl handler noinline 2023-06-01 18:12:31 +02:00
mtdconcat.c
mtdcore.c mtd: otp: clean up on error in mtd_otp_nvmem_add() 2023-06-19 10:26:06 +02:00
mtdcore.h
mtdoops.c mtd: mtdoops: panic caused mtdoops to call mtdoops_erase function immediately 2022-11-07 17:08:00 +01:00
mtdpart.c mtd: mtdpart: Drop useless LIST_HEAD 2023-06-09 17:27:14 +02:00
mtdpstore.c
mtdsuper.c
mtdswap.c
nftlcore.c
nftlmount.c
rfd_ftl.c
sm_ftl.c mtd: sm_ftl: Fix typos in comments 2023-06-22 23:00:43 +02:00
sm_ftl.h
ssfdc.c