From: Tom Herbert Date: Thu, 15 Dec 2016 00:54:15 +0000 (-0800) Subject: inet: Don't go into port scan when looking for specific bind port X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=9af7e923fdd82dc25ad5ea75e24e92708947f961;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git inet: Don't go into port scan when looking for specific bind port inet_csk_get_port is called with port number (snum argument) that may be zero or nonzero. If it is zero, then the intent is to find an available ephemeral port number to bind to. If snum is non-zero then the caller is asking to allocate a specific port number. In the latter case we never want to perform the scan in ephemeral port range. It is conceivable that this can happen if the "goto again" in "tb_found:" is done. This patch adds a check that snum is zero before doing the "goto again". Signed-off-by: Tom Herbert Signed-off-by: David S. Miller --- diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index d5d3ead0a6c3..f59838a60ea5 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -212,7 +212,7 @@ tb_found: sk->sk_reuseport && !rcu_access_pointer(sk->sk_reuseport_cb) && uid_eq(tb->fastuid, uid))) && - smallest_size != -1 && --attempts >= 0) { + !snum && smallest_size != -1 && --attempts >= 0) { spin_unlock_bh(&head->lock); goto again; }