Skip to contentSkip to conversation

media: mc: Add "kaboom" module parameter

RFC In review Sakari Ailus 3 participants 5 messages May 19, 2025 – May 21, 2025

Subsystems (2)
lore
Share & tools
lore

Sakari Ailus

author maintainer
#0 lore raw

RFC 1/1 media: mc: Add "kaboom" module parameter

Add "kaboom" module parameter for the "mc" module. Setting "kaboom" to a non-zero value will delay calling media device IOCTLs by 5 s and if the media device is unregistered and released during this time, NULL pointer is dereferenced and at least a kernel oops will happen:

[   63.754666] vim2m vim2m.0: Removing vim2m
[   63.754681] vim2m vim2m.0: media_gobj_destroy id 13: interface link id 12 ==> id 1
[   63.755611] vim2m vim2m.0: media_gobj_destroy id 9: data link id 2 ==> id 4
[   63.755618] vim2m vim2m.0: media_gobj_destroy id 8: data link id 2 ==> id 4
[   63.755622] vim2m vim2m.0: media_gobj_destroy id 2: source pad 'vim2m-source':0
[   63.755628] vim2m vim2m.0: media_gobj_destroy id 1: entity 'vim2m-source'
[   63.755633] vim2m vim2m.0: media_gobj_destroy id 11: data link id 5 ==> id 7
[   63.755637] vim2m vim2m.0: media_gobj_destroy id 10: data link id 5 ==> id 7
[   63.755641] vim2m vim2m.0: media_gobj_destroy id 4: sink pad 'vim2m-proc':0
[   63.755646] vim2m vim2m.0: media_gobj_destroy id 5: source pad 'vim2m-proc':1
[   63.755650] vim2m vim2m.0: media_gobj_destroy id 3: entity 'vim2m-proc'
[   63.755654] vim2m vim2m.0: media_gobj_destroy id 14: interface link id 12 ==> id 6
[   63.755659] vim2m vim2m.0: media_gobj_destroy id 7: sink pad 'vim2m-sink':0
[   63.755663] vim2m vim2m.0: media_gobj_destroy id 6: entity 'vim2m-sink'
[   63.755666] vim2m vim2m.0: media_gobj_destroy id 12: intf_devnode v4l-video - major: 81, minor: 0
[   63.755672] vim2m vim2m.0: Media device unregistered
[   68.105679] BUG: kernel NULL pointer dereference, address: 0000000000000000
[   68.107196] #PF: supervisor read access in kernel mode
[   68.108317] #PF: error_code(0x0000) - not-present page
[   68.109396] PGD 0 P4D 0
[   68.109596] Oops: Oops: 0000 [#1] SMP PTI
[   68.109596] CPU: 0 UID: 1000 PID: 957 Comm: media-ctl Tainted: G            E       6.15.0-rc1+ #20 PREEMPT(voluntary)
[   68.109596] Tainted: [E]=UNSIGNED_MODULE
[   68.109596] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[   68.109596] RIP: 0010:media_device_cleanup+0x20f/0xc00 [mc]
[   68.109596] Code: 00 00 00 89 43 7c 31 c0 5b 41 5c 41 5d 41 5e 5d 31 d2 31 c9 31 f6 31 ff c3 cc cc cc cc 49 8b 04 24 be 10 00 00 00 48 8b 40 68 <4c> 8b 28 4c 89 ef e8 f6 29 ca c3 48 89 c2 48 83 f8 ff 0f 85 e8 fe
[   68.109596] RSP: 0018:ffffb4efc0a6bd58 EFLAGS: 00010246
[   68.109596] RAX: 0000000000000000 RBX: ffffb4efc0a6bda0 RCX: 0000000000000000
[   68.109596] RDX: ffffffffc08244e0 RSI: 0000000000000010 RDI: ffffb4efc0a6bea0
[   68.109596] RBP: ffffb4efc0a6bd78 R08: ffff99a84a7f7e10 R09: 0000000000000000
[   68.109596] R10: 0000000000000000 R11: 0000000000000000 R12: ffff99a84a7f7cf8
[   68.109596] R13: 0000000000000000 R14: ffffb4efc0a6bda0 R15: ffff99a84a7f7cf8
[   68.109596] FS:  00007f5ceb8a4bc0(0000) GS:ffff99a9f24f3000(0000) knlGS:0000000000000000
[   68.109596] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   68.109596] CR2: 0000000000000000 CR3: 00000001108d2000 CR4: 00000000000006f0
[   68.109596] Call Trace:
[   68.109596]  <TASK>
[   68.109596]  media_device_cleanup+0x536/0xc00 [mc]
[   68.109596]  __media_device_usb_init+0x8ff/0xc00 [mc]
[   68.109596]  __x64_sys_ioctl+0xa7/0xe0
[   68.109596]  x64_sys_call+0xb40/0x2550
[   68.109596]  do_syscall_64+0x70/0x140
[   68.109596]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   68.109596] RIP: 0033:0x7f5ceb9be8db
[   68.109596] Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
[   68.109596] RSP: 002b:00007ffdacd35bd0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
[   68.109596] RAX: ffffffffffffffda RBX: 000056536edc42a0 RCX: 00007f5ceb9be8db
[   68.109596] RDX: 000056536edc42b0 RSI: 00000000c1007c00 RDI: 0000000000000003
[   68.109596] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[   68.109596] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
[   68.109596] R13: 00007ffdacd35f10 R14: 00007f5cebb3d000 R15: 0000565362627d78
[   68.109596]  </TASK>
[   68.109596] Modules linked in: snd_seq_dummy(E) snd_hrtimer(E) snd_seq(E) snd_seq_device(E) sunrpc(E) vim2m(E) v4l2_mem2mem(E) videobuf2_vmalloc(E) videobuf2_memops(E) videobuf2_v4l2(E) videobuf2_common(E) videodev(E) mc(E) qrtr(E) binfmt_misc(E) snd_pcm(E) snd_timer(E) snd(E) soundcore(E) pcspkr(E) e1000(E) i2c_piix4(E) pata_acpi(E) i2c_smbus(E) joydev(E) sch_fq_codel(E) efi_pstore(E) drm(E) nfnetlink(E) vsock_loopback(E) vmw_vsock_virtio_transport_common(E) vmw_vsock_vmci_transport(E) vsock(E) vmw_vmci(E) dmi_sysfs(E) qemu_fw_cfg(E) ip_tables(E) x_tables(E) autofs4(E) input_leds(E) psmouse(E) serio_raw(E) virtio_blk(E) mac_hid(E)
[   68.109596] CR2: 0000000000000000
[   68.121045] ---[ end trace 0000000000000000 ]---
[   68.121203] RIP: 0010:media_device_cleanup+0x20f/0xc00 [mc]
[   68.121391] Code: 00 00 00 89 43 7c 31 c0 5b 41 5c 41 5d 41 5e 5d 31 d2 31 c9 31 f6 31 ff c3 cc cc cc cc 49 8b 04 24 be 10 00 00 00 48 8b 40 68 <4c> 8b 28 4c 89 ef e8 f6 29 ca c3 48 89 c2 48 83 f8 ff 0f 85 e8 fe
[   68.123005] RSP: 0018:ffffb4efc0a6bd58 EFLAGS: 00010246
[   68.123191] RAX: 0000000000000000 RBX: ffffb4efc0a6bda0 RCX: 0000000000000000
[   68.123433] RDX: ffffffffc08244e0 RSI: 0000000000000010 RDI: ffffb4efc0a6bea0
[   68.123679] RBP: ffffb4efc0a6bd78 R08: ffff99a84a7f7e10 R09: 0000000000000000
[   68.123925] R10: 0000000000000000 R11: 0000000000000000 R12: ffff99a84a7f7cf8
[   68.124307] R13: 0000000000000000 R14: ffffb4efc0a6bda0 R15: ffff99a84a7f7cf8
[   68.124563] FS:  00007f5ceb8a4bc0(0000) GS:ffff99a9f24f3000(0000) knlGS:0000000000000000
[   68.124849] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   68.125055] CR2: 0000000000000000 CR3: 00000001108d2000 CR4: 00000000000006f0
[   68.125618] platform vim2m.0: Media device released
[   68.125997] mc: media_devnode_release: Media Devnode Deallocated

