* [PATCH net 0/2] Netfilter fixes for net
@ 2024-08-28 21:47 Pablo Neira Ayuso
2024-08-28 21:47 ` [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress Pablo Neira Ayuso
2024-08-28 21:47 ` [PATCH net 2/2] netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation Pablo Neira Ayuso
0 siblings, 2 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-08-28 21:47 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, fw
Hi,
The following patchset contains Netfilter fixes for net:
Patch #1 sets on NFT_PKTINFO_L4PROTO for UDP packets less than 4 bytes
payload from netdev/egress by subtracting skb_network_offset() when
validating IPv4 packet length, otherwise 'meta l4proto udp' never
matches.
Patch #2 subtracts skb_network_offset() when validating IPv6 packet
length for netdev/egress.
Please, pull these changes from:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-08-28
Thanks.
----------------------------------------------------------------
The following changes since commit 8af174ea863c72f25ce31cee3baad8a301c0cf0f:
net: mana: Fix race of mana_hwc_post_rx_wqe and new hwc response (2024-08-23 14:24:24 +0100)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf.git nf-24-08-28
for you to fetch changes up to 70c261d500951cf3ea0fcf32651aab9a65a91471:
netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation (2024-08-27 18:11:56 +0200)
----------------------------------------------------------------
netfilter pull request 24-08-28
----------------------------------------------------------------
Pablo Neira Ayuso (2):
netfilter: nf_tables: restore IP sanity checks for netdev/egress
netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation
include/net/netfilter/nf_tables_ipv4.h | 10 ++++++----
include/net/netfilter/nf_tables_ipv6.h | 5 +++--
2 files changed, 9 insertions(+), 6 deletions(-)
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress
2024-08-28 21:47 [PATCH net 0/2] Netfilter fixes for net Pablo Neira Ayuso
@ 2024-08-28 21:47 ` Pablo Neira Ayuso
2024-08-29 9:50 ` patchwork-bot+netdevbpf
2024-08-28 21:47 ` [PATCH net 2/2] netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation Pablo Neira Ayuso
1 sibling, 1 reply; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-08-28 21:47 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, fw
Subtract network offset to skb->len before performing IPv4 header sanity
checks, then adjust transport offset from offset from mac header.
Jorge Ortiz says:
When small UDP packets (< 4 bytes payload) are sent from eth0,
`meta l4proto udp` condition is not met because `NFT_PKTINFO_L4PROTO` is
not set. This happens because there is a comparison that checks if the
transport header offset exceeds the total length. This comparison does
not take into account the fact that the skb network offset might be
non-zero in egress mode (e.g., 14 bytes for Ethernet header).
Fixes: 0ae8e4cca787 ("netfilter: nf_tables: set transport offset from mac header for netdev/egress")
Reported-by: Jorge Ortiz <jorge.ortiz.escribano@gmail.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_tables_ipv4.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/net/netfilter/nf_tables_ipv4.h b/include/net/netfilter/nf_tables_ipv4.h
index 60a7d0ce3080..fcf967286e37 100644
--- a/include/net/netfilter/nf_tables_ipv4.h
+++ b/include/net/netfilter/nf_tables_ipv4.h
@@ -19,7 +19,7 @@ static inline void nft_set_pktinfo_ipv4(struct nft_pktinfo *pkt)
static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
{
struct iphdr *iph, _iph;
- u32 len, thoff;
+ u32 len, thoff, skb_len;
iph = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb),
sizeof(*iph), &_iph);
@@ -30,8 +30,10 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
return -1;
len = iph_totlen(pkt->skb, iph);
- thoff = skb_network_offset(pkt->skb) + (iph->ihl * 4);
- if (pkt->skb->len < len)
+ thoff = iph->ihl * 4;
+ skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
+
+ if (skb_len < len)
return -1;
else if (len < thoff)
return -1;
@@ -40,7 +42,7 @@ static inline int __nft_set_pktinfo_ipv4_validate(struct nft_pktinfo *pkt)
pkt->flags = NFT_PKTINFO_L4PROTO;
pkt->tprot = iph->protocol;
- pkt->thoff = thoff;
+ pkt->thoff = skb_network_offset(pkt->skb) + thoff;
pkt->fragoff = ntohs(iph->frag_off) & IP_OFFSET;
return 0;
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net 2/2] netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation
2024-08-28 21:47 [PATCH net 0/2] Netfilter fixes for net Pablo Neira Ayuso
2024-08-28 21:47 ` [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress Pablo Neira Ayuso
@ 2024-08-28 21:47 ` Pablo Neira Ayuso
1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2024-08-28 21:47 UTC (permalink / raw)
To: netfilter-devel; +Cc: davem, netdev, kuba, pabeni, edumazet, fw
From netdev/egress, skb->len can include the ethernet header, therefore,
subtract network offset from skb->len when validating IPv6 packet length.
Fixes: 42df6e1d221d ("netfilter: Introduce egress hook")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/net/netfilter/nf_tables_ipv6.h | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/include/net/netfilter/nf_tables_ipv6.h b/include/net/netfilter/nf_tables_ipv6.h
index 467d59b9e533..a0633eeaec97 100644
--- a/include/net/netfilter/nf_tables_ipv6.h
+++ b/include/net/netfilter/nf_tables_ipv6.h
@@ -31,8 +31,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
struct ipv6hdr *ip6h, _ip6h;
unsigned int thoff = 0;
unsigned short frag_off;
+ u32 pkt_len, skb_len;
int protohdr;
- u32 pkt_len;
ip6h = skb_header_pointer(pkt->skb, skb_network_offset(pkt->skb),
sizeof(*ip6h), &_ip6h);
@@ -43,7 +43,8 @@ static inline int __nft_set_pktinfo_ipv6_validate(struct nft_pktinfo *pkt)
return -1;
pkt_len = ntohs(ip6h->payload_len);
- if (pkt_len + sizeof(*ip6h) > pkt->skb->len)
+ skb_len = pkt->skb->len - skb_network_offset(pkt->skb);
+ if (pkt_len + sizeof(*ip6h) > skb_len)
return -1;
protohdr = ipv6_find_hdr(pkt->skb, &thoff, -1, &frag_off, &flags);
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress
2024-08-28 21:47 ` [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress Pablo Neira Ayuso
@ 2024-08-29 9:50 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-29 9:50 UTC (permalink / raw)
To: Pablo Neira Ayuso
Cc: netfilter-devel, davem, netdev, kuba, pabeni, edumazet, fw
Hello:
This series was applied to netdev/net.git (main)
by Pablo Neira Ayuso <pablo@netfilter.org>:
On Wed, 28 Aug 2024 23:47:07 +0200 you wrote:
> Subtract network offset to skb->len before performing IPv4 header sanity
> checks, then adjust transport offset from offset from mac header.
>
> Jorge Ortiz says:
>
> When small UDP packets (< 4 bytes payload) are sent from eth0,
> `meta l4proto udp` condition is not met because `NFT_PKTINFO_L4PROTO` is
> not set. This happens because there is a comparison that checks if the
> transport header offset exceeds the total length. This comparison does
> not take into account the fact that the skb network offset might be
> non-zero in egress mode (e.g., 14 bytes for Ethernet header).
>
> [...]
Here is the summary with links:
- [net,1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress
https://git.kernel.org/netdev/net/c/5fd062891897
- [net,2/2] netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation
https://git.kernel.org/netdev/net/c/70c261d50095
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-08-29 9:50 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-28 21:47 [PATCH net 0/2] Netfilter fixes for net Pablo Neira Ayuso
2024-08-28 21:47 ` [PATCH net 1/2] netfilter: nf_tables: restore IP sanity checks for netdev/egress Pablo Neira Ayuso
2024-08-29 9:50 ` patchwork-bot+netdevbpf
2024-08-28 21:47 ` [PATCH net 2/2] netfilter: nf_tables_ipv6: consider network offset in netdev/egress validation Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).