linux/drivers/media/pci
Jacopo Mondi c90fad3e41 media: ivtv: Fix invalid access to file *
Since commit 9ba9d11544 ("media: ivtv: Access v4l2_fh from file")
all ioctl handlers have been ported to operate on the file * first
function argument.

The ivtv DVB layer calls ivtv_init_on_first_open() when the driver
needs to start streaming. This function calls the s_input() and
s_frequency() ioctl handlers directly, but being called from the driver
context, it doesn't have a valid file * to pass them. This causes the
ioctl handlers to deference an invalid pointer.

Fix this by moving the implementation of those ioctls to two helper
functions.

The ivtv_do_s_input() helper accepts a struct ivtv * as first argument,
which is easily accessible in ivtv_init_on_first_open() as well as from
the file * argument of the ioctl handler.

The ivtv_s_frequency() takes an ivtv_stream * instead. The stream * can
safely be accessed in ivtv_init_on_first_open() where it is hard-coded
to the IVTV_ENC_STREAM_TYPE_MPG stream type, as well as from the ioctl
handler as a valid stream type is associated to each open file handle
depending on which video device node has been opened in the ivtv_open()
file operation.

The bug has been reported by Smatch.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Closes: https://lore.kernel.org/all/aKL4OMWsESUdX8KQ@stanley.mountain/
Fixes: 9ba9d11544 ("media: ivtv: Access v4l2_fh from file")
Cc: stable@vger.kernel.org
Reviewed-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Tested-by: Hans Verkuil <hverkuil+cisco@kernel.org>
Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
Signed-off-by: Hans Verkuil <hverkuil+cisco@kernel.org>
2025-10-14 15:53:37 +02:00
..
b2c2 media: b2c2: Fix use-after-free causing by irq_check_work in flexcop_pci_remove 2025-09-17 12:14:06 +02:00
bt8xx media: v4l2: Rename second ioctl handlers argument to 'void *priv' 2025-08-13 08:34:01 +02:00
cobalt media: update Hans Verkuil's email address 2025-09-09 15:58:44 +02:00
cx18 media: cx18: Fix invalid access to file * 2025-10-14 15:53:37 +02:00
cx88 media: Switch to use hrtimer_setup() 2025-02-18 11:19:04 +01:00
cx23885 media: cx23885: Add analog support for AVerMedia H789-C PCIe card 2025-03-04 15:56:11 +01:00
cx25821
ddbridge
dm1105
dt3155
intel media: ipu6: isys: Set embedded data type correctly for metadata formats 2025-08-25 15:40:34 +02:00
ivtv media: ivtv: Fix invalid access to file * 2025-10-14 15:53:37 +02:00
mantis
mgb4 media: pci: mgb4: Fix timings comparison in VIDIOC_S_DV_TIMINGS 2025-08-29 11:04:03 +02:00
netup_unidvb treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
ngene
pluto2
pt1
pt3 media: pt3: Replace deprecated PCI functions 2025-04-25 15:14:30 +02:00
saa7134 media: v4l2: Rename second ioctl handlers argument to 'void *priv' 2025-08-13 08:34:01 +02:00
saa7146
saa7164 media: Reset file->private_data to NULL in v4l2_fh_del() 2025-08-13 08:33:44 +02:00
smipcie
solo6x10 treewide: rename GPIO set callbacks back to their original names 2025-08-07 10:07:06 +02:00
ttpci
tw68 media: update Hans Verkuil's email address 2025-09-09 15:59:02 +02:00
tw686x treewide, timers: Rename from_timer() to timer_container_of() 2025-06-08 09:07:37 +02:00
tw5864 media: tw5864: Replace deprecated PCI functions 2025-04-25 15:14:31 +02:00
zoran media: pci: zoran: Remove unused debug parameter 2025-08-29 11:04:01 +02:00
Kconfig media: remove STA2x11 media pci driver 2025-04-25 15:14:25 +02:00
Makefile media: remove STA2x11 media pci driver 2025-04-25 15:14:25 +02:00