Without this patch the time window typically remains small but it is still always there.

---
 drivers/media/mc/mc-device.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/mc/mc-device.c +8 -0
index c0dd4ae57227..116065b0038a 100644
@@ -9,10 +9,12 @@
  */
 
 #include <linux/compat.h>
+#include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/idr.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/pci.h>
@@ -26,6 +28,9 @@
 
 #ifdef CONFIG_MEDIA_CONTROLLER
 
+static unsigned int kaboom;
+module_param(kaboom, int, 0600);
+
 /*
  * Legacy defines from linux/media.h. This is the only place we need this
  * so we just define it here. The media.h header doesn't expose it to the
@@ -441,6 +446,9 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 	char __karg[256], *karg = __karg;
 	long ret;
 
+	if (kaboom)
+		msleep(5000);
+
 	if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
 	    || ioctl_info[_IOC_NR(cmd)].cmd != cmd)
 		return -ENOIOCTLCMD;
Signature · 1 line
2.39.5
maintainer
#1 lore raw

Hi Sakari,

Thank you for the patch.

Quoted 4 lines · Sakari Ailus

Add "kaboom" module parameter for the "mc" module. Setting "kaboom" to a non-zero value will delay calling media device IOCTLs by 5 s and if the media device is unregistered and released during this time, NULL pointer is dereferenced and at least a kernel oops will happen:

This is useful for debugging, but do we really want to merge it in mainline ? Can't this patch be carried out-of-tree ?

Quoted 115 lines
[   63.754666] vim2m vim2m.0: Removing vim2m
[   63.754681] vim2m vim2m.0: media_gobj_destroy id 13: interface link id 12 ==> id 1
[   63.755611] vim2m vim2m.0: media_gobj_destroy id 9: data link id 2 ==> id 4
[   63.755618] vim2m vim2m.0: media_gobj_destroy id 8: data link id 2 ==> id 4
[   63.755622] vim2m vim2m.0: media_gobj_destroy id 2: source pad 'vim2m-source':0
[   63.755628] vim2m vim2m.0: media_gobj_destroy id 1: entity 'vim2m-source'
[   63.755633] vim2m vim2m.0: media_gobj_destroy id 11: data link id 5 ==> id 7
[   63.755637] vim2m vim2m.0: media_gobj_destroy id 10: data link id 5 ==> id 7
[   63.755641] vim2m vim2m.0: media_gobj_destroy id 4: sink pad 'vim2m-proc':0
[   63.755646] vim2m vim2m.0: media_gobj_destroy id 5: source pad 'vim2m-proc':1
[   63.755650] vim2m vim2m.0: media_gobj_destroy id 3: entity 'vim2m-proc'
[   63.755654] vim2m vim2m.0: media_gobj_destroy id 14: interface link id 12 ==> id 6
[   63.755659] vim2m vim2m.0: media_gobj_destroy id 7: sink pad 'vim2m-sink':0
[   63.755663] vim2m vim2m.0: media_gobj_destroy id 6: entity 'vim2m-sink'
[   63.755666] vim2m vim2m.0: media_gobj_destroy id 12: intf_devnode v4l-video - major: 81, minor: 0
[   63.755672] vim2m vim2m.0: Media device unregistered
[   68.105679] BUG: kernel NULL pointer dereference, address: 0000000000000000
[   68.107196] #PF: supervisor read access in kernel mode
[   68.108317] #PF: error_code(0x0000) - not-present page
[   68.109396] PGD 0 P4D 0
[   68.109596] Oops: Oops: 0000 [#1] SMP PTI
[   68.109596] CPU: 0 UID: 1000 PID: 957 Comm: media-ctl Tainted: G            E       6.15.0-rc1+ #20 PREEMPT(voluntary)
[   68.109596] Tainted: [E]=UNSIGNED_MODULE
[   68.109596] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[   68.109596] RIP: 0010:media_device_cleanup+0x20f/0xc00 [mc]
[   68.109596] Code: 00 00 00 89 43 7c 31 c0 5b 41 5c 41 5d 41 5e 5d 31 d2 31 c9 31 f6 31 ff c3 cc cc cc cc 49 8b 04 24 be 10 00 00 00 48 8b 40 68 <4c> 8b 28 4c 89 ef e8 f6 29 ca c3 48 89 c2 48 83 f8 ff 0f 85 e8 fe
[   68.109596] RSP: 0018:ffffb4efc0a6bd58 EFLAGS: 00010246
[   68.109596] RAX: 0000000000000000 RBX: ffffb4efc0a6bda0 RCX: 0000000000000000
[   68.109596] RDX: ffffffffc08244e0 RSI: 0000000000000010 RDI: ffffb4efc0a6bea0
[   68.109596] RBP: ffffb4efc0a6bd78 R08: ffff99a84a7f7e10 R09: 0000000000000000
[   68.109596] R10: 0000000000000000 R11: 0000000000000000 R12: ffff99a84a7f7cf8
[   68.109596] R13: 0000000000000000 R14: ffffb4efc0a6bda0 R15: ffff99a84a7f7cf8
[   68.109596] FS:  00007f5ceb8a4bc0(0000) GS:ffff99a9f24f3000(0000) knlGS:0000000000000000
[   68.109596] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   68.109596] CR2: 0000000000000000 CR3: 00000001108d2000 CR4: 00000000000006f0
[   68.109596] Call Trace:
[   68.109596]  <TASK>
[   68.109596]  media_device_cleanup+0x536/0xc00 [mc]
[   68.109596]  __media_device_usb_init+0x8ff/0xc00 [mc]
[   68.109596]  __x64_sys_ioctl+0xa7/0xe0
[   68.109596]  x64_sys_call+0xb40/0x2550
[   68.109596]  do_syscall_64+0x70/0x140
[   68.109596]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
[   68.109596] RIP: 0033:0x7f5ceb9be8db
[   68.109596] Code: 00 48 89 44 24 18 31 c0 48 8d 44 24 60 c7 04 24 10 00 00 00 48 89 44 24 08 48 8d 44 24 20 48 89 44 24 10 b8 10 00 00 00 0f 05 <89> c2 3d 00 f0 ff ff 77 1c 48 8b 44 24 18 64 48 2b 04 25 28 00 00
[   68.109596] RSP: 002b:00007ffdacd35bd0 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
[   68.109596] RAX: ffffffffffffffda RBX: 000056536edc42a0 RCX: 00007f5ceb9be8db
[   68.109596] RDX: 000056536edc42b0 RSI: 00000000c1007c00 RDI: 0000000000000003
[   68.109596] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000000
[   68.109596] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
[   68.109596] R13: 00007ffdacd35f10 R14: 00007f5cebb3d000 R15: 0000565362627d78
[   68.109596]  </TASK>
[   68.109596] Modules linked in: snd_seq_dummy(E) snd_hrtimer(E) snd_seq(E) snd_seq_device(E) sunrpc(E) vim2m(E) v4l2_mem2mem(E) videobuf2_vmalloc(E) videobuf2_memops(E) videobuf2_v4l2(E) videobuf2_common(E) videodev(E) mc(E) qrtr(E) binfmt_misc(E) snd_pcm(E) snd_timer(E) snd(E) soundcore(E) pcspkr(E) e1000(E) i2c_piix4(E) pata_acpi(E) i2c_smbus(E) joydev(E) sch_fq_codel(E) efi_pstore(E) drm(E) nfnetlink(E) vsock_loopback(E) vmw_vsock_virtio_transport_common(E) vmw_vsock_vmci_transport(E) vsock(E) vmw_vmci(E) dmi_sysfs(E) qemu_fw_cfg(E) ip_tables(E) x_tables(E) autofs4(E) input_leds(E) psmouse(E) serio_raw(E) virtio_blk(E) mac_hid(E)
[   68.109596] CR2: 0000000000000000
[   68.121045] ---[ end trace 0000000000000000 ]---
[   68.121203] RIP: 0010:media_device_cleanup+0x20f/0xc00 [mc]
[   68.121391] Code: 00 00 00 89 43 7c 31 c0 5b 41 5c 41 5d 41 5e 5d 31 d2 31 c9 31 f6 31 ff c3 cc cc cc cc 49 8b 04 24 be 10 00 00 00 48 8b 40 68 <4c> 8b 28 4c 89 ef e8 f6 29 ca c3 48 89 c2 48 83 f8 ff 0f 85 e8 fe
[   68.123005] RSP: 0018:ffffb4efc0a6bd58 EFLAGS: 00010246
[   68.123191] RAX: 0000000000000000 RBX: ffffb4efc0a6bda0 RCX: 0000000000000000
[   68.123433] RDX: ffffffffc08244e0 RSI: 0000000000000010 RDI: ffffb4efc0a6bea0
[   68.123679] RBP: ffffb4efc0a6bd78 R08: ffff99a84a7f7e10 R09: 0000000000000000
[   68.123925] R10: 0000000000000000 R11: 0000000000000000 R12: ffff99a84a7f7cf8
[   68.124307] R13: 0000000000000000 R14: ffffb4efc0a6bda0 R15: ffff99a84a7f7cf8
[   68.124563] FS:  00007f5ceb8a4bc0(0000) GS:ffff99a9f24f3000(0000) knlGS:0000000000000000
[   68.124849] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[   68.125055] CR2: 0000000000000000 CR3: 00000001108d2000 CR4: 00000000000006f0
[   68.125618] platform vim2m.0: Media device released
[   68.125997] mc: media_devnode_release: Media Devnode Deallocated

Without this patch the time window typically remains small but it is still always there.

---
 drivers/media/mc/mc-device.c | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/media/mc/mc-device.c +8 -0
index c0dd4ae57227..116065b0038a 100644
@@ -9,10 +9,12 @@
  */
 
 #include <linux/compat.h>
