Skip to content

Commit

Permalink
netfilter: nft_payload: rebuild vlan header on h_proto access
Browse files Browse the repository at this point in the history
nft can perform merging of adjacent payload requests.
This means that:

ether saddr 00:11 ... ether type 8021ad ...

is a single payload expression, for 8 bytes, starting at the
ethernet source offset.

Check that offset+length is fully within the source/destination mac
addersses.

This bug prevents 'ether type' from matching the correct h_proto in case
vlan tag got stripped.

Fixes: de6843b ("netfilter: nft_payload: rebuild vlan header when needed")
Reported-by: David Ward <david.ward@ll.mit.edu>
Signed-off-by: Florian Westphal <fw@strlen.de>
  • Loading branch information
Florian Westphal committed Oct 4, 2023
1 parent 51e7a66 commit af84f9e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion net/netfilter/nft_payload.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ int nft_payload_inner_offset(const struct nft_pktinfo *pkt)
return pkt->inneroff;
}

static bool nft_payload_need_vlan_copy(const struct nft_payload *priv)
{
unsigned int len = priv->offset + priv->len;

/* data past ether src/dst requested, copy needed */
if (len > offsetof(struct ethhdr, h_proto))
return true;

return false;
}

void nft_payload_eval(const struct nft_expr *expr,
struct nft_regs *regs,
const struct nft_pktinfo *pkt)
Expand All @@ -172,7 +183,7 @@ void nft_payload_eval(const struct nft_expr *expr,
goto err;

if (skb_vlan_tag_present(skb) &&
priv->offset >= offsetof(struct ethhdr, h_proto)) {
nft_payload_need_vlan_copy(priv)) {
if (!nft_payload_copy_vlan(dest, skb,
priv->offset, priv->len))
goto err;
Expand Down

0 comments on commit af84f9e

Please sign in to comment.