Skip to content

Null pointer dereference on concurrent VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF ioctl #6701

Open
@dividuum

Description

@dividuum

Describe the bug

I've observed kernel null pointer dereferences while using the VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF ioctl. A traceback might look like this:

[  634.185377] ---[ end trace 0000000000000000 ]---
[  634.185400] hwmon hwmon1: Failed to get throttled (-110)
[  645.781772] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000008
[  645.781801] Mem abort info:
[  645.781806]   ESR = 0x0000000096000046
[  645.781812]   EC = 0x25: DABT (current EL), IL = 32 bits
[  645.781819]   SET = 0, FnV = 0
[  645.781826]   EA = 0, S1PTW = 0
[  645.781831]   FSC = 0x06: level 2 translation fault
[  645.781840] Data abort info:
[  645.781844]   ISV = 0, ISS = 0x00000046, ISS2 = 0x00000000
[  645.781850]   CM = 0, WnR = 1, TnD = 0, TagAccess = 0
[  645.781856]   GCS = 0, Overlay = 0, DirtyBit = 0, Xs = 0
[  645.781866] user pgtable: 4k pages, 39-bit VAs, pgdp=00000000484d5000
[  645.781873] [0000000000000008] pgd=080000004c6eb003, p4d=080000004c6eb003, pud=080000004c6eb003, pmd=0000000000000000
[  645.781896] Internal error: Oops: 0000000096000046 [#1] PREEMPT SMP
[  645.781905] Modules linked in: bcm2835_codec(C) bcm2835_mmal_vchiq(C) vc_sm_cma(C) dwc2 edt_ft5x06 tc358762 drm_mipi_dbi simple_bridge panel_raspberrypi_touchscreen rpi_panel_attiny_regulator rpi_panel_v2_regulator panel_ilitek_ili9881c panel_simple nvmem_rmem drm_rp1_dsi drm_ttm_helper ttm snd_soc_hdmi_codec rpivid_hevc(C) pisp_be vc4 v4l2_mem2mem videobuf2_dma_contig videobuf2_v4l2 videobuf2_memops v3d drm_dma_helper videobuf2_common gpu_sched drm_shmem_helper drm_kms_helper drm_display_helper videodev drm backlight mc cec i2c_mux_pinctrl i2c_mux i2c_designware_platform i2c_designware_core i2c_brcmstb drm_panel_orientation_quirks raspberrypi_gpiomem uinput enc28j60 pwm_bcm2835 rpi_poe_power pwm_raspberrypi_poe gpio_fan simple_mfd_i2c raspberrypi_hwmon rtc_ds1307 rtc_pcf8523 i2c_bcm2708 i2c_dev regmap_i2c cdc_acm ftdi_sio pl2303 cp210x usbserial dm_crypt dm_mod hid_multitouch goodix_ts snd_soc_core snd_pcm_dmaengine snd_compress snd_bcm2835(C) snd_pcm snd_timer snd rt2800usb rt2800lib rt2x00usb rt2x00lib brcmfmac_wcc
[  645.782079]  brcmfmac brcmutil rtl8xxxu rtl8192cu rtl8192c_common rtl_usb rtlwifi xpad ff_memless tun i2c_bcm2835 overlay lib80211 mac80211 cfg80211 rfkill xt_owner xt_REDIRECT iptable_nat xt_MASQUERADE nf_nat xt_state nf_conntrack ipt_REJECT nf_reject_ipv4 nf_defrag_ipv6 nf_defrag_ipv4 xt_tcpudp iptable_filter ip_tables x_tables crc_ccitt squashfs fuse libarc4 ctr ccm cryptd sha256_arm64 aes_arm64 aes_generic libaes
[  645.782228] CPU: 0 UID: 0 PID: 297 Comm: SMIO Tainted: G        WC         6.12.16-v8+ #1859
[  645.782242] Tainted: [W]=WARN, [C]=CRAP
[  645.782248] Hardware name: Raspberry Pi 4 Model B Rev 1.1 (DT)
[  645.782255] pstate: 20000005 (nzCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--)
[  645.782265] pc : vc_sm_release_resource+0x54/0xf8 [vc_sm_cma]
[  645.782285] lr : vc_sm_release_resource+0x50/0xf8 [vc_sm_cma]
[  645.782296] sp : ffffffc080d63cf0
[  645.782302] x29: ffffffc080d63cf0 x28: ffffffc080a19da8 x27: ffffffac44f054d0
[  645.782317] x26: ffffffeb02f96cf0 x25: ffffffc080a19da0 x24: ffffffac44f05f98
[  645.782330] x23: ffffffac44f05908 x22: ffffffac4c854c20 x21: ffffffeb02f1b000
[  645.782344] x20: ffffffeb02f1b000 x19: ffffffac4c854c00 x18: ffffffffffffffff
[  645.782357] x17: ffffffc1499e7000 x16: ffffffeb33f8c698 x15: ffffffc080d63c75
[  645.782370] x14: 0000000000000032 x13: ffffffac4025eae8 x12: 0000000000000000
[  645.782383] x11: ffffffac414b53f8 x10: ffffffac414b5240 x9 : ffffffeb03066288
[  645.782397] x8 : ffffffac414b5268 x7 : 0000000000000034 x6 : 000000000000000c
[  645.782410] x5 : 0000000000000000 x4 : 0000000000000000 x3 : 0000000000000000
[  645.782423] x2 : 0000000000000000 x1 : 0000000000000000 x0 : ffffffac4025eb00
[  645.782436] Call trace:
[  645.782442]  vc_sm_release_resource+0x54/0xf8 [vc_sm_cma]
[  645.782454]  vc_sm_vpu_event+0x42c/0x508 [vc_sm_cma]
[  645.782464]  vc_sm_cma_vchi_videocore_io+0x1dc/0x398 [vc_sm_cma]
[  645.782475]  kthread+0x120/0x130
[  645.782488]  ret_from_fork+0x10/0x20
[  645.782502] Code: f9438280 91020000 94000c3f a9400662 (f9000441) 
[  645.782512] ---[ end trace 0000000000000000 ]---

Once that happened, other calls interfacing with the hardware might lock up and in my case the hardware watchdog resets the CPU. See also the discussion on the Pi forum.

Steps to reproduce the behaviour

On a Pi4, run the code from https://gist.github.com/dividuum/da0a9a7038b592898ea269f19917e438. After a few seconds, the program will stop showing output and the kernel log will likely show a traceback similar to the one above. Using more threads seems to speed up the time it takes to crash.

Device (s)

Raspberry Pi 4 Mod. B

System

Tested on

Revision        : b03111
Model           : Raspberry Pi 4 Model B Rev 1.1

 # uname -a (Kernel from raspberrypi/rpi-firmware)
Linux info-beamer-x 6.12.16-v8+ #1859 SMP PREEMPT Mon Feb 24 13:14:16 GMT 2025 aarch64 GNU/Linux

# vcgencmd bootloader_version
2025/02/11 17:00:13
version 75c1e570e99e14684e79e6ab8f5355d831440c71 (release)
timestamp 1739293213
update-time 1741025244
capabilities 0x0000007f

# vcgencmd version
Feb 17 2025 20:03:07 
Copyright (c) 2012 Broadcom
version da7125f985dfe3cb0cf91e3c47f1ace88018e466 (clean) (release) (start)

Logs

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions