• James Chapman's avatar
    l2tp: fix tunnel lookup use-after-free race · 28f5bfb8
    James Chapman authored
    l2tp_tunnel_get walks the tunnel list to find a matching tunnel
    instance and if a match is found, its refcount is increased before
    returning the tunnel pointer. But when tunnel objects are destroyed,
    they are on the tunnel list after their refcount hits zero. Fix this
    by moving the code that removes the tunnel from the tunnel list from
    the tunnel socket destructor into in the l2tp_tunnel_delete path,
    before the tunnel refcount is decremented.
    
    refcount_t: increment on 0; use-after-free.
    WARNING: CPU: 3 PID: 13507 at lib/refcount.c:153 refcount_inc+0x47/0x50
    Modules linked in:
    CPU: 3 PID: 13507 Comm: syzbot_6e6a5ec8 Not tainted 4.16.0-rc2+ #36
    Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
    RIP: 0010:refcount_inc+0x47/0x50
    RSP: 0018:ffff8800136ffb20 EFLAGS: 00010286
    RAX: dffffc0000000008 RBX: ffff880017068e68 RCX: ffffffff814d3333
    RDX: 0000000000000000 RSI: ffff88001a59f6d8 RDI: ffff88001a59f6d8
    RBP: ffff8800136ffb28 R08: 00000000000...
    28f5bfb8
l2tp_core.c 48.4 KB