From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=141.14.17.11 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796043902; b=UA1SrjpgaHl3V3ykZGkKPLD4DhdWdauJaXZIK41HwmyszzhWuCc++WqcYok1lFvWsiG4 o3RmkNkBaMeD2buRc8NIS/GuTSMTfW+unefg9h1+ROzfIHh1cqqgiK3DNx57w8Gd+zDRL aOqBbQ2V4E6YHOAC/voT2AOBLqfy/EmhmapFdDVfJoA33ZZPMxxkUXbPzHaFeD9Ve5nBa UeHKoAPb11Hw+WoE0yvQSygamthgtHZEHGU/dW/5WcVbl99HwhMqFJbbFGf7EoZZ0PWuh hP0BjMShbVbOgJecho7HqtsI+OLrlRKHrIKI6M1g1utkBzFfiuqrVsEEWnyTCmVlMWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796043902; h=DMARC-Filter:Received:Message-ID:Date:MIME-Version:User-Agent: Content-Language:To:Cc:From:Subject:Content-Type: Content-Transfer-Encoding:DKIM-Signature; bh=UL5KJiyU8CU/xC4qNqdgx9dey/Q7vrha1Ox+tpVHGzU=; b=HIIzFFmQAqNoMRL5A9ODBoY0Q5QKENq5iScF1g1zzctATu2r7XUxu9mRAoHdq2uk/h4a ClL5TdNrLq4IbJACZZyzJPEn7+NRbCUEn2rCpWBnvkRRUWdA1wCg2AR4gEK7ogvCDhh0D 1VaguGQsRiG5uBZzQoCkmxh8ZWGA8IhycBIcSjkJEponrzEGTfX/AnnLXdc2Nam3B6Ito BBmYSzlWd4N3vZSTOy02YU8PTs/kubcrScrFgQp8bGHHF9f7zhclK/D5cLYKDF6RM+FM0 J8D9EECgioMEYhIXVa4tkDyOWd7D8xYlP0Y41VbocM5tPqCaLJK2h0mTBeu/V1uv3FA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=molgen.mpg.de; spf=pass smtp.mailfrom=molgen.mpg.de; dkim=pass header.d=molgen.mpg.de header.i=@molgen.mpg.de header.a=rsa-sha256 header.s=20260906 header.b=qu9+vVoF; arc=none smtp.remote-ip=141.14.17.11 Received: from mx3.molgen.mpg.de (mx3.molgen.mpg.de [141.14.17.11]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E38C6606A336; Mon, 30 Nov 2026 13:05:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E38C6606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=molgen.mpg.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=molgen.mpg.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=molgen.mpg.de header.i=@molgen.mpg.de header.a=rsa-sha256 header.s=20260906 header.b=qu9+vVoF Received: from [141.14.220.44] (g44.guest.molgen.mpg.de [141.14.220.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pmenzel) by mx.molgen.mpg.de (Postfix) with ESMTPSA id 2D13D4C2C37D4B; Mon, 30 Nov 2026 14:04:12 +0100 (CET) Message-ID: Date: Mon, 30 Nov 2026 14:04:11 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Sakari Ailus , Antti Laakso Cc: Sarang Sapre , Divyamani Tripathi , Manik Bajpai , Hans Verkuil , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org From: Paul Menzel Subject: [BUG] media: ipu6: use-after-free in v4l2_release() after unbinding intel_ipu6_isys Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=molgen.mpg.de; s=20260906; t=1796043852; h=from:from:subject:date:message-id:mime-version:content-type:content-transfer-encoding; bh=UL5KJiyU8CU/xC4qNqdgx9dey/Q7vrha1Ox+tpVHGzU=; b=qu9+vVoFfcmAlKQ5HHhQ+PyTkw6lEYkg4NofuHDI0mqVz4GdgvmJZnPhLFaIDLE7BwvyX6VfPtQm xnPkJdErP/42/EipEx2KCVlsATCjv0YA7HXGeUyvsPcsLnSxISWK5gc5dyM+RxhNYXmhlsDzaAfs0D KM38L4n7xckuV+0f4+9v5uZDy+VhPvH6MqMhucH8DmzPzK4JMcLfzxUQIGwG+naXn+Mc0hCypdY0W6 dO4Y/gZGA/PIi1n703/IhDPUt7sx6v2pfgj8Fmah0OQUpzfu9ivyxp8SJc/hy0Ke1IRvtCHPm1UmZ0 b/sZJ3rx+5yiGY7Z8z+c6URKq/9GOYQw== Dear Sakari, dear Antti, On a Dell XPS 9315 (Alder Lake, IPU6 8086:465d, BIOS 1.26.0), unbinding intel_ipu6_isys while a video or subdevice node is open and then closing that node accesses freed memory. With Debian’s 7.3.5 this hung the laptop: WirePlumber still had the nodes open, and its close() at reboot hit list corruption, followed by a hard lockup in udev’s v4l_id: [ 222.050787] list_del corruption. prev->next should be ffff89dbc4d87f00, but was ffff89dbf9428328. (prev=ffff89dbf9428328) [ 222.050850] kernel BUG at lib/list_debug.c:62! [ 222.081991] CPU: 6 UID: 1000 PID: 3005 Comm: CameraManager Not tainted 7.3.5+deb14-amd64 #1 PREEMPT(lazy) Debian 7.3.5-1 [ 222.085043] v4l2_fh_del+0x2e/0x80 [videodev] [ 222.085048] v4l2_fh_release+0x1e/0x50 [videodev] [ 222.085064] v4l2_release+0xa0/0xe0 [videodev] [ 222.085076] __x64_sys_close+0x47/0xa0 [ 243.073203] watchdog: CPU1: Watchdog detected hard LOCKUP on cpu 1 [ 243.073502] CPU: 1 UID: 0 PID: 3661 Comm: v4l_id Tainted: G D 7.3.5+deb14-amd64 #1 [ 243.102780] v4l2_fh_add+0x3c/0xa0 [videodev] To confirm it, I passed the IPU6 through to a QEMU guest (vfio-pci) and ran v7.4-rc5 with KASAN there. The reproducer, as root: exec 3 /sys/bus/auxiliary/drivers/intel_ipu6_isys.isys/unbind exec 3<&- Closing /dev/video0: BUG: KASAN: use-after-free in v4l2_release+0x349/0x3c0 Read of size 8 at addr ffff888110260870 by task sh/113 CPU: 0 UID: 0 PID: 113 Comm: sh Not tainted 7.4.0-rc5-ipu6-kasan #2 PREEMPT(lazy) Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.17.0-debian-1.17.0-1 04/01/2014 Call Trace: dump_stack_lvl+0x53/0x70 print_report+0xce/0x630 kasan_report+0xce/0x100 v4l2_release+0x349/0x3c0 __fput+0x2f8/0x9e0 fput_close_sync+0xe2/0x190 __x64_sys_close+0x78/0xd0 do_syscall_64+0xea/0x4f0 entry_SYSCALL_64_after_hwframe+0x77/0x7f The buggy address belongs to the physical page: page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x110260 page_type: f0(buddy) page_owner tracks the page as freed page last allocated via order 4, migratetype Unmovable, gfp_mask 0x40dc0(GFP_KERNEL|__GFP_ZERO|__GFP_COMP), pid 104, tgid 104 (insmod), ts 941781474 prep_new_page+0xac/0x140 get_page_from_freelist+0xef3/0x3b10 __alloc_frozen_pages_noprof+0x30a/0x2d40 alloc_pages_mpol+0xc1/0x2d0 ___kmalloc_large_node+0xe7/0x140 __kmalloc_large_node_noprof+0x1a/0xa0 __kmalloc_node_track_caller_noprof+0x370/0x490 devm_kmalloc+0x70/0x240 isys_probe+0x249/0x17f0 [intel_ipu6_isys] really_probe+0x1c3/0x690 page last free pid 113 tgid 113 ts 1030318437 stack trace: __free_pages_ok+0x4bf/0xae0 release_nodes+0xb9/0x110 devres_release_all+0x100/0x170 device_unbind_cleanup+0x71/0x250 device_release_driver_internal+0x393/0x520 unbind_store+0xd1/0xf0 kernfs_fop_write_iter+0x30a/0x4f0 vfs_write+0x5c7/0xd40 Closing /dev/v4l-subdev0: BUG: KASAN: slab-use-after-free in v4l2_release+0x33c/0x3c0 Read of size 8 at addr ffff8881099842d8 by task sh/113 […] Allocated by task 104: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x40 __kasan_kmalloc+0x8f/0xa0 __kmalloc_node_track_caller_noprof+0x1ab/0x490 devm_kmalloc+0x70/0x240 isys_probe+0x8e/0x17f0 [intel_ipu6_isys] really_probe+0x1c3/0x690 […] Freed by task 113: kasan_save_stack+0x33/0x60 kasan_save_track+0x14/0x40 kasan_save_free_info+0x3b/0x60 __kasan_slab_free+0x57/0x80 kfree+0x186/0x3b0 release_nodes+0xb9/0x110 devres_release_all+0x100/0x170 device_unbind_cleanup+0x71/0x250 device_release_driver_internal+0x393/0x520 unbind_store+0xd1/0xf0 The buggy address belongs to the object at ffff888109984000 which belongs to the cache kmalloc-2k of size 2048 The buggy address is located 728 bytes inside of freed 2048-byte region [ffff888109984000, ffff888109984800) Closing /dev/media0 the same way reports nothing. Decoded with faddr2line, both reads are in v4l2-dev.c:466, `v4l2_device_supports_requests(vdev->v4l2_dev)`: - video node: the struct video_device itself is freed. It is isys->csi2[i].av[j].vdev, and isys->csi2 comes from devm_kzalloc_objs() (ipu6-isys.c:1001, the order-4 allocation above), while ipu6_isys_video_init() sets av->vdev.release = video_device_release_empty. - subdevice node: the video_device is the core’s refcounted one, but vdev->v4l2_dev points into struct ipu6_isys, from devm_kzalloc_obj() (ipu6-isys.c:990), which also embeds media_dev. That memory is freed when devres runs after isys_remove(). So every structure an open file handle can reach (isys, the CSI2 subdevices, the video devices, v4l2_dev, media_dev) is devm-allocated and gone after unbind, while nothing ties its lifetime to the last close(). I guess the usual fix is to kzalloc() these, free them from a v4l2_device.release() callback (video_register_device() already takes a v4l2_device reference per node), and move media_device_cleanup() there too, as v4l2_release() uses mdev->req_queue_mutex. But you know better whether you want that, or prefer a different approach (or whether it is already being worked on; I didn’t find anything on lore). Note that isys_probe() is also used for IPU7 and IPU8, which I couldn’t test. Only root can unbind, so I don’t see a security issue. But anything that removes the device while user space holds the nodes (the camera stack does by default) ends like this. The test harness (busybox initramfs, vfio-pci, KASAN config) and the full logs are available if useful. Kind regards, Paul PS: I used claude-opus-5.5 to build the QEMU/vfio-pci harness, run the tests and draft this report; I checked the result. PPS: The commands for the record: timeout 600 qemu-system-x86_64 \ -machine q35,accel=kvm -cpu host -smp 4 -m 4G \ -nodefaults -vga none -display none -no-reboot \ -serial file:guest-kasan-video.log \ -kernel kasan/bzImage -initrd initrd-kasan.cpio \ -append "console=ttyS0 panic=-1 loglevel=7 log_buf_len=16M page_owner=on repro.nodes=video" \ -device vfio-pci,host=0000:00:05.0,addr=05.0 - Other runs: the subdevice and media runs only change repro.nodes=subdev or repro.nodes=media and the log file name. The first run used kasan_multi_shot and had no page_owner=on. - addr=05.0: keeps the guest at the same PCI address as the host (devfn 0x28). The auxiliary device is then called intel_ipu6.isys.40 in the guest as on the host, so the same unbind line works in both. - No MSI options: the ISYS on IPU6EP uses legacy INTx interrupts, and plain vfio-pci handles that. Before QEMU starts, `run.sh` hands the device to vfio-pci: modprobe vfio-pci echo vfio-pci > /sys/bus/pci/devices/0000:00:05.0/driver_override echo 0000:00:05.0 > /sys/bus/pci/devices/0000:00:05.0/driver/unbind echo 0000:00:05.0 > /sys/bus/pci/drivers_probe Afterwards, an exit trap gives it back: it clears driver_override, unbinds from vfio-pci and runs drivers_probe again, which rebinds intel-ipu6. WirePlumber has to be stopped first. Unbinding intel-ipu6 on the host while WirePlumber holds the nodes open triggers the bug itself, on the host. The loop around the call was: for n in video subdev media; do systemctl --user stop wireplumber.service; sleep 3 sudo ./qemu/run.sh kasan/bzImage initrd-kasan.cpio guest-kasan-$n.log page_owner=on repro.nodes=$n done To keep the libcamera hook from restarting WirePlumber in between, it was also masked with systemctl --user mask --runtime during the runs.