netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: davem@davemloft.net, netdev@vger.kernel.org
Subject: [PATCH 13/15] netfilter: tcpmss, optstrip: prefer skb_ensure_writable
Date: Sat,  1 Jun 2019 20:23:38 +0200	[thread overview]
Message-ID: <20190601182340.2662-14-pablo@netfilter.org> (raw)
In-Reply-To: <20190601182340.2662-1-pablo@netfilter.org>

From: Florian Westphal <fw@strlen.de>

This also changes optstrip to only make the tcp header writeable
rather than the entire packet.

Signed-off-by: Florian Westphal <fw@strlen.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 net/netfilter/xt_TCPMSS.c      |  2 +-
 net/netfilter/xt_TCPOPTSTRIP.c | 28 +++++++++++++---------------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/net/netfilter/xt_TCPMSS.c b/net/netfilter/xt_TCPMSS.c
index 98efb202f8b4..3e24443ab81c 100644
--- a/net/netfilter/xt_TCPMSS.c
+++ b/net/netfilter/xt_TCPMSS.c
@@ -89,7 +89,7 @@ tcpmss_mangle_packet(struct sk_buff *skb,
 	if (par->fragoff != 0)
 		return 0;
 
-	if (!skb_make_writable(skb, skb->len))
+	if (skb_ensure_writable(skb, skb->len))
 		return -1;
 
 	len = skb->len - tcphoff;
diff --git a/net/netfilter/xt_TCPOPTSTRIP.c b/net/netfilter/xt_TCPOPTSTRIP.c
index eb92bffff11c..5a274813076a 100644
--- a/net/netfilter/xt_TCPOPTSTRIP.c
+++ b/net/netfilter/xt_TCPOPTSTRIP.c
@@ -31,33 +31,33 @@ 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_action_param *par,
-			  unsigned int tcphoff, unsigned int minlen)
+			  unsigned int tcphoff)
 {
 	const struct xt_tcpoptstrip_target_info *info = par->targinfo;
+	struct tcphdr *tcph, _th;
 	unsigned int optl, i, j;
-	struct tcphdr *tcph;
 	u_int16_t n, o;
 	u_int8_t *opt;
-	int len, tcp_hdrlen;
+	int tcp_hdrlen;
 
 	/* This is a fragment, no TCP header is available */
 	if (par->fragoff != 0)
 		return XT_CONTINUE;
 
-	if (!skb_make_writable(skb, skb->len))
+	tcph = skb_header_pointer(skb, tcphoff, sizeof(_th), &_th);
+	if (!tcph)
 		return NF_DROP;
 
-	len = skb->len - tcphoff;
-	if (len < (int)sizeof(struct tcphdr))
-		return NF_DROP;
-
-	tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
 	tcp_hdrlen = tcph->doff * 4;
+	if (tcp_hdrlen < sizeof(struct tcphdr))
+		return NF_DROP;
 
-	if (len < tcp_hdrlen)
+	if (skb_ensure_writable(skb, tcphoff + tcp_hdrlen))
 		return NF_DROP;
 
-	opt  = (u_int8_t *)tcph;
+	/* must reload tcph, might have been moved */
+	tcph = (struct tcphdr *)(skb_network_header(skb) + tcphoff);
+	opt  = (u8 *)tcph;
 
 	/*
 	 * Walk through all TCP options - if we find some option to remove,
@@ -91,8 +91,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, ip_hdrlen(skb),
-	       sizeof(struct iphdr) + sizeof(struct tcphdr));
+	return tcpoptstrip_mangle_packet(skb, par, ip_hdrlen(skb));
 }
 
 #if IS_ENABLED(CONFIG_IP6_NF_MANGLE)
@@ -109,8 +108,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, tcphoff,
-	       sizeof(*ipv6h) + sizeof(struct tcphdr));
+	return tcpoptstrip_mangle_packet(skb, par, tcphoff);
 }
 #endif
 
-- 
2.11.0


  parent reply	other threads:[~2019-06-01 18:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-01 18:23 [PATCH 00/15] Netfilter/IPVS updates for net-next Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 01/15] ipvs: allow rs_table to contain different real server types Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 02/15] ipvs: add function to find tunnels Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 03/15] ipvs: strip udp tunnel headers from icmp errors Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 04/15] netfilter: xt_owner: Add supplementary groups option Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 05/15] netfilter: nf_flow_table: remove unnecessary variable in flow_offload_tuple Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 06/15] netfilter: nf_tables: free base chain counters from worker Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 07/15] netfilter: bridge: convert skb_make_writable to skb_ensure_writable Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 08/15] netfilter: ipvs: prefer skb_ensure_writable Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 09/15] netfilter: conntrack, nat: " Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 10/15] netfilter: ipv4: " Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 11/15] netfilter: nf_tables: " Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 12/15] netfilter: xt_HL: " Pablo Neira Ayuso
2019-06-01 18:23 ` Pablo Neira Ayuso [this message]
2019-06-01 18:23 ` [PATCH 14/15] netfilter: replace skb_make_writable with skb_ensure_writable Pablo Neira Ayuso
2019-06-01 18:23 ` [PATCH 15/15] ipvs: add checksum support for gue encapsulation Pablo Neira Ayuso
2019-06-01 23:45 ` [PATCH 00/15] Netfilter/IPVS updates for net-next David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190601182340.2662-14-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).