mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Paul Menzel <pmenzel@molgen.mpg.de>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Antti Laakso <antti.laakso@linux.intel.com>
Cc: Sarang Sapre <sarang.sapre@intel.com>,
	Divyamani Tripathi <divyamani.tripathi@intel.com>,
	Manik Bajpai <manik.bajpai@intel.com>,
	Hans Verkuil <hverkuil@kernel.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [BUG] media: ipu6: use-after-free in v4l2_release() after unbinding intel_ipu6_isys
Date: Mon, 30 Nov 2026 14:04:11 +0100	[thread overview]
Message-ID: <abcc474a-bd58-45da-8551-d7925ca18d52@molgen.mpg.de> (raw)

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</dev/video0                  # or /dev/v4l-subdev0 
  

     echo intel_ipu6.isys.40 > 
/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:
      <TASK>
      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
      </TASK>

     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.

             reply	other threads:[~2026-11-30 13:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 13:04 Paul Menzel [this message]
2026-11-30 13:46 ` Sakari Ailus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=abcc474a-bd58-45da-8551-d7925ca18d52@molgen.mpg.de \
    --to=pmenzel@molgen.mpg.de \
    --cc=antti.laakso@linux.intel.com \
    --cc=divyamani.tripathi@intel.com \
    --cc=hverkuil@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=manik.bajpai@intel.com \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sarang.sapre@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®