• S
    ipv6: fix cleanup ordering for ip6_mr failure · afe49de4
    Sabrina Dubroca 提交于
    Commit 15e66807 ("ipv6: reorder icmpv6_init() and ip6_mr_init()")
    moved the cleanup label for ipmr_fail, but should have changed the
    contents of the cleanup labels as well. Now we can end up cleaning up
    icmpv6 even though it hasn't been initialized (jump to icmp_fail or
    ipmr_fail).
    
    Simply undo things in the reverse order of their initialization.
    
    Example of panic (triggered by faking a failure of icmpv6_init):
    
        kasan: GPF could be caused by NULL-ptr deref or user memory access
        general protection fault: 0000 [#1] PREEMPT SMP KASAN PTI
        [...]
        RIP: 0010:__list_del_entry_valid+0x79/0x160
        [...]
        Call Trace:
         ? lock_release+0x8a0/0x8a0
         unregister_pernet_operations+0xd4/0x560
         ? ops_free_list+0x480/0x480
         ? down_write+0x91/0x130
         ? unregister_pernet_subsys+0x15/0x30
         ? down_read+0x1b0/0x1b0
         ? up_read+0x110/0x110
         ? kmem_cache_create_usercopy+0x1b4/0x240
         unregister_pernet_subsys+0x1d/0x30
         icmpv6_cleanup+0x1d/0x30
         inet6_init+0x1b5/0x23f
    
    Fixes: 15e66807 ("ipv6: reorder icmpv6_init() and ip6_mr_init()")
    Signed-off-by: NSabrina Dubroca <sd@queasysnail.net>
    Signed-off-by: NDavid S. Miller <davem@davemloft.net>
    afe49de4
af_inet6.c 26.8 KB