netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH -stable-3.9 01/15] netfilter: xt_TCPOPTSTRIP: fix possible mangling beyond packet boundary
@ 2013-07-02 14:50 Pablo Neira Ayuso
  2013-07-02 14:50 ` [PATCH -stable-3.9 02/15] netfilter: ipt_ULOG: fix non-null terminated string in the nf_log path Pablo Neira Ayuso
                   ` (14 more replies)
  0 siblings, 15 replies; 18+ messages in thread
From: Pablo Neira Ayuso @ 2013-07-02 14:50 UTC (permalink / raw)
  To: netfilter-devel; +Cc: davem, stable

This target assumes that tcph->doff is well-formed, that may be well
not the case. Add extra sanity checkings to avoid possible crash due
to read/write out of the real packet boundary. After this patch, the
default action on malformed TCP packets is to drop them. Moreover,
fragments are skipped.

Reported-by: Rafal Kupka <rkupka@telemetry.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
Cherry-pick: bc6bcb59dd7c184d229f9e86d08aa56059938a4c

 net/netfilter/xt_TCPOPTSTRIP.c |   17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
index 25fd1c4..1eb1a44 100644
--- a/net/netfilter/xt_TCPOPTSTRIP.c
+++ b/net/netfilter/xt_TCPOPTSTRIP.c
@@ -30,17 +30,28 @@ static inline unsigned int optlen(const u_int8_t *opt, unsigned int offset)
 
 static unsigned int
 tcpoptstrip_mangle_packet(struct sk_buff *skb,
-			  const struct xt_tcpoptstrip_target_info *info,
+			  const struct xt_action_param *par,
 			  unsigned int tcphoff, unsigned int minlen)
 {
+	const struct xt_tcpoptstrip_target_info *info = par->targinfo;
 	unsigned int optl, i, j;
 	struct tcphdr *tcph;
 	u_int16_t n, o;
 	u_int8_t *opt;
+	int len;
+
+	/* This is a fragment, no TCP header is available */
+	if (par->fragoff != 0)
+		return XT_CONTINUE;
 
 	if (!skb_make_writable(skb, skb->len))
 		return NF_DROP;
 
+	len = skb->len - tcphoff;
+	if (len < (int)sizeof(struct tcphdr) ||
+	    tcp_hdr(skb)->doff * 4 > len)
+		return NF_DROP;
+
 	tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
 	opt  = (u_int8_t *)tcph;
 
@@ -76,7 +87,7 @@ tcpoptstrip_mangle_packet(struct sk_buff *skb,
 static unsigned int
 tcpoptstrip_tg4(struct sk_buff *skb, const struct xt_action_param *par)
 {
-	return tcpoptstrip_mangle_packet(skb, par->targinfo, ip_hdrlen(skb),
+	return tcpoptstrip_mangle_packet(skb, par, ip_hdrlen(skb),
 	       sizeof(struct iphdr) + sizeof(struct tcphdr));
 }
 
@@ -94,7 +105,7 @@ tcpoptstrip_tg6(struct sk_buff *skb, const struct xt_action_param *par)
 	if (tcphoff < 0)
 		return NF_DROP;
 
-	return tcpoptstrip_mangle_packet(skb, par->targinfo, tcphoff,
+	return tcpoptstrip_mangle_packet(skb, par, tcphoff,
 	       sizeof(*ipv6h) + sizeof(struct tcphdr));
 }
 #endif
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-07-05  8:36 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-02 14:50 [PATCH -stable-3.9 01/15] netfilter: xt_TCPOPTSTRIP: fix possible mangling beyond packet boundary Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 02/15] netfilter: ipt_ULOG: fix non-null terminated string in the nf_log path Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 03/15] netfilter: add nf_ipv6_ops hook to fix xt_addrtype with IPv6 Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 04/15] ipvs: Fix reuse connection if real server is dead Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 05/15] netfilter: xt_LOG: fix mark logging for IPv6 packets Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 06/15] ipvs: info leak in __ip_vs_get_dest_entries() Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 07/15] netfilter: nfnetlink_cttimeout: fix incomplete dumping of objects Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 08/15] netfilter: nfnetlink_acct: " Pablo Neira Ayuso
2013-07-02 14:50 ` [PATCH -stable-3.9 09/15] netfilter: xt_TCPMSS: Fix violation of RFC879 in absence of MSS option Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 10/15] netfilter: xt_TCPOPTSTRIP: don't use tcp_hdr() Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 11/15] netfilter: xt_TCPMSS: Fix missing fragmentation handling Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 12/15] netfilter: xt_TCPMSS: Fix IPv6 default MSS too Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 13/15] ipvs: SCTP ports should be writable in ICMP packets Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 14/15] netfilter: nf_nat_sip: fix mangling Pablo Neira Ayuso
2013-07-02 14:51 ` [PATCH -stable-3.9 15/15] netfilter: ctnetlink: send event when conntrack label was modified Pablo Neira Ayuso
2013-07-04 14:59 ` [PATCH -stable-3.9 01/15] netfilter: xt_TCPOPTSTRIP: fix possible mangling beyond packet boundary Luis Henriques
2013-07-05  5:01   ` Pablo Neira Ayuso
2013-07-05  8:36     ` Luis Henriques

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).