Skip to content

Commit af84f9e

Browse files
author
Florian Westphal
committed
netfilter: nft_payload: rebuild vlan header on h_proto access
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 <[email protected]> Signed-off-by: Florian Westphal <[email protected]>
1 parent 51e7a66 commit af84f9e

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

net/netfilter/nft_payload.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,17 @@ int nft_payload_inner_offset(const struct nft_pktinfo *pkt)
154154
return pkt->inneroff;
155155
}
156156

157+
static bool nft_payload_need_vlan_copy(const struct nft_payload *priv)
158+
{
159+
unsigned int len = priv->offset + priv->len;
160+
161+
/* data past ether src/dst requested, copy needed */
162+
if (len > offsetof(struct ethhdr, h_proto))
163+
return true;
164+
165+
return false;
166+
}
167+
157168
void nft_payload_eval(const struct nft_expr *expr,
158169
struct nft_regs *regs,
159170
const struct nft_pktinfo *pkt)
@@ -172,7 +183,7 @@ void nft_payload_eval(const struct nft_expr *expr,
172183
goto err;
173184

174185
if (skb_vlan_tag_present(skb) &&
175-
priv->offset >= offsetof(struct ethhdr, h_proto)) {
186+
nft_payload_need_vlan_copy(priv)) {
176187
if (!nft_payload_copy_vlan(dest, skb,
177188
priv->offset, priv->len))
178189
goto err;

0 commit comments

Comments
 (0)