]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.9.135/netfilter-check-for-seqadj-ext-existence-before-adding-it-in-nf_nat_setup_info.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.135 / netfilter-check-for-seqadj-ext-existence-before-adding-it-in-nf_nat_setup_info.patch
CommitLineData
7c95fd11
GKH
1From ab6dd1beac7be3c17f8bf3d38bdf29ecb7293f1e Mon Sep 17 00:00:00 2001
2From: Xin Long <lucien.xin@gmail.com>
3Date: Thu, 10 Aug 2017 10:22:24 +0800
4Subject: netfilter: check for seqadj ext existence before adding it in nf_nat_setup_info
5
6From: Xin Long <lucien.xin@gmail.com>
7
8commit ab6dd1beac7be3c17f8bf3d38bdf29ecb7293f1e upstream.
9
10Commit 4440a2ab3b9f ("netfilter: synproxy: Check oom when adding synproxy
11and seqadj ct extensions") wanted to drop the packet when it fails to add
12seqadj ext due to no memory by checking if nfct_seqadj_ext_add returns
13NULL.
14
15But that nfct_seqadj_ext_add returns NULL can also happen when seqadj ext
16already exists in a nf_conn. It will cause that userspace protocol doesn't
17work when both dnat and snat are configured.
18
19Li Shuang found this issue in the case:
20
21Topo:
22 ftp client router ftp server
23 10.167.131.2 <-> 10.167.131.254 10.167.141.254 <-> 10.167.141.1
24
25Rules:
26 # iptables -t nat -A PREROUTING -i eth1 -p tcp -m tcp --dport 21 -j \
27 DNAT --to-destination 10.167.141.1
28 # iptables -t nat -A POSTROUTING -o eth2 -p tcp -m tcp --dport 21 -j \
29 SNAT --to-source 10.167.141.254
30
31In router, when both dnat and snat are added, nf_nat_setup_info will be
32called twice. The packet can be dropped at the 2nd time for DNAT due to
33seqadj ext is already added at the 1st time for SNAT.
34
35This patch is to fix it by checking for seqadj ext existence before adding
36it, so that the packet will not be dropped if seqadj ext already exists.
37
38Note that as Florian mentioned, as a long term, we should review ext_add()
39behaviour, it's better to return a pointer to the existing ext instead.
40
41Fixes: 4440a2ab3b9f ("netfilter: synproxy: Check oom when adding synproxy and seqadj ct extensions")
42Reported-by: Li Shuang <shuali@redhat.com>
43Acked-by: Florian Westphal <fw@strlen.de>
44Signed-off-by: Xin Long <lucien.xin@gmail.com>
45Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
46Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
47
48---
49 net/netfilter/nf_nat_core.c | 2 +-
50 1 file changed, 1 insertion(+), 1 deletion(-)
51
52--- a/net/netfilter/nf_nat_core.c
53+++ b/net/netfilter/nf_nat_core.c
54@@ -421,7 +421,7 @@ nf_nat_setup_info(struct nf_conn *ct,
55 else
56 ct->status |= IPS_DST_NAT;
57
58- if (nfct_help(ct))
59+ if (nfct_help(ct) && !nfct_seqadj(ct))
60 if (!nfct_seqadj_ext_add(ct))
61 return NF_DROP;
62 }