android_kernel_motorola_sm6375/drivers/media
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Tuomas Tynkkynen 86f95b6314 media: media-request: Fix crash if memory allocation fails
commit e30cc79cc80fd919b697a15c5000d9f57487de8e upstream.

Syzbot reports a NULL-ptr deref in the kref_put() call:

BUG: KASAN: null-ptr-deref in media_request_put drivers/media/mc/mc-request.c:81 [inline]
 kref_put include/linux/kref.h:64 [inline]
 media_request_put drivers/media/mc/mc-request.c:81 [inline]
 media_request_close+0x4d/0x170 drivers/media/mc/mc-request.c:89
 __fput+0x2ed/0x750 fs/file_table.c:281
 task_work_run+0x147/0x1d0 kernel/task_work.c:123
 tracehook_notify_resume include/linux/tracehook.h:188 [inline]
 exit_to_usermode_loop arch/x86/entry/common.c:165 [inline]
 prepare_exit_to_usermode+0x48e/0x600 arch/x86/entry/common.c:196

What led to this crash was an injected memory allocation failure in
media_request_alloc():

FAULT_INJECTION: forcing a failure.
name failslab, interval 1, probability 0, space 0, times 0
 should_failslab+0x5/0x20
 kmem_cache_alloc_trace+0x57/0x300
 ? anon_inode_getfile+0xe5/0x170
 media_request_alloc+0x339/0x440
 media_device_request_alloc+0x94/0xc0
 media_device_ioctl+0x1fb/0x330
 ? do_vfs_ioctl+0x6ea/0x1a00
 ? media_ioctl+0x101/0x120
 ? __media_device_usb_init+0x430/0x430
 ? media_poll+0x110/0x110
 __se_sys_ioctl+0xf9/0x160
 do_syscall_64+0xf3/0x1b0

When that allocation fails, filp->private_data is left uninitialized
which media_request_close() does not expect and crashes.

To avoid this, reorder media_request_alloc() such that
allocating the struct file happens as the last step thus
media_request_close() will no longer get called for a partially created
media request.

Reported-by: [email protected]
Cc: [email protected]
Signed-off-by: Tuomas Tynkkynen <[email protected]>
Fixes: 10905d70d7 ("media: media-request: implement media requests")
Reviewed-by: Hans Verkuil <[email protected]>
Signed-off-by: Sakari Ailus <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
2020-08-19 08:16:24 +02:00
..
cec media: cec: silence shift wrapping warning in __cec_s_log_addrs() 2020-06-22 09:31:02 +02:00
common
dvb-core media: dvbdev: Fix tuner->demod media controller link 2020-06-22 09:30:55 +02:00
dvb-frontends
firewire media: firewire: Using uninitialized values in node_probe() 2020-08-19 08:16:10 +02:00
i2c media: ov5640: fix use of destroyed mutex 2020-06-22 09:31:19 +02:00
mc media: media-request: Fix crash if memory allocation fails 2020-08-19 08:16:24 +02:00
mmc
pci media: rc: prevent memory leak in cx23888_ir_probe 2020-08-05 09:59:40 +02:00
platform media: cros-ec-cec: do not bail on device_init_wakeup failure 2020-08-19 08:16:10 +02:00
radio
rc media: rc: add keymap for Videostrong KII Pro 2020-04-17 10:49:59 +02:00
spi
tuners media: si2157: Better check for running tuner in init 2020-06-22 09:30:50 +02:00
usb media: cxusb-analog: fix V4L2 dependency 2020-08-19 08:16:07 +02:00
v4l2-core media: v4l2-core: fix a use-after-free bug of sd->devnode 2020-04-01 11:02:18 +02:00
Kconfig
Makefile