Skip to content

Commit

Permalink
netfilter: nf_queue: do not allow packet truncation below transport h…
Browse files Browse the repository at this point in the history
…eader offset

[ Upstream commit 99a63d3 ]

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 <[email protected]>
Signed-off-by: Florian Westphal <[email protected]>
Reviewed-by: Pablo Neira Ayuso <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
  • Loading branch information
Florian Westphal authored and gregkh committed Aug 1, 2022
1 parent 7fe415d commit d4cc8d6
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion net/netfilter/nfnetlink_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -838,11 +838,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) {
Expand Down

0 comments on commit d4cc8d6

Please sign in to comment.