linux/drivers/media/dvb-core
Max Kellermann da677fe143 [media] dvb-core/en50221: use kref to manage struct dvb_ca_private
Don't free the object until the file handle has been closed.  Fixes
use-after-free bug which occurs when I disconnect my DVB-S received
while VDR is running.

This is a crash dump of such a use-after-free:

    general protection fault: 0000 [#1] SMP
    CPU: 0 PID: 2541 Comm: CI adapter on d Not tainted 4.7.0-rc1-hosting+ #49
    Hardware name: Bochs Bochs, BIOS Bochs 01/01/2011
    task: ffff880027d7ce00 ti: ffff88003d8f8000 task.ti: ffff88003d8f8000
    RIP: 0010:[<ffffffff812f3d1f>]  [<ffffffff812f3d1f>] dvb_ca_en50221_io_read_condition.isra.7+0x6f/0x150
    RSP: 0018:ffff88003d8fba98  EFLAGS: 00010206
    RAX: 0000000059534255 RBX: 000000753d470f90 RCX: ffff88003c74d181
    RDX: 00000001bea04ba9 RSI: ffff88003d8fbaf4 RDI: 3a3030a56d763fc0
    RBP: ffff88003d8fbae0 R08: ffff88003c74d180 R09: 0000000000000000
    R10: 0000000000000001 R11: 0000000000000000 R12: ffff88003c480e00
    R13: 00000000ffffffff R14: 0000000059534255 R15: 0000000000000000
    FS:  00007fb4209b4700(0000) GS:ffff88003fc00000(0000) knlGS:0000000000000000
    CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
    CR2: 00007f06445f4078 CR3: 000000003c55b000 CR4: 00000000000006b0
    Stack:
     ffff88003d8fbaf4 000000003c2170c0 0000000000004000 0000000000000000
     ffff88003c480e00 ffff88003d8fbc80 ffff88003c74d180 ffff88003d8fbb8c
     0000000000000000 ffff88003d8fbb10 ffffffff812f3e37 ffff88003d8fbb00
    Call Trace:
     [<ffffffff812f3e37>] dvb_ca_en50221_io_poll+0x37/0xa0
     [<ffffffff8113109b>] do_sys_poll+0x2db/0x520

This is a backtrace of the kernel attempting to lock a freed mutex:

    #0  0xffffffff81083d40 in rep_nop () at ./arch/x86/include/asm/processor.h:569
    #1  cpu_relax () at ./arch/x86/include/asm/processor.h:574
    #2  virt_spin_lock (lock=<optimized out>) at ./arch/x86/include/asm/qspinlock.h:57
    #3  native_queued_spin_lock_slowpath (lock=0xffff88003c480e90, val=761492029) at kernel/locking/qspinlock.c:304
    #4  0xffffffff810d1a06 in pv_queued_spin_lock_slowpath (val=<optimized out>, lock=<optimized out>) at ./arch/x86/include/asm/paravirt.h:669
    #5  queued_spin_lock_slowpath (val=<optimized out>, lock=<optimized out>) at ./arch/x86/include/asm/qspinlock.h:28
    #6  queued_spin_lock (lock=<optimized out>) at include/asm-generic/qspinlock.h:107
    #7  __mutex_lock_common (use_ww_ctx=<optimized out>, ww_ctx=<optimized out>, ip=<optimized out>, nest_lock=<optimized out>, subclass=<optimized out>,
        state=<optimized out>, lock=<optimized out>) at kernel/locking/mutex.c:526
    #8  mutex_lock_interruptible_nested (lock=0xffff88003c480e88, subclass=<optimized out>) at kernel/locking/mutex.c:647
    #9  0xffffffff812f49fe in dvb_ca_en50221_io_do_ioctl (file=<optimized out>, cmd=761492029, parg=0x1 <irq_stack_union+1>)
        at drivers/media/dvb-core/dvb_ca_en50221.c:1210
    #10 0xffffffff812ee660 in dvb_usercopy (file=<optimized out>, cmd=761492029, arg=<optimized out>, func=<optimized out>) at drivers/media/dvb-core/dvbdev.c:883
    #11 0xffffffff812f3410 in dvb_ca_en50221_io_ioctl (file=<optimized out>, cmd=<optimized out>, arg=<optimized out>) at drivers/media/dvb-core/dvb_ca_en50221.c:1284
    #12 0xffffffff8112eddd in vfs_ioctl (arg=<optimized out>, cmd=<optimized out>, filp=<optimized out>) at fs/ioctl.c:43
    #13 do_vfs_ioctl (filp=0xffff88003c480e90, fd=<optimized out>, cmd=<optimized out>, arg=<optimized out>) at fs/ioctl.c:674
    #14 0xffffffff8112f30c in SYSC_ioctl (arg=<optimized out>, cmd=<optimized out>, fd=<optimized out>) at fs/ioctl.c:689
    #15 SyS_ioctl (fd=6, cmd=2148298626, arg=140734533693696) at fs/ioctl.c:680
    #16 0xffffffff8103feb2 in entry_SYSCALL_64 () at arch/x86/entry/entry_64.S:207

Signed-off-by: Max Kellermann <max@duempel.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
2016-07-13 15:45:29 -03:00
..
demux.h [media] dvb: use ktime_t for internal timeout 2016-07-08 16:36:00 -03:00
dmxdev.c [media] dvb: use ktime_t for internal timeout 2016-07-08 16:36:00 -03:00
dmxdev.h [media] remove include/linux/dvb/dmx.h 2012-10-19 07:29:17 -03:00
dvb_ca_en50221.c [media] dvb-core/en50221: use kref to manage struct dvb_ca_private 2016-07-13 15:45:29 -03:00
dvb_ca_en50221.h [media] dvb_ca_en50221.h: Make checkpatch.pl happy 2015-10-06 18:40:01 -03:00
dvb_demux.c [media] dvb: use ktime_t for internal timeout 2016-07-08 16:36:00 -03:00
dvb_demux.h [media] dvb: use ktime_t for internal timeout 2016-07-08 16:36:00 -03:00
dvb_filter.c
dvb_filter.h
dvb_frontend.c [media] dvb_frontend: eliminate blocking wait in dvb_unregister_frontend() 2016-07-13 15:43:31 -03:00
dvb_frontend.h [media] dvb_frontend: pass the props cache to get_frontend() as arg 2016-02-04 16:27:30 -02:00
dvb_math.c
dvb_math.h [media] DocBook: add dvb_math.h to documentation 2015-08-22 09:05:40 -03:00
dvb_net.c [media] dvb: use ktime_t for internal timeout 2016-07-08 16:36:00 -03:00
dvb_net.h [media] dvb: push down ioctl lock in dvb_usercopy 2012-12-27 15:44:21 -02:00
dvb_ringbuffer.c [media] media: dvb_ringbuffer: Add memory barriers 2016-07-09 07:57:47 -03:00
dvb_ringbuffer.h [media] DocBook: add dvb_ringbuffer.h to documentation 2015-08-22 09:05:45 -03:00
dvb-usb-ids.h [media] az6027: Add support for Elgato EyeTV Sat v3 2016-05-06 15:53:23 -03:00
dvbdev.c [media] media/dvb-core: forward media_create_pad_links() return value 2016-05-07 10:56:55 -03:00
dvbdev.h [media] mxl111sf: Add a tuner entity 2016-01-11 12:19:26 -02:00
Kconfig
Makefile