Patchwork netfilter: xt_TCPMSS: Add safe fragmentation handling

login
register
mail settings
Submitter Phil Oester
Date June 10, 2013, 4:06 a.m.
Message ID <20130610040634.GB2742@gmail.com>
Download mbox | patch
Permalink /patch/250333/
State Accepted
Headers show

Comments

Phil Oester - June 10, 2013, 4:06 a.m.
Similar to commit bc6bcb59 ("netfilter: xt_TCPOPTSTRIP: fix possible mangling
beyond packet boundary"), add safe fragment handling to xt_TCPMSS.

Phil

Signed-off-by: Phil Oester <kernel@linuxace.com>
Pablo Neira - June 14, 2013, 4:03 p.m.
On Mon, Jun 10, 2013 at 12:06:34AM -0400, Phil Oester wrote:
> Similar to commit bc6bcb59 ("netfilter: xt_TCPOPTSTRIP: fix possible mangling
> beyond packet boundary"), add safe fragment handling to xt_TCPMSS.

Applied, thanks.

I have used the previous changes to make it smaller.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index a75240f..d81b760 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -45,17 +45,22 @@  optlen(const u_int8_t *opt, unsigned int offset)
 
 static int
 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 tcphoff,
 		     unsigned int minlen)
 {
+	const struct xt_tcpmss_info *info = par->targinfo;
 	struct tcphdr *tcph;
 	unsigned int tcplen, i;
 	__be16 oldval;
 	u16 newmss;
 	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))
 		return -1;
 
@@ -182,7 +187,7 @@  tcpmss_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 	__be16 newlen;
 	int ret;
 
-	ret = tcpmss_mangle_packet(skb, par->targinfo,
+	ret = tcpmss_mangle_packet(skb, par,
 				   tcpmss_reverse_mtu(skb, PF_INET),
 				   iph->ihl * 4,
 				   sizeof(*iph) + sizeof(struct tcphdr));
@@ -211,7 +216,7 @@  tcpmss_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 	tcphoff = ipv6_skip_exthdr(skb, sizeof(*ipv6h), &nexthdr, &frag_off);
 	if (tcphoff < 0)
 		return NF_DROP;
-	ret = tcpmss_mangle_packet(skb, par->targinfo,
+	ret = tcpmss_mangle_packet(skb, par,
 				   tcpmss_reverse_mtu(skb, PF_INET6),
 				   tcphoff,
 				   sizeof(*ipv6h) + sizeof(struct tcphdr));