linux-stable/drivers/mtd
ZhaoLong Wang d8ac253776 mtd: Fix gluebi NULL pointer dereference caused by ftl notifier
[ Upstream commit a43bdc376d ]

If both ftl.ko and gluebi.ko are loaded, the notifier of ftl
triggers NULL pointer dereference when trying to access
‘gluebi->desc’ in gluebi_read().

ubi_gluebi_init
  ubi_register_volume_notifier
    ubi_enumerate_volumes
      ubi_notify_all
        gluebi_notify    nb->notifier_call()
          gluebi_create
            mtd_device_register
              mtd_device_parse_register
                add_mtd_device
                  blktrans_notify_add   not->add()
                    ftl_add_mtd         tr->add_mtd()
                      scan_header
                        mtd_read
                          mtd_read_oob
                            mtd_read_oob_std
                              gluebi_read   mtd->read()
                                gluebi->desc - NULL

Detailed reproduction information available at the Link [1],

In the normal case, obtain gluebi->desc in the gluebi_get_device(),
and access gluebi->desc in the gluebi_read(). However,
gluebi_get_device() is not executed in advance in the
ftl_add_mtd() process, which leads to NULL pointer dereference.

The solution for the gluebi module is to run jffs2 on the UBI
volume without considering working with ftl or mtdblock [2].
Therefore, this problem can be avoided by preventing gluebi from
creating the mtdblock device after creating mtd partition of the
type MTD_UBIVOLUME.

Fixes: 2ba3d76a1e ("UBI: make gluebi a separate module")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217992 [1]
Link: https://lore.kernel.org/lkml/441107100.23734.1697904580252.JavaMail.zimbra@nod.at/ [2]
Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
Reviewed-by: Zhihao Cheng <chengzhihao1@huawei.com>
Acked-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20231220024619.2138625-1-wangzhaolong1@huawei.com
Signed-off-by: Sasha Levin <sashal@kernel.org>
2024-01-25 14:52:34 -08:00
..
chips mtd: cfi_cmdset_0001: Byte swap OTP info 2023-11-28 16:56:31 +00:00
devices mtd: devices: docg3: check the return value of devm_ioremap() in the probe 2022-10-26 12:35:09 +02:00
hyperbus
lpddr mtd: lpddr2_nvm: Fix possible null-ptr-deref 2022-12-31 13:14:10 +01:00
maps mtd: physmap-core: Restore map_rom fallback 2023-10-25 11:59:02 +02:00
nand mtd: rawnand: Increment IFC_TIMEOUT_MSECS for nand controller response 2024-01-25 14:52:33 -08:00
parsers mtd: parsers: bcm47xxpart: Fix halfblock reads 2022-11-10 18:15:32 +01:00
spi-nor mtd: spi-nor: Check bus width while setting QE bit 2023-09-19 12:22:49 +02:00
tests
ubi ubi: Refuse attaching if mtd's erasesize is 0 2023-10-10 21:59:06 +02:00
ftl.c
inftlcore.c
inftlmount.c
Kconfig
Makefile
mtd_blkdevs.c mtd: Fix gluebi NULL pointer dereference caused by ftl notifier 2024-01-25 14:52:34 -08:00
mtdblock.c mtdblock: tolerate corrected bit-flips 2023-04-20 12:13:52 +02:00
mtdblock_ro.c
mtdchar.c
mtdconcat.c
mtdcore.c mtd: core: fix error path for nvmem provider 2023-05-11 23:00:39 +09:00
mtdcore.h
mtdoops.c
mtdpart.c
mtdpstore.c
mtdsuper.c
mtdswap.c
nftlcore.c
nftlmount.c
rfd_ftl.c
sm_ftl.c mtd: sm_ftl: Fix deadlock caused by cancel_work_sync in sm_release 2022-08-17 14:23:40 +02:00
sm_ftl.h
ssfdc.c