• X
    sctp: delay auto_asconf init until binding the first addr · f443b21a
    Xin Long 提交于
    stable inclusion
    from linux-4.19.191
    commit 59339c866e0428fb92bfb3f5290c49a5325d2494
    
    --------------------------------
    
    commit 34e5b011 upstream.
    
    As Or Cohen described:
    
      If sctp_destroy_sock is called without sock_net(sk)->sctp.addr_wq_lock
      held and sp->do_auto_asconf is true, then an element is removed
      from the auto_asconf_splist without any proper locking.
    
      This can happen in the following functions:
      1. In sctp_accept, if sctp_sock_migrate fails.
      2. In inet_create or inet6_create, if there is a bpf program
         attached to BPF_CGROUP_INET_SOCK_CREATE which denies
         creation of the sctp socket.
    
    This patch is to fix it by moving the auto_asconf init out of
    sctp_init_sock(), by which inet_create()/inet6_create() won't
    need to operate it in sctp_destroy_sock() when calling
    sk_common_release().
    
    It also makes more sense to do auto_asconf init while binding the
    first addr, as auto_asconf actually requires an ANY addr bind,
    see it in sctp_addr_wq_timeout_handler().
    
    This addresses CVE-2021-23133.
    
    Fixes: 61023658 ("bpf: Add new cgroup attach type to enable sock modifications")
    Reported-by: NOr Cohen <orcohen@paloaltonetworks.com>
    Signed-off-by: NXin Long <lucien.xin@gmail.com>
    Signed-off-by: NDavid S. Miller <davem@davemloft.net>
    Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
    f443b21a
socket.c 247.2 KB