linux-stable/drivers
Md Sadre Alam c63fbe063f mtd: rawnand: qcom: fix memory corruption that causes panic
commit ba7542eb2d upstream.

This patch fixes a memory corruption that occurred in the
nand_scan() path for Hynix nand device.

On boot, for Hynix nand device will panic at a weird place:
| Unable to handle kernel NULL pointer dereference at virtual
  address 00000070
| [00000070] *pgd=00000000
| Internal error: Oops: 5 [#1] PREEMPT SMP ARM
| Modules linked in:
| CPU: 0 PID: 1 Comm: swapper/0 Not tainted 5.17.0-01473-g13ae1769cfb0
  #38
| Hardware name: Generic DT based system
| PC is at nandc_set_reg+0x8/0x1c
| LR is at qcom_nandc_command+0x20c/0x5d0
| pc : [<c088b74c>]    lr : [<c088d9c8>]    psr: 00000113
| sp : c14adc50  ip : c14ee208  fp : c0cc970c
| r10: 000000a3  r9 : 00000000  r8 : 00000040
| r7 : c16f6a00  r6 : 00000090  r5 : 00000004  r4 :c14ee040
| r3 : 00000000  r2 : 0000000b  r1 : 00000000  r0 :c14ee040
| Flags: nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM Segment none
| Control: 10c5387d  Table: 8020406a  DAC: 00000051
| Register r0 information: slab kmalloc-2k start c14ee000 pointer offset
  64 size 2048
| Process swapper/0 (pid: 1, stack limit = 0x(ptrval))
| nandc_set_reg from qcom_nandc_command+0x20c/0x5d0
| qcom_nandc_command from nand_readid_op+0x198/0x1e8
| nand_readid_op from hynix_nand_has_valid_jedecid+0x30/0x78
| hynix_nand_has_valid_jedecid from hynix_nand_init+0xb8/0x454
| hynix_nand_init from nand_scan_with_ids+0xa30/0x14a8
| nand_scan_with_ids from qcom_nandc_probe+0x648/0x7b0
| qcom_nandc_probe from platform_probe+0x58/0xac

The problem is that the nand_scan()'s qcom_nand_attach_chip callback
is updating the nandc->max_cwperpage from 1 to 4 or 8 based on page size.
This causes the sg_init_table of clear_bam_transaction() in the driver's
qcom_nandc_command() to memset much more than what was initially
allocated by alloc_bam_transaction().

This patch will update nandc->max_cwperpage 1 to 4 or 8 based on page
size in qcom_nand_attach_chip call back after freeing the previously
allocated memory for bam txn as per nandc->max_cwperpage = 1 and then
again allocating bam txn as per nandc->max_cwperpage = 4 or 8 based on
page size in qcom_nand_attach_chip call back itself.

Cc: stable@vger.kernel.org
Fixes: 6a3cec64f1 ("mtd: rawnand: qcom: convert driver to nand_scan()")
Reported-by: Konrad Dybcio <konrad.dybcio@somainline.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Co-developed-by: Sricharan R <quic_srichara@quicinc.com>
Signed-off-by: Sricharan R <quic_srichara@quicinc.com>
Signed-off-by: Md Sadre Alam <quic_mdalam@quicinc.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/1650268107-5363-1-git-send-email-quic_mdalam@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-05-09 09:14:41 +02:00
..
accessibility speakup-dectlk: Restore pitch setting 2022-02-16 12:56:37 +01:00
acpi Revert "ACPI: processor: idle: fix lockup regression on 32-bit ThinkPad T40" 2022-05-09 09:14:41 +02:00
amba
android
ata ata: pata_marvell: Check the 'bmdma_addr' beforing reading 2022-04-27 14:38:58 +02:00
atm atm: eni: Add check for dma_map_single 2022-03-23 09:16:41 +01:00
auxdisplay auxdisplay: lcd2s: Use proper API to free the instance of charlcd object 2022-03-08 19:12:47 +01:00
base arch_topology: Do not set llc_sibling if llc_id is invalid 2022-05-09 09:14:30 +02:00
bcma
block floppy: disable FDRAWCMD by default 2022-05-01 17:22:22 +02:00
bluetooth Bluetooth: btmtksdio: Fix kernel oops in btmtksdio_interrupt 2022-04-08 14:23:41 +02:00
bus bus: sunxi-rsb: Fix the return value of sunxi_rsb_device_create() 2022-05-09 09:14:37 +02:00
cdrom
char virtio_console: eliminate anonymous module_init & module_exit 2022-04-13 20:59:13 +02:00
clk clk: sunxi: sun9i-mmc: check return value after calling platform_get_resource() 2022-05-09 09:14:37 +02:00
clocksource clocksource: acpi_pm: fix return value of __setup handler 2022-04-08 14:23:09 +02:00
comedi
connector
counter
cpufreq cpufreq: qcom-cpufreq-hw: Clear dcvs interrupts 2022-05-09 09:14:37 +02:00
cpuidle
crypto crypto: hisilicon/sec - not need to enable sm4 extra mode at HW V3 2022-04-08 14:23:55 +02:00
cxl cxl/regs: Fix size of CXL Capability Header Register 2022-04-08 14:23:30 +02:00
dax dax: make sure inodes are flushed before destroy cache 2022-04-08 14:23:31 +02:00
dca
devfreq
dio
dma dmaengine: imx-sdma: fix init of uart scripts 2022-04-27 14:38:58 +02:00
dma-buf udmabuf: validate ubuf->pagecount 2022-04-08 14:23:24 +02:00
edac EDAC/synopsys: Read the error count from the correct register 2022-04-27 14:38:57 +02:00
eisa
extcon
firewire
firmware firmware: arm_scmi: Fix sorting of retrieved clock rates 2022-04-20 09:34:09 +02:00
fpga
fsi fsi: Aspeed: Fix a potential double free 2022-04-08 14:23:44 +02:00
gnss
gpio gpio: Request interrupts after IRQ is initialized 2022-04-27 14:39:00 +02:00
gpu drm/amd/display: Fix memory leak in dcn21_clock_source_create 2022-05-09 09:14:38 +02:00
greybus greybus: svc: fix an error handling bug in gb_svc_hello() 2022-04-08 14:22:50 +02:00
hid HID: i2c-hid: fix GET/SET_REPORT for unnumbered reports 2022-04-08 14:23:31 +02:00
hsi
hv Drivers: hv: balloon: Disable balloon and hot-add accordingly 2022-04-20 09:34:16 +02:00
hwmon hwmon: (pmbus) Add Vin unit off handling 2022-04-08 14:23:09 +02:00
hwspinlock
hwtracing coresight: syscfg: Fix memleak on registration failure in cscfg_create_device 2022-04-08 14:22:50 +02:00
i2c i2c: pasemi: Wait for write xfers to finish 2022-04-20 09:34:21 +02:00
i3c i3c: master: dw: check return of dw_i3c_master_get_free_pos() 2022-03-08 19:12:37 +01:00
idle
iio iio:imu:bmi160: disable regulator in error path 2022-05-09 09:14:31 +02:00
infiniband RDMA/hfi1: Fix use-after-free bug for mm struct 2022-04-13 20:59:23 +02:00
input Input: omap4-keypad - fix pm_runtime_get_sync() error checking 2022-04-27 14:38:58 +02:00
interconnect interconnect: qcom: sdx55: Drop IP0 interconnects 2022-05-09 09:14:33 +02:00
iommu iommu/omap: Fix regression in probe for NULL pointer dereference 2022-04-13 20:59:20 +02:00
ipack
irqchip irqchip/gic, gic-v3: Prevent GSI to SGI translations 2022-04-13 20:59:28 +02:00
isdn isdn: hfcpci: check the return value of dma_set_mask() in setup_hw() 2022-03-16 14:23:36 +01:00
leds
macintosh
mailbox mailbox: imx: fix wakeup failure from freeze mode 2022-04-08 14:24:10 +02:00
mcb
md dm integrity: fix memory corruption when tag_size is less than digest size 2022-04-20 09:34:20 +02:00
media media: rockchip/rga: do proper error checking in probe 2022-04-20 09:34:09 +02:00
memory memory: renesas-rpc-if: Fix HF/OSPI data transfer in Manual Mode 2022-05-09 09:14:34 +02:00
memstick
message
mfd mfd: asic3: Add missing iounmap() on error asic3_mfd_probe 2022-04-08 14:23:43 +02:00
misc habanalabs: fix possible memory leak in MMU DR fini 2022-04-13 20:59:12 +02:00
mmc mmc: core: Fixup support for writeback-cache for eMMC and SD 2022-04-13 20:59:21 +02:00
most
mtd mtd: rawnand: qcom: fix memory corruption that causes panic 2022-05-09 09:14:41 +02:00
mux
net drivers: net: hippi: Fix deadlock in rr_close() 2022-05-09 09:14:40 +02:00
nfc nfc: st21nfca: Fix potential buffer overflows in EVT_TRANSACTION 2022-03-28 09:58:42 +02:00
ntb ntb: intel: fix port config status offset for SPR 2022-03-08 19:12:44 +01:00
nubus
nvdimm nvdimm/region: Fix default alignment for small regions 2022-04-08 14:23:48 +02:00
nvme nvme-pci: disable namespace identifiers for Qemu controllers 2022-04-27 14:38:57 +02:00
nvmem nvmem: core: Fix a conflict between MTD and NVMEM on wp-gpios property 2022-03-02 11:48:06 +01:00
of of: net: move of_net under net/ 2022-03-08 19:12:41 +01:00
opp opp: Expose of-node's name in debugfs 2022-04-13 20:59:11 +02:00
parisc parisc: Fix CPU affinity for Lasi, WAX and Dino chips 2022-04-13 20:59:14 +02:00
parport
pci PCI: hv: Propagate coherence from VMbus device to PCI device 2022-04-20 09:34:15 +02:00
pcmcia
perf arm_pmu: Validate single/group leader events 2022-04-27 14:39:00 +02:00
phy phy: amlogic: fix error path in phy_g12a_usb3_pcie_probe() 2022-05-09 09:14:34 +02:00
pinctrl pinctrl: pistachio: fix use of irq_of_parse_and_map() 2022-05-09 09:14:36 +02:00
platform platform/x86: samsung-laptop: Fix an unsigned comparison which can never be negative 2022-04-27 14:38:55 +02:00
pnp
power power: supply: axp288-charger: Set Vhold to 4.4V 2022-04-13 20:59:05 +02:00
powercap
pps pps: clients: gpio: Propagate return value from pps_gpio_probe 2022-04-08 14:23:44 +02:00
ps3
ptp ptp: replace snprintf with sysfs_emit 2022-04-13 20:59:01 +02:00
pwm pwm: lpc18xx-sct: Initialize driver data and hardware before pwmchip_add() 2022-04-08 14:23:44 +02:00
rapidio
ras
regulator regulator: wm8994: Add an off-on delay for WM8994 variant 2022-04-20 09:34:16 +02:00
remoteproc remoteproc: qcom_q6v5_mss: Fix some leaks in q6v5_alloc_memory_region 2022-04-08 14:23:47 +02:00
reset reset: tegra-bpmp: Restore Handle errors in BPMP response 2022-04-27 14:38:55 +02:00
rpmsg rpmsg: char: Fix race between the release of rpmsg_eptdev and cdev 2022-02-01 17:27:07 +01:00
rtc rtc: mc146818-lib: fix signedness bug in mc146818_get_time() 2022-04-13 20:59:26 +02:00
s390 block: drop unused includes in <linux/genhd.h> 2022-03-16 14:23:46 +01:00
sbus
scsi scsi: sr: Do not leak information in ioctl 2022-04-27 14:38:58 +02:00
sh
siox
slimbus
soc soc: qcom: aoss: Fix missing put_device call in qmp_get 2022-04-20 09:34:21 +02:00
soundwire ASoC: Intel: sof_sdw: fix quirks for 2022 HP Spectre x360 13" 2022-04-08 14:24:02 +02:00
spi spi: cadence-quadspi: fix write completion support 2022-05-01 17:22:27 +02:00
spmi
ssb
staging staging: wfx: fix an error handling in wfx_init_common() 2022-04-13 20:59:11 +02:00
target scsi: target: tcmu: Fix possible page UAF 2022-04-20 09:34:15 +02:00
tc
tee optee: use driver internal tee_context for some rpc 2022-03-02 11:47:51 +01:00
thermal thermal: int340x: Check for NULL after calling kmemdup() 2022-04-08 14:23:05 +02:00
thunderbolt
tty serial: 8250: Correct the clock for EndRun PTP/1588 PCIe device 2022-05-09 09:14:30 +02:00
uio
usb USB: Fix xhci event ring dequeue pointer ERDP update issue 2022-05-09 09:14:32 +02:00
vdpa vdpa: mlx5: prevent cvq work from hogging CPU 2022-04-13 20:59:15 +02:00
vfio vfio/pci: Fix vf_token mechanism when device-specific VF drivers are used 2022-04-20 09:34:13 +02:00
vhost tuntap: add sanity checks about msg_controllen in sendmsg 2022-04-13 20:59:07 +02:00
video video: fbdev: udlfb: properly check endpoint type 2022-05-09 09:14:31 +02:00
virt virt: acrn: fix a memory leak in acrn_dev_ioctl() 2022-04-08 14:23:50 +02:00
virtio virtio: acknowledge all features before access 2022-03-16 14:23:43 +01:00
visorbus
vlynq
vme
w1 w1: w1_therm: fixes w1_seq for ds28ea00 sensors 2022-04-13 20:59:11 +02:00
watchdog watchdog: rti-wdt: Add missing pm_runtime_disable() in probe function 2022-04-08 14:24:11 +02:00
xen swiotlb: Support aligned swiotlb buffers 2022-04-08 14:24:17 +02:00
zorro
Kconfig
Makefile