linux-xiaomi-chiron/drivers
Jesper Juhl bafefc0cf8 V4L/DVB (4154): Fix use-after-free bug in cpia2 driver
The coverity checker detected a use-after-free error in
drivers/media/video/cpia2/cpia2_v4l.c::cpia2_close() (coverity
error #1281).
What happens is that we lock cam->busy_lock, then proceed to free
resources, and in the case of (--cam->open_count == 0) we finish off by
doing a kfree(cam) and then at the end of the function we do a
mutex_unlock(&cam->busy_lock) which will explode since it'll dereference
the free'd `cam' :
...
mutex_lock(&cam->busy_lock);
...
if (--cam->open_count == 0) {
    ...
    if (!cam->present) {
        video_unregister_device(dev);
        kfree(cam);
    }
}
mutex_unlock(&cam->busy_lock);   <--- PROBLEM, cam no longer around.
...
Since this only happens in the case of open_count going down to zero I
don't see a problem with just releasing the mutex after unregistering the
device and just before the kfree().  In this case there is nothing around
that we can race against; we are in the release method, open_count is zero,
(!cam->present) and the device has just been unregistered, so letting go of
the mutex at this point looks safe to me.
Patch below to implement that solution.
Acked-by: Randy Dunlap <rdunlap@xenotime.net>

Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
2006-06-25 02:05:14 -03:00
..
acorn
acpi [PATCH] fix typo in acpi video brightness changes. 2006-06-23 21:37:34 -07:00
amba
atm
base Enable minimal per-device resume tracing 2006-06-24 14:47:59 -07:00
block [PATCH] drivers/block/loop.c: don't return garbage if LOOP_SET_STATUS not called 2006-06-23 07:43:09 -07:00
bluetooth
cdrom
char Merge branch 'drm-patches' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6 2006-06-24 14:48:43 -07:00
connector
cpufreq [PATCH] cpufreq build fix 2006-06-23 08:47:27 -07:00
crypto
dio
dma
edac
eisa
fc4
firmware
hwmon
i2c
ide Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik/libata-dev 2006-06-23 15:58:44 -07:00
ieee1394
infiniband
input [SPARC64]: Add of_device layer and make ebus/isa use it. 2006-06-23 23:15:43 -07:00
isdn
leds
macintosh
mca
md
media V4L/DVB (4154): Fix use-after-free bug in cpia2 driver 2006-06-25 02:05:14 -03:00
message
mfd
misc
mmc
mtd
net [NET] sunhme: Kill useless loop over sdevs in quattro_sbus_find(). 2006-06-23 23:16:11 -07:00
nubus
oprofile
parisc
parport [PARPORT] sunbpp: Convert to new SBUS device framework. 2006-06-23 23:16:19 -07:00
pci
pcmcia
pnp
rapidio
rtc
s390
sbus [SBUS]: Rewrite and plug into of_device framework. 2006-06-23 23:15:50 -07:00
scsi [SCSI] qlogicpti: Convert to new SBUS device framework. 2006-06-23 23:16:15 -07:00
serial Merge master.kernel.org:/home/rmk/linux-2.6-arm 2006-06-24 17:48:14 -07:00
sh
sn
spi
tc
telephony
usb Revert "[PATCH] usb: drivers/usb/core/devio.c dereferences a userspace pointer" 2006-06-24 17:47:09 -07:00
video Merge branch 'intelfb-patches' of git://git.kernel.org/pub/scm/linux/kernel/git/airlied/intelfb-2.6 2006-06-24 14:48:35 -07:00
w1
zorro
Kconfig
Makefile