nfc: Avoid endless loops caused by repeated llcp_sock_connect()
authorXiaoming Ni <nixiaoming@huawei.com>
Thu, 25 Mar 2021 03:51:13 +0000 (11:51 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 14 Apr 2021 06:41:57 +0000 (08:41 +0200)
commita12a2fa9a129d3200065fde95f6eb0a98672a2c3
treec6bd2dd28a8b1aae67f1760325740e85b0e76373
parent568ac94df580b1a65837dc299e8758635e7b1423
nfc: Avoid endless loops caused by repeated llcp_sock_connect()

commit 4b5db93e7f2afbdfe3b78e37879a85290187e6f1 upstream.

When sock_wait_state() returns -EINPROGRESS, "sk->sk_state" is
 LLCP_CONNECTING. In this case, llcp_sock_connect() is repeatedly invoked,
 nfc_llcp_sock_link() will add sk to local->connecting_sockets twice.
 sk->sk_node->next will point to itself, that will make an endless loop
 and hang-up the system.
To fix it, check whether sk->sk_state is LLCP_CONNECTING in
 llcp_sock_connect() to avoid repeated invoking.

Fixes: b4011239a08e ("NFC: llcp: Fix non blocking sockets connections")
Reported-by: "kiyin(尹亮)" <kiyin@tencent.com>
Link: https://www.openwall.com/lists/oss-security/2020/11/01/1
Cc: <stable@vger.kernel.org> #v3.11
Signed-off-by: Xiaoming Ni <nixiaoming@huawei.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/nfc/llcp_sock.c