public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Re: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier
@ 2024-06-17 14:25 Gagan Sidhu
  2024-06-17 14:31 ` Richard Weinberger
  2024-06-17 15:42 ` Richard Weinberger
  0 siblings, 2 replies; 41+ messages in thread
From: Gagan Sidhu @ 2024-06-17 14:25 UTC (permalink / raw)
  To: wangzhaolong1
  Cc: Artem.Bityutskiy, chengzhihao1, dpervushin, linux-kernel,
	linux-mtd, miquel.raynal, richard, vigneshr, yangerkun, yi.zhang

hi,

this patch isn’t a good one.

it must be reverted.

the problem with mr wang's changes is that it breaks expected mounting behaviour of a filesystem within an UBI, as is the case for openwrt.

i am surprised no one has raised the issue about this. i see mr raynal did raise an issue with one of mr zhihao’s fundamental errors:

https://lore.kernel.org/lkml/20231027194026.1bc32dfe@xps-13/

> Therefore, this problem can be avoided by preventing gluebi
> from creating mtdblock devices.

this is absolutely wrong.

typically what happens is we will wrap a squashfs filesystem inside a UBI layer. openwrt people call this “ubinising” the root filesystem.

then, after we label the appropriate nand partitions as ‘uimage,fw’ to call the right mtdsplit, the mtd_ubi subsystem works its magic automatically, as long as the root partition is named “rootfs”.

at that point, the rootfs will be *AUTOMATICALLY* mounted AND booted from BY THE KERNEL. that is, no cmdline hacks are required.

this patch breaks that behaviour since mr wang’s additional conditions result in the failure of the partition to get added to the mtd list, and thus fails mount.

i have attached a log of this behaviour. and by removing mr wang’s “fixes”, it mounts as we would expect.

this change must be reverted. extremely surprised the openwrt team has not raised issues over this by now.

