From: Florian Westphal <fw@strlen•de>
To: <netdev@vger•kernel.org>
Cc: Paolo Abeni <pabeni@redhat•com>, Jakub Kicinski <kuba@kernel•org>,
"David S. Miller" <davem@davemloft•net>,
Eric Dumazet <edumazet@google•com>,
Florian Westphal <fw@strlen•de>,
Domingo Dirutigliano <pwnzer0tt1@proton•me>,
Pablo Neira Ayuso <pablo@netfilter•org>
Subject: [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset
Date: Tue, 26 Jul 2022 21:20:54 +0200 [thread overview]
Message-ID: <20220726192056.13497-2-fw@strlen.de> (raw)
In-Reply-To: <20220726192056.13497-1-fw@strlen.de>
Domingo Dirutigliano and Nicola Guerrera report kernel panic when
sending nf_queue verdict with 1-byte nfta_payload attribute.
The IP/IPv6 stack pulls the IP(v6) header from the packet after the
input hook.
If user truncates the packet below the header size, this skb_pull() will
result in a malformed skb (skb->len < 0).
Fixes: 7af4cc3fa158 ("[NETFILTER]: Add "nfnetlink_queue" netfilter queue handler over nfnetlink")
Reported-by: Domingo Dirutigliano <pwnzer0tt1@proton•me>
Signed-off-by: Florian Westphal <fw@strlen•de>
Reviewed-by: Pablo Neira Ayuso <pablo@netfilter•org>
---
net/netfilter/nfnetlink_queue.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nfnetlink_queue.c b/net/netfilter/nfnetlink_queue.c
index a364f8e5e698..87a9009d5234 100644
--- a/net/netfilter/nfnetlink_queue.c
+++ b/net/netfilter/nfnetlink_queue.c
@@ -843,11 +843,16 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
}
static int
-nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)
+nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int diff)
{
struct sk_buff *nskb;
if (diff < 0) {
+ unsigned int min_len = skb_transport_offset(e->skb);
+
+ if (data_len < min_len)
+ return -EINVAL;
+
if (pskb_trim(e->skb, data_len))
return -ENOMEM;
} else if (diff > 0) {
--
2.35.1
next prev parent reply other threads:[~2022-07-26 19:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-26 19:20 [PATCH net 0/3] netfilter updates for net Florian Westphal
2022-07-26 19:20 ` Florian Westphal [this message]
2022-07-27 3:10 ` [PATCH net 1/3] netfilter: nf_queue: do not allow packet truncation below transport header offset patchwork-bot+netdevbpf
2022-07-26 19:20 ` [PATCH net 2/3] netfilter: nf_tables: add rescheduling points during loop detection walks Florian Westphal
2022-07-26 19:20 ` [PATCH net 3/3] netfilter: nft_queue: only allow supported familes and hooks 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=20220726192056.13497-2-fw@strlen.de \
--to=fw@strlen$(echo .)de \
--cc=davem@davemloft$(echo .)net \
--cc=edumazet@google$(echo .)com \
--cc=kuba@kernel$(echo .)org \
--cc=netdev@vger$(echo .)kernel.org \
--cc=pabeni@redhat$(echo .)com \
--cc=pablo@netfilter$(echo .)org \
--cc=pwnzer0tt1@proton$(echo .)me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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