diff options
author | Eric Dumazet <edumazet@google.com> | 2017-04-03 13:55:11 -0400 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2017-04-08 16:24:19 -0400 |
commit | 2638fd0f92d4397884fd991d8f4925cb3f081901 (patch) | |
tree | f7c6cce4be9a84861a75ee58a2106a23cd79b91a | |
parent | 0b9aefea860063bb39e36bd7fe6c7087fed0ba87 (diff) |
netfilter: xt_TCPMSS: add more sanity tests on tcph->doff
Denys provided an awesome KASAN report pointing to an use
after free in xt_TCPMSS
I have provided three patches to fix this issue, either in xt_TCPMSS or
in xt_tcpudp.c. It seems xt_TCPMSS patch has the smallest possible
impact.
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Denys Fedoryshchenko <nuclearcat@nuclearcat.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
-rw-r--r-- | net/netfilter/xt_TCPMSS.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c index 27241a767f17..c64aca611ac5 100644 --- a/net/netfilter/xt_TCPMSS.c +++ b/net/netfilter/xt_TCPMSS.c | |||
@@ -104,7 +104,7 @@ tcpmss_mangle_packet(struct sk_buff *skb, | |||
104 | tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff); | 104 | tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff); |
105 | tcp_hdrlen = tcph->doff * 4; | 105 | tcp_hdrlen = tcph->doff * 4; |
106 | 106 | ||
107 | if (len < tcp_hdrlen) | 107 | if (len < tcp_hdrlen || tcp_hdrlen < sizeof(struct tcphdr)) |
108 | return -1; | 108 | return -1; |
109 | 109 | ||
110 | if (info->mss == XT_TCPMSS_CLAMP_PMTU) { | 110 | if (info->mss == XT_TCPMSS_CLAMP_PMTU) { |
@@ -152,6 +152,10 @@ tcpmss_mangle_packet(struct sk_buff *skb, | |||
152 | if (len > tcp_hdrlen) | 152 | if (len > tcp_hdrlen) |
153 | return 0; | 153 | return 0; |
154 | 154 | ||
155 | /* tcph->doff has 4 bits, do not wrap it to 0 */ | ||
156 | if (tcp_hdrlen >= 15 * 4) | ||
157 | return 0; | ||
158 | |||
155 | /* | 159 | /* |
156 | * MSS Option not found ?! add it.. | 160 | * MSS Option not found ?! add it.. |
157 | */ | 161 | */ |