Commit e00c7f1f authored by David S. Miller's avatar David S. Miller

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: default avatarDavid S. Miller <davem@davemloft.net>
parents ab69bde6 b396966c
...@@ -45,17 +45,22 @@ optlen(const u_int8_t *opt, unsigned int offset) ...@@ -45,17 +45,22 @@ optlen(const u_int8_t *opt, unsigned int offset)
static int static int
tcpmss_mangle_packet(struct sk_buff *skb, tcpmss_mangle_packet(struct sk_buff *skb,
const struct xt_tcpmss_info *info, const struct xt_action_param *par,
unsigned int in_mtu, unsigned int in_mtu,
unsigned int tcphoff, unsigned int tcphoff,
unsigned int minlen) unsigned int minlen)
{ {
const struct xt_tcpmss_info *info = par->targinfo;
struct tcphdr *tcph; struct tcphdr *tcph;
unsigned int tcplen, i; unsigned int tcplen, i;
__be16 oldval; __be16 oldval;
u16 newmss; u16 newmss;
u8 *opt; u8 *opt;
/* This is a fragment, no TCP header is available */
if (par->fragoff != 0)
return XT_CONTINUE;
if (!skb_make_writable(skb, skb->len)) if (!skb_make_writable(skb, skb->len))
return -1; return -1;
...@@ -125,11 +130,17 @@ tcpmss_mangle_packet(struct sk_buff *skb, ...@@ -125,11 +130,17 @@ tcpmss_mangle_packet(struct sk_buff *skb,
skb_put(skb, TCPOLEN_MSS); skb_put(skb, TCPOLEN_MSS);
/* RFC 879 states that the default MSS is 536 without specific /*
* knowledge that the destination host is prepared to accept larger. * IPv4: RFC 1122 states "If an MSS option is not received at
* Since no MSS was provided, we MUST NOT set a value > 536. * connection setup, TCP MUST assume a default send MSS of 536".
* IPv6: RFC 2460 states IPv6 has a minimum MTU of 1280 and a minimum
* length IPv6 header of 60, ergo the default MSS value is 1220
* Since no MSS was provided, we must use the default values
*/ */
newmss = min(newmss, (u16)536); if (par->family == NFPROTO_IPV4)
newmss = min(newmss, (u16)536);
else
newmss = min(newmss, (u16)1220);
opt = (u_int8_t *)tcph + sizeof(struct tcphdr); opt = (u_int8_t *)tcph + sizeof(struct tcphdr);
memmove(opt + TCPOLEN_MSS, opt, tcplen - sizeof(struct tcphdr)); 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) ...@@ -188,7 +199,7 @@ tcpmss_tg4(struct sk_buff *skb, const struct xt_action_param *par)
__be16 newlen; __be16 newlen;
int ret; int ret;
ret = tcpmss_mangle_packet(skb, par->targinfo, ret = tcpmss_mangle_packet(skb, par,
tcpmss_reverse_mtu(skb, PF_INET), tcpmss_reverse_mtu(skb, PF_INET),
iph->ihl * 4, iph->ihl * 4,
sizeof(*iph) + sizeof(struct tcphdr)); sizeof(*iph) + sizeof(struct tcphdr));
...@@ -217,7 +228,7 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par) ...@@ -217,7 +228,7 @@ tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)
tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr, &frag_off); tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr, &frag_off);
if (tcphoff < 0) if (tcphoff < 0)
return NF_DROP; return NF_DROP;
ret = tcpmss_mangle_packet(skb, par->targinfo, ret = tcpmss_mangle_packet(skb, par,
tcpmss_reverse_mtu(skb, PF_INET6), tcpmss_reverse_mtu(skb, PF_INET6),
tcphoff, tcphoff,
sizeof(*ipv6h) + sizeof(struct tcphdr)); sizeof(*ipv6h) + sizeof(struct tcphdr));
......
...@@ -48,11 +48,13 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb, ...@@ -48,11 +48,13 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
return NF_DROP; return NF_DROP;
len = skb->len - tcphoff; len = skb->len - tcphoff;
if (len < (int)sizeof(struct tcphdr) || if (len < (int)sizeof(struct tcphdr))
tcp_hdr(skb)->doff * 4 > len)
return NF_DROP; return NF_DROP;
tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff); tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
if (tcph->doff * 4 > len)
return NF_DROP;
opt = (u_int8_t *)tcph; opt = (u_int8_t *)tcph;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment