Skip to content

Commit 0ae8e4c

Browse files
committed
netfilter: nf_tables: set transport offset from mac header for netdev/egress
Before this patch, transport offset (pkt->thoff) provides an offset relative to the network header. This is fine for the inet families because skb->data points to the network header in such case. However, from netdev/egress, skb->data points to the mac header (if available), thus, pkt->thoff is missing the mac header length. Add skb_network_offset() to the transport offset (pkt->thoff) for netdev, so transport header mangling works as expected. Adjust payload fast eval function to use skb->data now that pkt->thoff provides an absolute offset. This explains why users report that matching on egress/netdev works but payload mangling does not. This patch implicitly fixes payload mangling for IPv4 packets in netdev/egress given skb_store_bits() requires an offset from skb->data to reach the transport header. I suspect that nft_exthdr and the trace infra were also broken from netdev/egress because they also take skb->data as start, and pkt->thoff was not correct. Note that IPv6 is fine because ipv6_find_hdr() already provides a transport offset starting from skb->data, which includes skb_network_offset(). The bridge family also uses nft_set_pktinfo_ipv4_validate(), but there skb_network_offset() is zero, so the update in this patch does not alter the existing behaviour. Fixes: 42df6e1 ("netfilter: Introduce egress hook") Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 8353c2a commit 0ae8e4c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

include/net/netfilter/nf_tables_ipv4.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
3030
return -1;
3131

3232
len = iph_totlen(pkt->skb, iph);
33-
thoff = iph->ihl * 4;
33+
thoff = skb_network_offset(pkt->skb) + (iph->ihl * 4);
3434
if (pkt->skb->len < len)
3535
return -1;
3636
else if (len < thoff)

net/netfilter/nf_tables_core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr,
158158
else {
159159
if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
160160
return false;
161-
ptr = skb_network_header(skb) + nft_thoff(pkt);
161+
ptr = skb->data + nft_thoff(pkt);
162162
}
163163

164164
ptr += priv->offset;

0 commit comments

Comments
 (0)