• Xin Long's avatar
    sctp: use sk_wmem_queued to check for writable space · 642dd4d3
    Xin Long authored
    sk->sk_wmem_queued is used to count the size of chunks in out queue
    while sk->sk_wmem_alloc is for counting the size of chunks has been
    sent. sctp is increasing both of them before enqueuing the chunks,
    and using sk->sk_wmem_alloc to check for writable space.
    
    However, sk_wmem_alloc is also increased by 1 for the skb allocked
    for sending in sctp_packet_transmit() but it will not wake up the
    waiters when sk_wmem_alloc is decreased in this skb's destructor.
    
    If msg size is equal to sk_sndbuf and sendmsg is waiting for sndbuf,
    the check 'msg_len <= sctp_wspace(asoc)' in sctp_wait_for_sndbuf()
    will keep waiting if there's a skb allocked in sctp_packet_transmit,
    and later even if this skb got freed, the waiting thread will never
    get waked up.
    
    This issue has been there since very beginning, so we change to use
    sk->sk_wmem_queued to check for writable space as sk_wmem_queued is
    not increased for the skb allocked for sending, also as TCP does.
    
    SOCK_SNDBUF_LOCK check is also removed here as it's for tx buf auto
    tuning which I will add in another patch.
    Signed-off-by: default avatarXin Long <lucien.xin@gmail.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    
    CVE-2019-3874
    
    (backported from commit cd305c74)
    [tyhicks: Backport to 4.4:
     - sctp_sendmsg_to_asoc() does not yet exist and its code is still in
       sctp_sendmsg()
     - sctp_sendmsg() has slight context differences due to timeo being
       unconditionally assigned
     - Minor context differences due to a different #include line
     - sctp_sendmsg() doesn't call sctp_prsctp_prune() due to missing commit
       8dbdf1f5 ("sctp: implement prsctp PRIO policy")]
    Signed-off-by: default avatarTyler Hicks <tyhicks@canonical.com>
    Acked-by: default avatarStefan Bader <stefan.bader@canonical.com>
    Acked-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
    642dd4d3
socket.c 209 KB