Skip to content

Commit e00c7f1

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/pablo/nf
Pablo Neira Ayuso says: ==================== The following patchset contains Netfilter fixes. They are targeted to the TCP option targets, that have receive some scrinity in the last week. The changes are: * Fix TCPOPTSTRIP, it stopped working in the forward chain as tcp_hdr uses skb->transport_header, and we cannot use that in the forwarding case, from myself. * Fix default IPv6 MSS in TCPMSS in case of absence of TCP MSS options, from Phil Oester. * Fix missing fragmentation handling again in TCPMSS, from Phil Oester. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents ab69bde + b396966 commit e00c7f1

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

net/netfilter/xt_TCPMSS.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,22 @@ optlen(const u_int8_t *opt, unsigned int offset)
4545

4646
static int
4747
tcpmss_mangle_packet(struct sk_buff *skb,
48-
const struct xt_tcpmss_info *info,
48+
const struct xt_action_param *par,
4949
unsigned int in_mtu,
5050
unsigned int tcphoff,
5151
unsigned int minlen)
5252
{
53+
const struct xt_tcpmss_info *info = par->targinfo;
5354
struct tcphdr *tcph;
5455
unsigned int tcplen, i;
5556
__be16 oldval;
5657
u16 newmss;
5758
u8 *opt;
5859

60+
/* This is a fragment, no TCP header is available */
61+
if (par->fragoff != 0)
62+
return XT_CONTINUE;
63+
5964
if (!skb_make_writable(skb, skb->len))
6065
return -1;
6166

@@ -125,11 +130,17 @@ tcpmss_mangle_packet(struct sk_buff *skb,
125130

126131
skb_put(skb, TCPOLEN_MSS);
127132

128-
/* RFC 879 states that the default MSS is 536 without specific
129-
* knowledge that the destination host is prepared to accept larger.
130-
* Since no MSS was provided, we MUST NOT set a value > 536.
133+
/*
134+
* IPv4: RFC 1122 states "If an MSS option is not received at
135+
* connection setup, TCP MUST assume a default send MSS of 536".
136+
* IPv6: RFC 2460 states IPv6 has a minimum MTU of 1280 and a minimum
137+
* length IPv6 header of 60, ergo the default MSS value is 1220
138+
* Since no MSS was provided, we must use the default values
131139
*/
132-
newmss = min(newmss, (u16)536);
140+
if (par->family == NFPROTO_IPV4)
141+
newmss = min(newmss, (u16)536);
142+
else
143+
newmss = min(newmss, (u16)1220);
133144

134145
opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
135146
memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr));
@@ -188,7 +199,7 @@ tcpmss_tg4(struct sk_buff *skb, const struct xt_action_param *par)
188199
__be16 newlen;
189200
int ret;
190201

191-
ret = tcpmss_mangle_packet(skb, par->targinfo,
202+
ret = tcpmss_mangle_packet(skb, par,
192203
tcpmss_reverse_mtu(skb, PF_INET),
193204
iph->ihl * 4,
194205
sizeof(*iph) + sizeof(struct tcphdr));
@@ -217,7 +228,7 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)
217228
tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr, &frag_off);
218229
if (tcphoff < 0)
219230
return NF_DROP;
220-
ret = tcpmss_mangle_packet(skb, par->targinfo,
231+
ret = tcpmss_mangle_packet(skb, par,
221232
tcpmss_reverse_mtu(skb, PF_INET6),
222233
tcphoff,
223234
sizeof(*ipv6h) + sizeof(struct tcphdr));

net/netfilter/xt_TCPOPTSTRIP.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
4848
return NF_DROP;
4949

5050
len = skb->len - tcphoff;
51-
if (len < (int)sizeof(struct tcphdr) ||
52-
tcp_hdr(skb)->doff * 4 > len)
51+
if (len < (int)sizeof(struct tcphdr))
5352
return NF_DROP;
5453

5554
tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
55+
if (tcph->doff * 4 > len)
56+
return NF_DROP;
57+
5658
opt = (u_int8_t *)tcph;
5759

5860
/*

0 commit comments

Comments
 (0)