```


3: System Boot system code via Flash.
## Booting image at bc180000 ...
  Image Name:   DD-WRT v24 Linux Kernel Imag
  Image Type:   MIPS Linux Kernel Image (lzma compressed)
  Data Size:    3875031 Bytes =  3.7 MB
  Load Address: 80001000
  Entry Point:  807d9e20
............................................................   Verifying Checksum ... OK
  Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 807d9e20) ...
## Giving linux memsize in MB, 256

Starting kernel ...

[    0.000000] Linux version 4.14.348-openela-rt159 (
Gagan@GagansMacPro.local
) (gcc version 14.1.0 (GCC)) #5426 SMP Sat Jun 15 07:23:17 MDT 2024
[    0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[    0.000000] MIPS: machine is D-Link DIR-2640 rev. A1
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 10000000 @ 00000000 (usable)
[    0.000000] VPE topology {2,2} total 4
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x0000000000ffffff]
[    0.000000]   Normal   [mem 0x0000000001000000-0x000000000fffffff]
[    0.000000]   HighMem  empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000] percpu: Embedded 15 pages/cpu s30672 r8192 d22576 u61440
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 65024
[    0.000000] Kernel command line: console=ttyS0,57600n8
[    0.000000] log_buf_len individual max cpu contribution: 4096 bytes
[    0.000000] log_buf_len total cpu_extra contributions: 12288 bytes
[    0.000000] log_buf_len min size: 16384 bytes
[    0.000000] log_buf_len: 32768 bytes
[    0.000000] early log buf free: 14216(86%)
[    0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Writing ErrCtl register=000412fa
[    0.000000] Readback ErrCtl register=000412fa
[    0.000000] Memory: 247980K/262144K available (8061K kernel code, 892K rwdata, 1568K rodata, 280K init, 733K bss, 14164K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000] NR_IRQS: 256
[    0.000000] CPU Clock: 880MHz
[    0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478abb4, max_idle_ns: 440795247997 ns
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 4343773742 ns
[    0.000009] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 4880645118ns
[    0.015565] Calibrating delay loop... 583.68 BogoMIPS (lpj=1167360)
[    0.055919] pid_max: default: 4096 minimum: 301
[    0.065064] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.078089] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.093805] Hierarchical SRCU implementation.
[    0.103082] smp: Bringing up secondary CPUs ...
[    0.113986] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.113994] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.114004] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.114122] CPU1 revision is: 0001992f (MIPS 1004Kc)
[    0.140246] Synchronize counters for CPU 1: done.
[    0.205804] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.205812] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.205818] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.205878] CPU2 revision is: 0001992f (MIPS 1004Kc)
[    0.239402] Synchronize counters for CPU 2: done.
[    0.300999] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.301006] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.301013] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.301082] CPU3 revision is: 0001992f (MIPS 1004Kc)
[    0.327024] Synchronize counters for CPU 3: done.
[    0.386624] smp: Brought up 1 node, 4 CPUs
[    0.395319] devtmpfs: initialized
[    0.405072] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.424361] futex hash table entries: 16 (order: -3, 512 bytes)
[    0.436154] pinctrl core: initialized pinctrl subsystem
[    0.447323] NET: Registered protocol family 16
[    0.456700] cpuidle: using governor menu
[    0.484220] pull PCIe RST: RALINK_RSTCTRL = 4000000
[    0.794105] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.804176] ***** Xtal 40MHz *****
[    0.810918] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.821113] Port 0 N_FTS = 1b105000
[    0.828025] Port 1 N_FTS = 1b105000
[    0.834937] Port 2 N_FTS = 1b102800
[    1.992951] PCIE2 no card, disable it(RST&CLK)
[    2.001641]  -> 21007f2
[    2.006479] PCIE0 enabled
[    2.011663] PCIE1 enabled
[    2.016858] PCI host bridge /pcie@1e140000 ranges:
[    2.026367]  MEM 0x0000000060000000..0x000000006fffffff
[    2.036726]   IO 0x000000001e160000..0x000000001e16ffff
[    2.047093] PCI coherence region base: 0x60000000, mask/settings: 0xf0000002
[    2.066762] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.078058] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.089214] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.100683] vgaarb: loaded
[    2.106249] SCSI subsystem initialized
[    2.113766] usbcore: registered new interface driver usbfs
[    2.124606] usbcore: registered new interface driver hub
[    2.135129] usbcore: registered new device driver usb
[    2.145477] i2c-mt7621 1e000900.i2c: clock 100KHz, re-start not support
[    2.158813] PCI host bridge to bus 0000:00
[    2.166839] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff]
[    2.180477] pci_bus 0000:00: root bus resource [io  0x1e160000-0x1e16ffff]
[    2.194129] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    2.207606] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.224155] pci 0000:01:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x1 link at 0000:00:00.0 (capable of 4.000 Gb/s with 5 GT/s x1 link)
[    2.251939] pci 0000:02:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x1 link at 0000:00:01.0 (capable of 4.000 Gb/s with 5 GT/s x1 link)
[    2.279470] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    2.292494] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.306313] pci 0000:00:01.0: BAR 0: no space for [mem size 0x80000000]
[    2.319449] pci 0000:00:01.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.333277] pci 0000:00:00.0: BAR 8: assigned [mem 0x60000000-0x600fffff]
[    2.346755] pci 0000:00:01.0: BAR 8: assigned [mem 0x60100000-0x601fffff]
[    2.360233] pci 0000:00:00.0: BAR 1: assigned [mem 0x60200000-0x6020ffff]
[    2.373709] pci 0000:00:01.0: BAR 1: assigned [mem 0x60210000-0x6021ffff]
[    2.387208] pci 0000:01:00.0: BAR 0: assigned [mem 0x60000000-0x600fffff 64bit]
[    2.401712] pci 0000:00:00.0: PCI bridge to [bus 01]
[    2.411548] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    2.425039] pci 0000:02:00.0: BAR 0: assigned [mem 0x60100000-0x601fffff 64bit]
[    2.439555] pci 0000:00:01.0: PCI bridge to [bus 02]
[    2.449396] pci 0000:00:01.0:   bridge window [mem 0x60100000-0x601fffff]
[    2.463554] clocksource: Switched to clocksource GIC
[    2.474753] NET: Registered protocol family 2
[    2.483561] IP idents hash table entries: 4096 (order: 3, 32768 bytes)
[    2.497245] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[    2.511002] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[    2.523798] TCP: Hash tables configured (established 2048 bind 2048)
[    2.536493] UDP hash table entries: 128 (order: 0, 4096 bytes)
[    2.547983] UDP-Lite hash table entries: 128 (order: 0, 4096 bytes)
[    2.560657] NET: Registered protocol family 1
[    2.659518] 4 CPUs re-calibrate udelay(lpj = 1163264)
[    2.670337] workingset: timestamp_bits=30 max_order=16 bucket_order=0
[    2.689246] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.709543] io scheduler noop registered
[    2.717554] io scheduler cfq registered (default)
[    2.726769] io scheduler mq-deadline registered
[    2.735774] io scheduler kyber registered
[    2.744477] mtk_hsdma 1e007000.hsdma: Using 3 as missing dma-requests property
[    2.758985] mtk_hsdma 1e007000.hsdma: MediaTek HSDMA driver registered
[    2.823896] serial8250_init
[    2.829315] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    2.843297] console [ttyS0] disabled
[    2.850333] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 19, base_baud = 3125000) is a 16550A
[    2.868297] console [ttyS0] enabled
[    2.868297] console [ttyS0] enabled
[    2.882070] bootconsole [early0] disabled
[    2.882070] bootconsole [early0] disabled
[    2.898446] Ralink gpio driver initialized:power_gpio[8]
[    2.910106] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[    2.924094] Enable NFI Clock
[    2.929829] # MTK NAND # : Use HW ECC
[    2.937139] Device not found, ID: c8d1
[    2.944610] Not Support this Device!
[    2.952075] chip_mode=00000001
[    2.958157] Support this Device in MTK table! c8d1
[    2.968055] [NAND]select ecc bit:4, sparesize :64 spare_per_sector=16
[    2.980930] nand: device found, Manufacturer ID: 0xc8, Chip ID: 0xd1
[    2.993590] nand: ESMT NAND 128MiB 3,3V 8-bit
[    3.002281] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    3.017376] Scanning device for bad blocks
[    3.169277] MT7621-NAND: parsing partitions cmdlinepart
[    3.180264] MT7621-NAND: got parser (null)
[    3.188484] 9 fixed-partitions partitions found on MTD device MT7621-NAND
[    3.202005] Creating 9 MTD partitions on "MT7621-NAND":
[    3.212430] 0x000000000000-0x000000080000 : "Bootloader"
[    3.224024] 0x0000000c0000-0x000000100000 : "Config"
[    3.234684] 0x000000100000-0x000000140000 : "Factory"
[    3.245518] 0x000000140000-0x000000180000 : "Config2"
[    3.256379] 0x000000180000-0x000002d80000 : "sysv"
[    3.895176] 1 squashfs-split partitions found on MTD device sysv
[    3.907164] 0x0000005c1000-0x000002d60000 : "ddwrt"
[    3.920925] 2 uimage-fw partitions found on MTD device sysv
[    3.932031] Creating 2 MTD partitions on "sysv":
[    3.941232] 0x000000000000-0x000000400000 : "kernel"
[    3.951995] 0x000000400000-0x000002c00000 : "ubi"
[    3.962325] 0x000002d80000-0x000004d80000 : "private"
[    3.973322] 0x000004d80000-0x000007580000 : "firmware2"
[    3.984759] 0x000007580000-0x000007b80000 : "mydlink"
[    3.995699] 0x000007b80000-0x000008000000 : "reserved"
[    4.006687] [mtk_nand] probe successfully!
[    4.015584] Signature matched and data read!
[    4.024090] load_fact_bbt success 1023
[    4.031931] tun: Universal TUN/TAP device driver, 1.6
[    4.042377] CHIP_ID = MT7621
[    4.048133] WAN at P4
[    4.052659] GMAC1 support rgmii
[    4.058911] GE1_RGMII_FORCE_1000
[    4.065348] GMAC2 support rgmii
[    4.071606] RGMII_AN (Internal GigaPhy)
[    4.079973] STD_v0.1  1024 rx/2048 tx descriptors allocated, mtu = 1500!
[    4.094358] set CLK_CFG_0 = 0x40a00020!!!!!!!!!!!!!!!!!!1
[    4.105108] trgmii_set_7621 Completed!!
[    4.324297] MT7530 Reset Completed!!
[    4.340754] trgmii_set_7530 Completed!!
[    4.348739] change HW-TRAP to 0x17c8f
[    4.360357] set LAN/WAN LLLLW
[    4.374100] eth3: ===> virtualif_open
[    4.381646] == MT7530 MCM ==
[    4.387482] PPP generic driver version 2.4.2
[    4.396233] PPP BSD Compression module registered
[    4.405603] PPP Deflate Compression module registered
[    4.415687] PPP MPPE Compression module registered
[    4.425229] NET: Registered protocol family 24
[    4.434106] register mt_drv
[    4.439738] bus=0x1, slot = 0x0, irq=0x0
[    4.472239]
[    4.472239] == pAd = c0181000, size = 6632704, Status=0 ==
[    4.486132] pAd->PciHif.CSRBaseAddress =0xc0080000, csr_addr=0xc0080000!
[    4.499531] RTMPInitPCIeDevice():device_id=0x7615
[    4.508911] mt_pci_chip_cfg(): HWVer=0x8a10, FWVer=0x8a10, pAd->ChipID=0x7615
[    4.523136] mt_pci_chip_cfg(): HIF_SYS_REV=0x76150001
[    4.533196] AP Driver version-5.1.0.0
[    4.540493] RtmpChipOpsHook(223): Not support for HIF_MT yet! MACVersion=0x0
[    4.554527] mt7615_init()-->
[    4.560266] Use 1st ePAeLNA default bin.
[    4.568078] Use 0st /etc/wlan/mt7615e.eeprom.bin default bin.
[    4.579550] <--mt7615_init()
[    4.589234] <-- RTMPAllocTxRxRingMemory, Status=0
[    4.599438] bus=0x2, slot = 0x1, irq=0x0
[    4.631995]
[    4.631995] == pAd = c0901000, size = 6632704, Status=0 ==
[    4.645884] pAd->PciHif.CSRBaseAddress =0xc0800000, csr_addr=0xc0800000!
[    4.659234] RTMPInitPCIeDevice():device_id=0x7615
[    4.668612] mt_pci_chip_cfg(): HWVer=0x8a10, FWVer=0x8a10, pAd->ChipID=0x7615
[    4.682820] mt_pci_chip_cfg(): HIF_SYS_REV=0x76150001
[    4.692879] AP Driver version-5.1.0.0
[    4.700175] RtmpChipOpsHook(223): Not support for HIF_MT yet! MACVersion=0x0
[    4.714208] mt7615_init()-->
[    4.719946] Use 2nd ePAeLNA default bin.
[    4.727767] Use 1st /etc/wlan/mt7615e.eeprom.bin default bin.
[    4.739224] <--mt7615_init()
[    4.748896] <-- RTMPAllocTxRxRingMemory, Status=0
[    4.759057] rdm_major = 255
[    4.765124] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    4.775743] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus number 1
[    4.799681] xhci-mtk 1e1c0000.xhci: hcc params 0x01401198 hci version 0x96 quirks 0x0000000000290010
[    4.817950] xhci-mtk 1e1c0000.xhci: irq 22, io mem 0x1e1c0000
[    4.830260] hub 1-0:1.0: USB hub found
[    4.837822] hub 1-0:1.0: 2 ports detected
[    4.846283] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    4.856910] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus number 2
[    4.871846] xhci-mtk 1e1c0000.xhci: Host supports USB 3.0  SuperSpeed
[    4.884885] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    4.901675] hub 2-0:1.0: USB hub found
[    4.909226] hub 2-0:1.0: 1 port detected
[    4.917608] usbcore: registered new interface driver usblp
[    4.928659] usbcore: registered new interface driver usb-storage
[    4.940727] usbcore: registered new interface driver usbserial
[    5.007737] rtc-pcf8563 0-0051: registered as rtc0
[    5.031606] i2c /dev entries driver
[    5.038842] Ralink APSoC Hardware Watchdog Timer
[    5.049311] usbcore: registered new interface driver usbhid
[    5.060419] usbhid: USB HID core driver
[    5.068615] u32 classifier
[    5.074005]     Performance counters on
[    5.081638]     Actions configured
[    5.088434] Netfilter messages via NETLINK v0.30.
[    5.098071] nf_conntrack version 0.5.0 (4096 buckets, 16384 max)
[    5.110321] ctnetlink v0.93: registering with nfnetlink.
[    5.121402] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    5.132985] ip_tables: (C) 2000-2006 Netfilter Core Team
[    5.144546] NET: Registered protocol family 10
[    5.155889] Segment Routing with IPv6
[    5.163303] NET: Registered protocol family 17
[    5.172292] Bridge firewalling registered
[    5.180281] 8021q: 802.1Q VLAN Support v1.8
[    5.189452] registered taskstats version 1
[    5.198914] searching for nvram
[    5.279016] found nvram at 0, name:Config, contributed bytes:262144
[    5.328401] nvram empty
[    5.407013] found nvram at 1, name:Config2, contributed bytes:262144
[    5.456567] nvram empty
[    5.462504] auto-attach mtd7
[    5.462525] ubi0: default fastmap pool size: 15
[    5.477309] ubi0: default fastmap WL pool size: 7
[    5.486683] ubi0: attaching mtd7
[    5.811240] UBI: EOF marker found, PEBs from 273 will be erased
[    5.811299] ubi0: scanning is finished
[    5.874546] gluebi (pid 1): gluebi_resized: got update notification for unknown UBI device 0 volume 1
[    5.892927] ubi0: volume 1 ("rootfs_data") re-sized from 9 to 28 LEBs
[    5.906683] ubi0: attached mtd7 (name "ubi", size 40 MiB)
[    5.917446] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[    5.931132] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[    5.944654] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[    5.958513] ubi0: good PEBs: 320, bad PEBs: 0, corrupted PEBs: 0
[    5.970472] ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
[    5.984859] ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1613475955
[    6.003045] ubi0: available PEBs: 0, total reserved PEBs: 320, PEBs reserved for bad PEB handling: 15
[    6.021426] rootfs: parsing partitions cmdlinepart
[    6.021444] ubi0: background thread "ubi_bgt0d" started, PID 97
[    6.043694] rootfs: got parser (null)
[    6.051426] mtd: device 12 (rootfs) set to be root filesystem
[    6.062891] rootfs_data: parsing partitions cmdlinepart
[    6.073669] rootfs_data: got parser (null)
[    6.211240] block ubiblock0_0: created from ubi0:0(rootfs)
[    6.259545] rtc-pcf8563 0-0051: hctosys: unable to read the hardware clock
[    6.282125] VFS: Cannot open root device "(null)" or unknown-block(31,12): error -6
[    6.297406] Please append a correct "root=" boot option; here are the available partitions:
[    6.314054] 1f00             512 mtdblock0
[    6.314060]  (driver?)
[    6.327077] 1f01             256 mtdblock1
[    6.327081]  (driver?)
[    6.340101] 1f02             256 mtdblock2
[    6.340105]  (driver?)
[    6.353124] 1f03             256 mtdblock3
[    6.353129]  (driver?)
[    6.366153] 1f04           45056 mtdblock4
[    6.366158]  (driver?)
[    6.379175] 1f05           40572 mtdblock5
[    6.379179]  (driver?)
[    6.392217] 1f06            4096 mtdblock6
[    6.392222]  (driver?)
[    6.405240] 1f07           40960 mtdblock7
[    6.405244]  (driver?)
[    6.418272] 1f08           32768 mtdblock8
[    6.418277]  (driver?)
[    6.431296] 1f09           40960 mtdblock9
[    6.431300]  (driver?)
[    6.444324] 1f0a            6144 mtdblock10
[    6.444328]  (driver?)
[    6.457518] 1f0b            4608 mtdblock11
[    6.457523]  (driver?)
[    6.470720] fe00           33604 ubiblock0_0
[    6.470724]  (driver?)
[    6.484090] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,12)
[    6.500892] Rebooting in 1 seconds..

```

