Skip to content

Commit fa4af3e

Browse files
Florian WestphalRezaT4795
authored andcommitted
netfilter: nf_queue: do not allow packet truncation below transport header offset
[ Upstream commit 99a63d36cb3ed5ca3aa6fcb64cffbeaf3b0fb164 ] 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: 7af4cc3 ("[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> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 4477f5c commit fa4af3e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

net/netfilter/nfnetlink_queue.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,11 +836,16 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
836836
}
837837

838838
static int
839-
nfqnl_mangle(void *data, int data_len, struct nf_queue_entry *e, int diff)
839+
nfqnl_mangle(void *data, unsigned int data_len, struct nf_queue_entry *e, int diff)
840840
{
841841
struct sk_buff *nskb;
842842

843843
if (diff < 0) {
844+
unsigned int min_len = skb_transport_offset(e->skb);
845+
846+
if (data_len < min_len)
847+
return -EINVAL;
848+
844849
if (pskb_trim(e->skb, data_len))
845850
return -ENOMEM;
846851
} else if (diff > 0) {

0 commit comments

Comments
 (0)