linux-stable/drivers/mtd
Linus Walleij 63fbcea8d0 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:20:06 +00:00
..
chips mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 17:20:06 +00:00
devices mtd: spear_smi: Use helper function devm_clk_get_enabled() 2023-08-21 09:44:39 +02:00
hyperbus memory: renesas-rpc-if: Remove Runtime PM wrappers 2023-01-23 11:48:00 +01:00
lpddr mtd: lpddr2_nvm: Convert to devm_platform_ioremap_resource() 2023-07-12 14:08:26 +02:00
maps mtd: physmap-core: Restore map_rom fallback 2023-09-11 17:48:22 +02:00
nand mtd: rawnand: meson: check return value of devm_kasprintf() 2023-11-28 17:19:48 +00:00
parsers Raw NAND core changes: 2023-04-19 20:39:03 +02:00
spi-nor Core MTD changes: 2023-09-03 09:59:53 -07: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-09-07 21:59:04 +02:00
ftl.c mtd: ftl: use container_of() rather than cast 2022-09-19 18:14:53 +02:00
inftlcore.c mtd: inftlcore: fix repeated words in comments 2022-11-07 17:14:21 +01:00
inftlmount.c
Kconfig
Makefile
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 mtdblock: make warning messages ratelimited 2023-07-27 17:16:14 +02:00
mtdblock_ro.c mtdblock: make warning messages ratelimited 2023-07-27 17:16:14 +02:00
mtdchar.c mtdchar: mark bits of ioctl handler noinline 2023-06-01 18:12:31 +02:00
mtdconcat.c mtd: fix repeated word in comment 2022-09-20 10:40:30 +02:00
mtdcore.c mtd: Clean refcounting with MTD_PARTITIONED_MASTER 2023-08-04 09:01:56 +02:00
mtdcore.h mtd: use refcount to prevent corruption 2023-07-12 13:30:08 +02:00
mtdoops.c mtd: mtdoops: panic caused mtdoops to call mtdoops_erase function immediately 2022-11-07 17:08:00 +01:00
mtdpart.c mtd: use refcount to prevent corruption 2023-07-12 13:30:08 +02:00
mtdpstore.c mtd: Fix a typo in a comment 2022-09-19 18:14:53 +02:00
mtdsuper.c mtd: key superblock by device number 2023-08-31 12:47:15 +02:00
mtdswap.c mtd: always initialize 'stats' in struct mtd_oob_ops 2022-09-21 10:38:07 +02:00
nftlcore.c mtd: always initialize 'stats' in struct mtd_oob_ops 2022-09-21 10:38:07 +02:00
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 mtd: always initialize 'stats' in struct mtd_oob_ops 2022-09-21 10:38:07 +02:00