All of lore.kernel.org
 help / color / mirror / Atom feed
From: Xiao Liang <shaw.leon@gmail.com>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH nf] netfilter: nft_exthdr: Fix non-linear header modification
Date: Fri, 25 Aug 2023 10:14:27 +0800	[thread overview]
Message-ID: <20230825021432.6053-1-shaw.leon@gmail.com> (raw)

nft_tcp_header_pointer() may copy TCP header if it's not linear.
In that case, we should modify the packet rather than the buffer, after
proper skb_ensure_writable().

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
---
 net/netfilter/nft_exthdr.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/net/netfilter/nft_exthdr.c b/net/netfilter/nft_exthdr.c
index 7f856ceb3a66..2189ccc1119c 100644
--- a/net/netfilter/nft_exthdr.c
+++ b/net/netfilter/nft_exthdr.c
@@ -254,13 +254,12 @@ static void nft_exthdr_tcp_set_eval(const struct nft_expr *expr,
 			goto err;
 
 		if (skb_ensure_writable(pkt->skb,
-					nft_thoff(pkt) + i + priv->len))
+					nft_thoff(pkt) + i + priv->offset +
+					priv->len))
 			goto err;
 
-		tcph = nft_tcp_header_pointer(pkt, sizeof(buff), buff,
-					      &tcphdr_len);
-		if (!tcph)
-			goto err;
+		tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
+		opt = (u8 *)tcph;
 
 		offset = i + priv->offset;
 
@@ -325,9 +324,9 @@ static void nft_exthdr_tcp_strip_eval(const struct nft_expr *expr,
 	if (skb_ensure_writable(pkt->skb, nft_thoff(pkt) + tcphdr_len))
 		goto drop;
 
-	opt = (u8 *)nft_tcp_header_pointer(pkt, sizeof(buff), buff, &tcphdr_len);
-	if (!opt)
-		goto err;
+	tcph = (struct tcphdr *)(pkt->skb->data + nft_thoff(pkt));
+	opt = (u8 *)tcph;
+
 	for (i = sizeof(*tcph); i < tcphdr_len - 1; i += optl) {
 		unsigned int j;
 
-- 
2.42.0


             reply	other threads:[~2023-08-25  2:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-25  2:14 Xiao Liang [this message]
2023-08-25  3:11 ` [PATCH nf] netfilter: nft_exthdr: Fix non-linear header modification Florian Westphal
2023-08-25  3:23   ` Xiao Liang
2023-08-25  3:34   ` Xiao Liang
2023-08-25  3:52     ` Florian Westphal

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=20230825021432.6053-1-shaw.leon@gmail.com \
    --to=shaw.leon@gmail.com \
    --cc=fw@strlen.de \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.