]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
netfilter: nat: limit port clash resolution attempts
authorFlorian Westphal <fw@strlen.de>
Thu, 3 Feb 2022 12:41:55 +0000 (13:41 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 8 Feb 2022 17:16:27 +0000 (18:16 +0100)
commit6fc2e2f5d1f5aa18a88a58250bec436013044040
treeb55c7bf8abf9de68724ec33f094064e12043cd7e
parent64212979d93de3993cbbaf2833309088f618c430
netfilter: nat: limit port clash resolution attempts

commit a504b703bb1da526a01593da0e4be2af9d9f5fa8 upstream.

In case almost or all available ports are taken, clash resolution can
take a very long time, resulting in soft lockup.

This can happen when many to-be-natted hosts connect to same
destination:port (e.g. a proxy) and all connections pass the same SNAT.

Pick a random offset in the acceptable range, then try ever smaller
number of adjacent port numbers, until either the limit is reached or a
useable port was found.  This results in at most 248 attempts
(128 + 64 + 32 + 16 + 8, i.e. 4 restarts with new search offset)
instead of 64000+,

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Signed-off-by: Vimal Agrawal <vimal.agrawal@sophos.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/netfilter/nf_nat_proto_common.c