+#include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/idr.h>
 #include <linux/ioctl.h>
 #include <linux/media.h>
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/types.h>
 #include <linux/pci.h>
@@ -26,6 +28,9 @@
 
 #ifdef CONFIG_MEDIA_CONTROLLER
 
+static unsigned int kaboom;
+module_param(kaboom, int, 0600);
+
 /*
  * Legacy defines from linux/media.h. This is the only place we need this
  * so we just define it here. The media.h header doesn't expose it to the
@@ -441,6 +446,9 @@ static long media_device_ioctl(struct file *filp, unsigned int cmd,
 	char __karg[256], *karg = __karg;
 	long ret;
 
+	if (kaboom)
+		msleep(5000);
+
 	if (_IOC_NR(cmd) >= ARRAY_SIZE(ioctl_info)
 	    || ioctl_info[_IOC_NR(cmd)].cmd != cmd)
 		return -ENOIOCTLCMD;
Signature · 3 lines
Regards,

Laurent Pinchart
author maintainer
#2 lore raw

Hi Laurent,

Quoted 4 lines · Laurent Pinchart

Hi Sakari,

Thank you for the patch.

Quoted 8 lines
Quoted 4 lines · Sakari Ailus

Add "kaboom" module parameter for the "mc" module. Setting "kaboom" to a non-zero value will delay calling media device IOCTLs by 5 s and if the media device is unregistered and released during this time, NULL pointer is dereferenced and at least a kernel oops will happen:

This is useful for debugging, but do we really want to merge it in mainline ? Can't this patch be carried out-of-tree ?

Rather than merging this anywhere, the problems this patch underlines should be fixed. The first one that you hit is a NULL pointer dereference due to lack of refcounting and the second one stems from the device disappearing while an IOCTL is in progress, leading to similar issues.

Signature · 3 lines
Regards,

Sakari Ailus
maintainer
#3 lore raw
Quoted 7 lines · Sakari Ailus
Quoted 6 lines · Laurent Pinchart
Quoted 4 lines · Sakari Ailus

Add "kaboom" module parameter for the "mc" module. Setting "kaboom" to a non-zero value will delay calling media device IOCTLs by 5 s and if the media device is unregistered and released during this time, NULL pointer is dereferenced and at least a kernel oops will happen:

Quoted 5 lines
Quoted 2 lines

This is useful for debugging, but do we really want to merge it in mainline ? Can't this patch be carried out-of-tree ?

Rather than merging this anywhere, the problems this patch underlines should be fixed.

Absolutely :-) Can you clarify what you want to do with this patch ? Did you send it to share a means of reproducing the problem with other developers interested in fixing it, or do you want to merge it in mainline ?

Quoted 3 lines

The first one that you hit is a NULL pointer dereference due to lack of refcounting and the second one stems from the device disappearing while an IOCTL is in progress, leading to similar issues.

Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw
Quoted 11 lines · Laurent Pinchart
Quoted 10 lines · Sakari Ailus
Quoted 8 lines · Laurent Pinchart
Quoted 4 lines · Sakari Ailus

Add "kaboom" module parameter for the "mc" module. Setting "kaboom" to a non-zero value will delay calling media device IOCTLs by 5 s and if the media device is unregistered and released during this time, NULL pointer is dereferenced and at least a kernel oops will happen:

This is useful for debugging, but do we really want to merge it in mainline ? Can't this patch be carried out-of-tree ?

Quoted 7 lines
Quoted 2 lines

Rather than merging this anywhere, the problems this patch underlines should be fixed.

Absolutely :-) Can you clarify what you want to do with this patch ? Did you send it to share a means of reproducing the problem with other developers interested in fixing it, or do you want to merge it in mainline ?

I wanted to have a patch to trigger this kernel oops. For now it is not meant to be merged, but when we actually fix this issue, then we should consider merging this patch (or a variant) and enable it in the test-media regression test to verify that this issue won't come back.

Regards,

Hans

Quoted 5 lines
Quoted 4 lines

The first one that you hit is a NULL pointer dereference due to lack of refcounting and the second one stems from the device disappearing while an IOCTL is in progress, leading to similar issues.