bless,
g



Thanks,
Gagan


Thanks,
Gagan


^ permalink raw reply	[flat|nested] 41+ messages in thread
* Re: [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier
@ 2024-06-17 14:21 Gagan Sidhu
  0 siblings, 0 replies; 41+ messages in thread
From: Gagan Sidhu @ 2024-06-17 14:21 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-mtd

hi,

this patch isn’t a good one.

it must be reverted.

the problem with mr wang's changes is that it breaks expected mounting behaviour of a filesystem within an UBI, as is the case for openwrt.

i am surprised no one has raised the issue about this. i see mr raynal did raise an issue with one of mr zhihao’s fundamental errors:

https://lore.kernel.org/lkml/20231027194026.1bc32dfe@xps-13/

> Therefore, this problem can be avoided by preventing gluebi
> from creating mtdblock devices.

this is absolutely wrong.

typically what happens is we will wrap a squashfs filesystem inside a UBI layer. openwrt people call this “ubinising” the root filesystem.

then, after we label the appropriate nand partitions as ‘uimage,fw’ to call the right mtdsplit, the mtd_ubi subsystem works its magic automatically, as long as the root partition is named “rootfs”.

at that point, the rootfs will be *AUTOMATICALLY* mounted AND booted from BY THE KERNEL. that is, no cmdline hacks are required.

this patch breaks that behaviour since mr wang’s additional conditions result in the failure of the partition to get added to the mtd list, and thus fails mount.

i have attached a log of this behaviour. and by removing mr wang’s “fixes”, it mounts as we would expect.

this change must be reverted. extremely surprised the openwrt team has not raised issues over this by now.

```


3: System Boot system code via Flash.
## Booting image at bc180000 ...
   Image Name:   DD-WRT v24 Linux Kernel Imag
   Image Type:   MIPS Linux Kernel Image (lzma compressed)
   Data Size:    3875031 Bytes =  3.7 MB
   Load Address: 80001000
   Entry Point:  807d9e20
............................................................   Verifying Checksum ... OK
   Uncompressing Kernel Image ... OK
No initrd
## Transferring control to Linux (at address 807d9e20) ...
## Giving linux memsize in MB, 256

Starting kernel ...

[    0.000000] Linux version 4.14.348-openela-rt159 (
Gagan@GagansMacPro.local
) (gcc version 14.1.0 (GCC)) #5426 SMP Sat Jun 15 07:23:17 MDT 2024
[    0.000000] SoC Type: MediaTek MT7621 ver:1 eco:3
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 0001992f (MIPS 1004Kc)
[    0.000000] MIPS: machine is D-Link DIR-2640 rev. A1
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 10000000 @ 00000000 (usable)
[    0.000000] VPE topology {2,2} total 4
[    0.000000] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.000000] Zone ranges:
[    0.000000]   DMA      [mem 0x0000000000000000-0x0000000000ffffff]
[    0.000000]   Normal   [mem 0x0000000001000000-0x000000000fffffff]
[    0.000000]   HighMem  empty
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x000000000fffffff]
[    0.000000] percpu: Embedded 15 pages/cpu s30672 r8192 d22576 u61440
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 65024
[    0.000000] Kernel command line: console=ttyS0,57600n8
[    0.000000] log_buf_len individual max cpu contribution: 4096 bytes
[    0.000000] log_buf_len total cpu_extra contributions: 12288 bytes
[    0.000000] log_buf_len min size: 16384 bytes
[    0.000000] log_buf_len: 32768 bytes
[    0.000000] early log buf free: 14216(86%)
[    0.000000] PID hash table entries: 1024 (order: 0, 4096 bytes)
[    0.000000] Dentry cache hash table entries: 32768 (order: 5, 131072 bytes)
[    0.000000] Inode-cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Writing ErrCtl register=000412fa
[    0.000000] Readback ErrCtl register=000412fa
[    0.000000] Memory: 247980K/262144K available (8061K kernel code, 892K rwdata, 1568K rodata, 280K init, 733K bss, 14164K reserved, 0K cma-reserved, 0K highmem)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=4, Nodes=1
[    0.000000] Hierarchical RCU implementation.
[    0.000000] NR_IRQS: 256
[    0.000000] CPU Clock: 880MHz
[    0.000000] clocksource: GIC: mask: 0xffffffffffffffff max_cycles: 0xcaf478abb4, max_idle_ns: 440795247997 ns
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 4343773742 ns
[    0.000009] sched_clock: 32 bits at 440MHz, resolution 2ns, wraps every 4880645118ns
[    0.015565] Calibrating delay loop... 583.68 BogoMIPS (lpj=1167360)
[    0.055919] pid_max: default: 4096 minimum: 301
[    0.065064] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.078089] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.093805] Hierarchical SRCU implementation.
[    0.103082] smp: Bringing up secondary CPUs ...
[    0.113986] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.113994] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.114004] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.114122] CPU1 revision is: 0001992f (MIPS 1004Kc)
[    0.140246] Synchronize counters for CPU 1: done.
[    0.205804] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.205812] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.205818] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.205878] CPU2 revision is: 0001992f (MIPS 1004Kc)
[    0.239402] Synchronize counters for CPU 2: done.
[    0.300999] Primary instruction cache 32kB, VIPT, 4-way, linesize 32 bytes.
[    0.301006] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.301013] MIPS secondary cache 256kB, 8-way, linesize 32 bytes.
[    0.301082] CPU3 revision is: 0001992f (MIPS 1004Kc)
[    0.327024] Synchronize counters for CPU 3: done.
[    0.386624] smp: Brought up 1 node, 4 CPUs
[    0.395319] devtmpfs: initialized
[    0.405072] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 7645041785100000 ns
[    0.424361] futex hash table entries: 16 (order: -3, 512 bytes)
[    0.436154] pinctrl core: initialized pinctrl subsystem
[    0.447323] NET: Registered protocol family 16
[    0.456700] cpuidle: using governor menu
[    0.484220] pull PCIe RST: RALINK_RSTCTRL = 4000000
[    0.794105] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.804176] ***** Xtal 40MHz *****
[    0.810918] release PCIe RST: RALINK_RSTCTRL = 7000000
[    0.821113] Port 0 N_FTS = 1b105000
[    0.828025] Port 1 N_FTS = 1b105000
[    0.834937] Port 2 N_FTS = 1b102800
[    1.992951] PCIE2 no card, disable it(RST&CLK)
[    2.001641]  -> 21007f2
[    2.006479] PCIE0 enabled
[    2.011663] PCIE1 enabled
[    2.016858] PCI host bridge /pcie@1e140000 ranges:
[    2.026367]  MEM 0x0000000060000000..0x000000006fffffff
[    2.036726]   IO 0x000000001e160000..0x000000001e16ffff
[    2.047093] PCI coherence region base: 0x60000000, mask/settings: 0xf0000002
[    2.066762] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.078058] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.089214] mt7621_gpio 1e000600.gpio: registering 32 gpios
[    2.100683] vgaarb: loaded
[    2.106249] SCSI subsystem initialized
[    2.113766] usbcore: registered new interface driver usbfs
[    2.124606] usbcore: registered new interface driver hub
[    2.135129] usbcore: registered new device driver usb
[    2.145477] i2c-mt7621 1e000900.i2c: clock 100KHz, re-start not support
[    2.158813] PCI host bridge to bus 0000:00
[    2.166839] pci_bus 0000:00: root bus resource [mem 0x60000000-0x6fffffff]
[    2.180477] pci_bus 0000:00: root bus resource [io  0x1e160000-0x1e16ffff]
[    2.194129] pci_bus 0000:00: root bus resource [??? 0x00000000 flags 0x0]
[    2.207606] pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
[    2.224155] pci 0000:01:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x1 link at 0000:00:00.0 (capable of 4.000 Gb/s with 5 GT/s x1 link)
[    2.251939] pci 0000:02:00.0: 2.000 Gb/s available PCIe bandwidth, limited by 2.5 GT/s x1 link at 0000:00:01.0 (capable of 4.000 Gb/s with 5 GT/s x1 link)
[    2.279470] pci 0000:00:00.0: BAR 0: no space for [mem size 0x80000000]
[    2.292494] pci 0000:00:00.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.306313] pci 0000:00:01.0: BAR 0: no space for [mem size 0x80000000]
[    2.319449] pci 0000:00:01.0: BAR 0: failed to assign [mem size 0x80000000]
[    2.333277] pci 0000:00:00.0: BAR 8: assigned [mem 0x60000000-0x600fffff]
[    2.346755] pci 0000:00:01.0: BAR 8: assigned [mem 0x60100000-0x601fffff]
[    2.360233] pci 0000:00:00.0: BAR 1: assigned [mem 0x60200000-0x6020ffff]
[    2.373709] pci 0000:00:01.0: BAR 1: assigned [mem 0x60210000-0x6021ffff]
[    2.387208] pci 0000:01:00.0: BAR 0: assigned [mem 0x60000000-0x600fffff 64bit]
[    2.401712] pci 0000:00:00.0: PCI bridge to [bus 01]
[    2.411548] pci 0000:00:00.0:   bridge window [mem 0x60000000-0x600fffff]
[    2.425039] pci 0000:02:00.0: BAR 0: assigned [mem 0x60100000-0x601fffff 64bit]
[    2.439555] pci 0000:00:01.0: PCI bridge to [bus 02]
[    2.449396] pci 0000:00:01.0:   bridge window [mem 0x60100000-0x601fffff]
[    2.463554] clocksource: Switched to clocksource GIC
[    2.474753] NET: Registered protocol family 2
[    2.483561] IP idents hash table entries: 4096 (order: 3, 32768 bytes)
[    2.497245] TCP established hash table entries: 2048 (order: 1, 8192 bytes)
[    2.511002] TCP bind hash table entries: 2048 (order: 2, 16384 bytes)
[    2.523798] TCP: Hash tables configured (established 2048 bind 2048)
[    2.536493] UDP hash table entries: 128 (order: 0, 4096 bytes)
[    2.547983] UDP-Lite hash table entries: 128 (order: 0, 4096 bytes)
[    2.560657] NET: Registered protocol family 1
[    2.659518] 4 CPUs re-calibrate udelay(lpj = 1163264)
[    2.670337] workingset: timestamp_bits=30 max_order=16 bucket_order=0
[    2.689246] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    2.709543] io scheduler noop registered
[    2.717554] io scheduler cfq registered (default)
[    2.726769] io scheduler mq-deadline registered
[    2.735774] io scheduler kyber registered
[    2.744477] mtk_hsdma 1e007000.hsdma: Using 3 as missing dma-requests property
[    2.758985] mtk_hsdma 1e007000.hsdma: MediaTek HSDMA driver registered
[    2.823896] serial8250_init
[    2.829315] Serial: 8250/16550 driver, 2 ports, IRQ sharing disabled
[    2.843297] console [ttyS0] disabled
[    2.850333] 1e000c00.uartlite: ttyS0 at MMIO 0x1e000c00 (irq = 19, base_baud = 3125000) is a 16550A
[    2.868297] console [ttyS0] enabled
[    2.868297] console [ttyS0] enabled
[    2.882070] bootconsole [early0] disabled
[    2.882070] bootconsole [early0] disabled
[    2.898446] Ralink gpio driver initialized:power_gpio[8]
[    2.910106] MediaTek Nand driver init, version v2.1 Fix AHB virt2phys error
[    2.924094] Enable NFI Clock
[    2.929829] # MTK NAND # : Use HW ECC
[    2.937139] Device not found, ID: c8d1
[    2.944610] Not Support this Device!
[    2.952075] chip_mode=00000001
[    2.958157] Support this Device in MTK table! c8d1
[    2.968055] [NAND]select ecc bit:4, sparesize :64 spare_per_sector=16
[    2.980930] nand: device found, Manufacturer ID: 0xc8, Chip ID: 0xd1
[    2.993590] nand: ESMT NAND 128MiB 3,3V 8-bit
[    3.002281] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
[    3.017376] Scanning device for bad blocks
[    3.169277] MT7621-NAND: parsing partitions cmdlinepart
[    3.180264] MT7621-NAND: got parser (null)
[    3.188484] 9 fixed-partitions partitions found on MTD device MT7621-NAND
[    3.202005] Creating 9 MTD partitions on "MT7621-NAND":
[    3.212430] 0x000000000000-0x000000080000 : "Bootloader"
[    3.224024] 0x0000000c0000-0x000000100000 : "Config"
[    3.234684] 0x000000100000-0x000000140000 : "Factory"
[    3.245518] 0x000000140000-0x000000180000 : "Config2"
[    3.256379] 0x000000180000-0x000002d80000 : "sysv"
[    3.895176] 1 squashfs-split partitions found on MTD device sysv
[    3.907164] 0x0000005c1000-0x000002d60000 : "ddwrt"
[    3.920925] 2 uimage-fw partitions found on MTD device sysv
[    3.932031] Creating 2 MTD partitions on "sysv":
[    3.941232] 0x000000000000-0x000000400000 : "kernel"
[    3.951995] 0x000000400000-0x000002c00000 : "ubi"
[    3.962325] 0x000002d80000-0x000004d80000 : "private"
[    3.973322] 0x000004d80000-0x000007580000 : "firmware2"
[    3.984759] 0x000007580000-0x000007b80000 : "mydlink"
[    3.995699] 0x000007b80000-0x000008000000 : "reserved"
[    4.006687] [mtk_nand] probe successfully!
[    4.015584] Signature matched and data read!
[    4.024090] load_fact_bbt success 1023
[    4.031931] tun: Universal TUN/TAP device driver, 1.6
[    4.042377] CHIP_ID = MT7621
[    4.048133] WAN at P4
[    4.052659] GMAC1 support rgmii
[    4.058911] GE1_RGMII_FORCE_1000
[    4.065348] GMAC2 support rgmii
[    4.071606] RGMII_AN (Internal GigaPhy)
[    4.079973] STD_v0.1  1024 rx/2048 tx descriptors allocated, mtu = 1500!
[    4.094358] set CLK_CFG_0 = 0x40a00020!!!!!!!!!!!!!!!!!!1
[    4.105108] trgmii_set_7621 Completed!!
[    4.324297] MT7530 Reset Completed!!
[    4.340754] trgmii_set_7530 Completed!!
[    4.348739] change HW-TRAP to 0x17c8f
[    4.360357] set LAN/WAN LLLLW
[    4.374100] eth3: ===> virtualif_open
[    4.381646] == MT7530 MCM ==
[    4.387482] PPP generic driver version 2.4.2
[    4.396233] PPP BSD Compression module registered
[    4.405603] PPP Deflate Compression module registered
[    4.415687] PPP MPPE Compression module registered
[    4.425229] NET: Registered protocol family 24
[    4.434106] register mt_drv
[    4.439738] bus=0x1, slot = 0x0, irq=0x0
[    4.472239]
[    4.472239] == pAd = c0181000, size = 6632704, Status=0 ==
[    4.486132] pAd->PciHif.CSRBaseAddress =0xc0080000, csr_addr=0xc0080000!
[    4.499531] RTMPInitPCIeDevice():device_id=0x7615
[    4.508911] mt_pci_chip_cfg(): HWVer=0x8a10, FWVer=0x8a10, pAd->ChipID=0x7615
[    4.523136] mt_pci_chip_cfg(): HIF_SYS_REV=0x76150001
[    4.533196] AP Driver version-5.1.0.0
[    4.540493] RtmpChipOpsHook(223): Not support for HIF_MT yet! MACVersion=0x0
[    4.554527] mt7615_init()-->
[    4.560266] Use 1st ePAeLNA default bin.
[    4.568078] Use 0st /etc/wlan/mt7615e.eeprom.bin default bin.
[    4.579550] <--mt7615_init()
[    4.589234] <-- RTMPAllocTxRxRingMemory, Status=0
[    4.599438] bus=0x2, slot = 0x1, irq=0x0
[    4.631995]
[    4.631995] == pAd = c0901000, size = 6632704, Status=0 ==
[    4.645884] pAd->PciHif.CSRBaseAddress =0xc0800000, csr_addr=0xc0800000!
[    4.659234] RTMPInitPCIeDevice():device_id=0x7615
[    4.668612] mt_pci_chip_cfg(): HWVer=0x8a10, FWVer=0x8a10, pAd->ChipID=0x7615
[    4.682820] mt_pci_chip_cfg(): HIF_SYS_REV=0x76150001
[    4.692879] AP Driver version-5.1.0.0
[    4.700175] RtmpChipOpsHook(223): Not support for HIF_MT yet! MACVersion=0x0
[    4.714208] mt7615_init()-->
[    4.719946] Use 2nd ePAeLNA default bin.
[    4.727767] Use 1st /etc/wlan/mt7615e.eeprom.bin default bin.
[    4.739224] <--mt7615_init()
[    4.748896] <-- RTMPAllocTxRxRingMemory, Status=0
[    4.759057] rdm_major = 255
[    4.765124] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    4.775743] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus number 1
[    4.799681] xhci-mtk 1e1c0000.xhci: hcc params 0x01401198 hci version 0x96 quirks 0x0000000000290010
[    4.817950] xhci-mtk 1e1c0000.xhci: irq 22, io mem 0x1e1c0000
[    4.830260] hub 1-0:1.0: USB hub found
[    4.837822] hub 1-0:1.0: 2 ports detected
[    4.846283] xhci-mtk 1e1c0000.xhci: xHCI Host Controller
[    4.856910] xhci-mtk 1e1c0000.xhci: new USB bus registered, assigned bus number 2
[    4.871846] xhci-mtk 1e1c0000.xhci: Host supports USB 3.0  SuperSpeed
[    4.884885] usb usb2: We don't know the algorithms for LPM for this host, disabling LPM.
[    4.901675] hub 2-0:1.0: USB hub found
[    4.909226] hub 2-0:1.0: 1 port detected
[    4.917608] usbcore: registered new interface driver usblp
[    4.928659] usbcore: registered new interface driver usb-storage
[    4.940727] usbcore: registered new interface driver usbserial
[    5.007737] rtc-pcf8563 0-0051: registered as rtc0
[    5.031606] i2c /dev entries driver
[    5.038842] Ralink APSoC Hardware Watchdog Timer
[    5.049311] usbcore: registered new interface driver usbhid
[    5.060419] usbhid: USB HID core driver
[    5.068615] u32 classifier
[    5.074005]     Performance counters on
[    5.081638]     Actions configured
[    5.088434] Netfilter messages via NETLINK v0.30.
[    5.098071] nf_conntrack version 0.5.0 (4096 buckets, 16384 max)
[    5.110321] ctnetlink v0.93: registering with nfnetlink.
[    5.121402] ipip: IPv4 and MPLS over IPv4 tunneling driver
[    5.132985] ip_tables: (C) 2000-2006 Netfilter Core Team
[    5.144546] NET: Registered protocol family 10
[    5.155889] Segment Routing with IPv6
[    5.163303] NET: Registered protocol family 17
[    5.172292] Bridge firewalling registered
[    5.180281] 8021q: 802.1Q VLAN Support v1.8
[    5.189452] registered taskstats version 1
[    5.198914] searching for nvram
[    5.279016] found nvram at 0, name:Config, contributed bytes:262144
[    5.328401] nvram empty
[    5.407013] found nvram at 1, name:Config2, contributed bytes:262144
[    5.456567] nvram empty
[    5.462504] auto-attach mtd7
[    5.462525] ubi0: default fastmap pool size: 15
[    5.477309] ubi0: default fastmap WL pool size: 7
[    5.486683] ubi0: attaching mtd7
[    5.811240] UBI: EOF marker found, PEBs from 273 will be erased
[    5.811299] ubi0: scanning is finished
[    5.874546] gluebi (pid 1): gluebi_resized: got update notification for unknown UBI device 0 volume 1
[    5.892927] ubi0: volume 1 ("rootfs_data") re-sized from 9 to 28 LEBs
[    5.906683] ubi0: attached mtd7 (name "ubi", size 40 MiB)
[    5.917446] ubi0: PEB size: 131072 bytes (128 KiB), LEB size: 126976 bytes
[    5.931132] ubi0: min./max. I/O unit sizes: 2048/2048, sub-page size 2048
[    5.944654] ubi0: VID header offset: 2048 (aligned 2048), data offset: 4096
[    5.958513] ubi0: good PEBs: 320, bad PEBs: 0, corrupted PEBs: 0
[    5.970472] ubi0: user volume: 2, internal volumes: 1, max. volumes count: 128
[    5.984859] ubi0: max/mean erase counter: 1/0, WL threshold: 4096, image sequence number: 1613475955
[    6.003045] ubi0: available PEBs: 0, total reserved PEBs: 320, PEBs reserved for bad PEB handling: 15
[    6.021426] rootfs: parsing partitions cmdlinepart
[    6.021444] ubi0: background thread "ubi_bgt0d" started, PID 97
[    6.043694] rootfs: got parser (null)
[    6.051426] mtd: device 12 (rootfs) set to be root filesystem
[    6.062891] rootfs_data: parsing partitions cmdlinepart
[    6.073669] rootfs_data: got parser (null)
[    6.211240] block ubiblock0_0: created from ubi0:0(rootfs)
[    6.259545] rtc-pcf8563 0-0051: hctosys: unable to read the hardware clock
[    6.282125] VFS: Cannot open root device "(null)" or unknown-block(31,12): error -6
[    6.297406] Please append a correct "root=" boot option; here are the available partitions:
[    6.314054] 1f00             512 mtdblock0
[    6.314060]  (driver?)
[    6.327077] 1f01             256 mtdblock1
[    6.327081]  (driver?)
[    6.340101] 1f02             256 mtdblock2
[    6.340105]  (driver?)
[    6.353124] 1f03             256 mtdblock3
[    6.353129]  (driver?)
[    6.366153] 1f04           45056 mtdblock4
[    6.366158]  (driver?)
[    6.379175] 1f05           40572 mtdblock5
[    6.379179]  (driver?)
[    6.392217] 1f06            4096 mtdblock6
[    6.392222]  (driver?)
[    6.405240] 1f07           40960 mtdblock7
[    6.405244]  (driver?)
[    6.418272] 1f08           32768 mtdblock8
[    6.418277]  (driver?)
[    6.431296] 1f09           40960 mtdblock9
[    6.431300]  (driver?)
[    6.444324] 1f0a            6144 mtdblock10
[    6.444328]  (driver?)
[    6.457518] 1f0b            4608 mtdblock11
[    6.457523]  (driver?)
[    6.470720] fe00           33604 ubiblock0_0
[    6.470724]  (driver?)
[    6.484090] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(31,12)
[    6.500892] Rebooting in 1 seconds..

```

bless,
g



Thanks,
Gagan


^ permalink raw reply	[flat|nested] 41+ messages in thread
* [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier
@ 2023-10-18 12:16 ZhaoLong Wang
  2023-10-19  1:57 ` Zhihao Cheng
  2023-10-19 20:27 ` Richard Weinberger
  0 siblings, 2 replies; 41+ messages in thread
From: ZhaoLong Wang @ 2023-10-18 12:16 UTC (permalink / raw)
  To: richard, miquel.raynal, vigneshr, dpervushin, Artem.Bityutskiy
  Cc: linux-mtd, linux-kernel, chengzhihao1, wangzhaolong1, yi.zhang,
	yangerkun

If both flt.ko and gluebi.ko are loaded, the notiier 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
                            mtd_read_oob
                              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 accesses 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 value of gluebi->desc may also be a negative error code, which
triggers the page fault error.

This patch has the following modifications:

1. Do not assign gluebi->desc to the error code. Use the NULL instead.

2. Always check the validity of gluebi->desc in gluebi_read() If the
   gluebi->desc is NULL, try to get MTD device.

Such a modification currently works because the mutex "mtd_table_mutex"
is held on all necessary paths, including the ftl_add_mtd() call path,
open and close paths. Therefore, many race condition can be avoided.

Fixes: 2ba3d76a1e29 ("UBI: make gluebi a separate module")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=217992 [1]
Signed-off-by: ZhaoLong Wang <wangzhaolong1@huawei.com>
---
 drivers/mtd/ubi/gluebi.c | 37 +++++++++++++++++++++++++++++++------
 1 file changed, 31 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 1b980d15d9fb..0ca7f104adbf 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -85,6 +85,7 @@ static int gluebi_get_device(struct mtd_info *mtd)
 {
 	struct gluebi_device *gluebi;
 	int ubi_mode = UBI_READONLY;
+	struct ubi_volume_desc *vdesc;
 
 	if (mtd->flags & MTD_WRITEABLE)
 		ubi_mode = UBI_READWRITE;
@@ -109,12 +110,14 @@ static int gluebi_get_device(struct mtd_info *mtd)
 	 * This is the first reference to this UBI volume via the MTD device
 	 * interface. Open the corresponding volume in read-write mode.
 	 */
-	gluebi->desc = ubi_open_volume(gluebi->ubi_num, gluebi->vol_id,
+	vdesc = ubi_open_volume(gluebi->ubi_num, gluebi->vol_id,
 				       ubi_mode);
-	if (IS_ERR(gluebi->desc)) {
+	if (IS_ERR(vdesc)) {
+		gluebi->desc = NULL;
 		mutex_unlock(&devices_mutex);
-		return PTR_ERR(gluebi->desc);
+		return PTR_ERR(vdesc);
 	}
+	gluebi->desc = vdesc;
 	gluebi->refcnt += 1;
 	mutex_unlock(&devices_mutex);
 	return 0;
@@ -134,8 +137,10 @@ static void gluebi_put_device(struct mtd_info *mtd)
 	gluebi = container_of(mtd, struct gluebi_device, mtd);
 	mutex_lock(&devices_mutex);
 	gluebi->refcnt -= 1;
-	if (gluebi->refcnt == 0)
+	if (gluebi->refcnt == 0) {
 		ubi_close_volume(gluebi->desc);
+		gluebi->desc = NULL;
+	}
 	mutex_unlock(&devices_mutex);
 }
 
@@ -154,9 +159,26 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
 		       size_t *retlen, unsigned char *buf)
 {
 	int err = 0, lnum, offs, bytes_left;
-	struct gluebi_device *gluebi;
+	struct gluebi_device *gluebi = container_of(mtd, struct gluebi_device,
+						    mtd);
+	int no_desc = gluebi->desc == NULL ? 1 : 0;
+
+	/**
+	 * In normal case, the UBI volume desc has been initialized by
+	 * ->_get_device(). However, in the ftl notifier process, the
+	 * ->_get_device() is not executed in advance and the MTD device
+	 * is directly scanned which cause NULL pointer dereference.
+	 * Therefore, try to get the MTD device here.
+	 */
+	if (unlikely(no_desc)) {
+		err = __get_mtd_device(mtd);
+		if (err) {
+			err_msg("cannot get MTD device %d, UBI device %d, volume %d, error %d",
+				mtd->index, gluebi->ubi_num, gluebi->vol_id, err);
+			return err;
+		}
+	}
 
-	gluebi = container_of(mtd, struct gluebi_device, mtd);
 	lnum = div_u64_rem(from, mtd->erasesize, &offs);
 	bytes_left = len;
 	while (bytes_left) {
@@ -176,6 +198,9 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
 	}
 
 	*retlen = len - bytes_left;
+
+	if (unlikely(no_desc))
+		__put_mtd_device(mtd);
 	return err;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 41+ messages in thread

end of thread, other threads:[~2024-06-24 19:00 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-17 14:25 [PATCH v2] ubi: gluebi: Fix NULL pointer dereference caused by ftl notifier Gagan Sidhu
2024-06-17 14:31 ` Richard Weinberger
2024-06-17 15:42 ` Richard Weinberger
     [not found]   ` <14779870-BA54-4ABF-8ABF-FF1D23D172A7@mac.com>
2024-06-17 16:00     ` Richard Weinberger
2024-06-17 16:05       ` Gagan Sidhu
2024-06-17 16:52         ` Richard Weinberger
     [not found]           ` <E3E2C13C-1E52-46F2-BE2D-D2592C3369DB@mac.com>
2024-06-17 17:33             ` Gagan Sidhu
2024-06-17 17:48               ` Gagan Sidhu
2024-06-17 18:09                 ` Richard Weinberger
2024-06-17 18:18                   ` Gagan Sidhu
2024-06-17 18:32                     ` Richard Weinberger
2024-06-17 18:46                       ` Gagan Sidhu
2024-06-17 18:52                         ` Richard Weinberger
2024-06-17 20:29                           ` Daniel Golle
2024-06-17 21:22                             ` Gagan Sidhu
2024-06-17 22:13                               ` Gagan Sidhu
2024-06-18  4:03                                 ` Zhihao Cheng
2024-06-20 22:06                                   ` Gagan Sidhu
2024-06-21  1:59                                     ` Zhihao Cheng
2024-06-21  2:09                                       ` Gagan Sidhu
2024-06-21  3:03                                         ` Zhihao Cheng
2024-06-21  4:27                                           ` Gagan Sidhu
2024-06-21  4:55                                             ` Zhihao Cheng
2024-06-21 11:36                                               ` Gagan Sidhu
2024-06-22  2:37                                                 ` Zhihao Cheng
2024-06-22  2:43                                                   ` Gagan Sidhu
2024-06-22 21:07                                                     ` Daniel Golle
2024-06-24 19:00                                                       ` Gagan Sidhu
  -- strict thread matches above, loose matches on Subject: below --
2024-06-17 14:21 Gagan Sidhu
2023-10-18 12:16 ZhaoLong Wang
2023-10-19  1:57 ` Zhihao Cheng
2023-10-19 20:27 ` Richard Weinberger
2023-10-20  2:27   ` Zhihao Cheng
2023-10-21 16:09     ` Richard Weinberger
2023-10-23  6:41       ` ZhaoLong Wang
2023-10-23  6:46         ` Richard Weinberger
2023-10-23  7:12           ` ZhaoLong Wang
2023-10-23  7:16             ` Richard Weinberger
2023-10-23  7:09       ` Zhihao Cheng
2023-10-23  7:15         ` Richard Weinberger
2023-10-23  7:36           ` Zhihao Cheng

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox