Patch "netfilter: nf_tables: set transport offset from mac header for netdev/egress" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    netfilter: nf_tables: set transport offset from mac header for netdev/egress

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     netfilter-nf_tables-set-transport-offset-from-mac-he.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 56cc1e9b5b7e464b9e998329d7173330be70efb2
Author: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
Date:   Thu Dec 14 11:50:12 2023 +0100

    netfilter: nf_tables: set transport offset from mac header for netdev/egress
    
    [ Upstream commit 0ae8e4cca78781401b17721bfb72718fdf7b4912 ]
    
    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: 42df6e1d221d ("netfilter: Introduce egress hook")
    Signed-off-by: Pablo Neira Ayuso <pablo@xxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/include/net/netfilter/nf_tables_ipv4.h b/include/net/netfilter/nf_tables_ipv4.h
index d8f6cb47ebe37..5225d2bd1a6e9 100644
--- a/include/net/netfilter/nf_tables_ipv4.h
+++ b/include/net/netfilter/nf_tables_ipv4.h
@@ -30,7 +30,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
 		return -1;
 
 	len = iph_totlen(pkt->skb, iph);
-	thoff = iph->ihl * 4;
+	thoff = skb_network_offset(pkt->skb) + (iph->ihl * 4);
 	if (pkt->skb->len < len)
 		return -1;
 	else if (len < thoff)
diff --git a/net/netfilter/nf_tables_core.c b/net/netfilter/nf_tables_core.c
index cee3e4e905ec8..e0c117229ee9d 100644
--- a/net/netfilter/nf_tables_core.c
+++ b/net/netfilter/nf_tables_core.c
@@ -141,7 +141,7 @@ static bool nft_payload_fast_eval(const struct nft_expr *expr,
 	else {
 		if (!(pkt->flags & NFT_PKTINFO_L4PROTO))
 			return false;
-		ptr = skb_network_header(skb) + nft_thoff(pkt);
+		ptr = skb->data + nft_thoff(pkt);
 	}
 
 	ptr += priv->offset;




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux