* [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths
@ 2026-05-28 15:28 Siho Lee
2026-05-28 16:08 ` Florian Westphal
0 siblings, 1 reply; 3+ messages in thread
From: Siho Lee @ 2026-05-28 15:28 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel, netdev, stable
From e11e35dfd10960ea8ca4258dfa6ed7aeb207179f Mon Sep 17 00:00:00 2001
From: Siho Lee <25esihoya@gmail.com>
Date: Fri, 29 May 2026 00:23:35 +0900
Subject: [PATCH v2] netfilter: nft_payload: validate offset for all csum_type
paths
When csum_type is NFT_PAYLOAD_CSUM_NONE and csum_flags is 0, the
bounds check inside the csum condition block is skipped entirely.
For NFT_PAYLOAD_LL_HEADER, offset is computed as:
offset = skb_mac_header(skb) - skb->data - vlan_hlen
which evaluates to -14 (or -18 with VLAN) after eth_type_trans()
pulls the Ethernet header. This is a valid negative offset that
refers to the Ethernet header area (used by bridge/vlan rules).
However, without any bounds check in the csum=NONE path:
- skb_ensure_writable(skb, max(offset + priv->len, 0)):
max() converts negative values to 0, making it a no-op.
- skb_store_bits(skb, offset, src, priv->len):
A negative offset that exceeds skb headroom writes out of bounds.
Add proper validation after the csum condition block:
- Negative offsets: ensure they fall within skb_headroom(skb)
(bridge/vlan rules legitimately access the Ethernet header)
- Positive offsets: ensure offset + len does not exceed skb->len
Also remove the max() wrapper from skb_ensure_writable() since
the new validation guarantees the offset is within range.
Fixes: d5953d680f7e ("netfilter: nft_payload: sanitize offset and
length before calling skb_checksum()")
Cc: stable@vger.kernel.org
Signed-off-by: Siho Lee <25esihoya@gmail.com>
---
net/netfilter/nft_payload.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 01e13e5255a9..2c891c13bbf5 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -892,7 +892,17 @@ static void nft_payload_set_eval(const struct
nft_expr *expr,
goto err;
}
- if (skb_ensure_writable(skb, max(offset + priv->len, 0)) ||
+ /* Negative offset (LL_HEADER with bridge/vlan) must be within headroom.
+ * Positive offset must be within skb length.
+ */
+ if (offset < 0) {
+ if (-offset > (int)skb_headroom(skb))
+ goto err;
+ } else if (offset + priv->len > skb->len) {
+ goto err;
+ }
+
+ if (skb_ensure_writable(skb, offset + priv->len) ||
skb_store_bits(skb, offset, src, priv->len) < 0)
goto err;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths
2026-05-28 14:12 ` Florian Westphal
@ 2026-05-28 15:28 ` Siho Lee
0 siblings, 0 replies; 3+ messages in thread
From: Siho Lee @ 2026-05-28 15:28 UTC (permalink / raw)
To: Pablo Neira Ayuso, Florian Westphal; +Cc: netfilter-devel, netdev, stable
From e11e35dfd10960ea8ca4258dfa6ed7aeb207179f Mon Sep 17 00:00:00 2001
From: Siho Lee <25esihoya@gmail.com>
Date: Fri, 29 May 2026 00:23:35 +0900
Subject: [PATCH v2] netfilter: nft_payload: validate offset for all csum_type
paths
When csum_type is NFT_PAYLOAD_CSUM_NONE and csum_flags is 0, the
bounds check inside the csum condition block is skipped entirely.
For NFT_PAYLOAD_LL_HEADER, offset is computed as:
offset = skb_mac_header(skb) - skb->data - vlan_hlen
which evaluates to -14 (or -18 with VLAN) after eth_type_trans()
pulls the Ethernet header. This is a valid negative offset that
refers to the Ethernet header area (used by bridge/vlan rules).
However, without any bounds check in the csum=NONE path:
- skb_ensure_writable(skb, max(offset + priv->len, 0)):
max() converts negative values to 0, making it a no-op.
- skb_store_bits(skb, offset, src, priv->len):
A negative offset that exceeds skb headroom writes out of bounds.
Add proper validation after the csum condition block:
- Negative offsets: ensure they fall within skb_headroom(skb)
(bridge/vlan rules legitimately access the Ethernet header)
- Positive offsets: ensure offset + len does not exceed skb->len
Also remove the max() wrapper from skb_ensure_writable() since
the new validation guarantees the offset is within range.
Fixes: d5953d680f7e ("netfilter: nft_payload: sanitize offset and
length before calling skb_checksum()")
Cc: stable@vger.kernel.org
Signed-off-by: Siho Lee <25esihoya@gmail.com>
---
net/netfilter/nft_payload.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 01e13e5255a9..2c891c13bbf5 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -892,7 +892,17 @@ static void nft_payload_set_eval(const struct
nft_expr *expr,
goto err;
}
- if (skb_ensure_writable(skb, max(offset + priv->len, 0)) ||
+ /* Negative offset (LL_HEADER with bridge/vlan) must be within headroom.
+ * Positive offset must be within skb length.
+ */
+ if (offset < 0) {
+ if (-offset > (int)skb_headroom(skb))
+ goto err;
+ } else if (offset + priv->len > skb->len) {
+ goto err;
+ }
+
+ if (skb_ensure_writable(skb, offset + priv->len) ||
skb_store_bits(skb, offset, src, priv->len) < 0)
goto err;
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths
2026-05-28 15:28 [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths Siho Lee
@ 2026-05-28 16:08 ` Florian Westphal
0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2026-05-28 16:08 UTC (permalink / raw)
To: Siho Lee; +Cc: Pablo Neira Ayuso, netfilter-devel, netdev, stable
Siho Lee <25esihoya@gmail.com> wrote:
> For NFT_PAYLOAD_LL_HEADER, offset is computed as:
> offset = skb_mac_header(skb) - skb->data - vlan_hlen
> which evaluates to -14 (or -18 with VLAN) after eth_type_trans()
> pulls the Ethernet header. This is a valid negative offset that
> refers to the Ethernet header area (used by bridge/vlan rules).
>
> However, without any bounds check in the csum=NONE path:
> - skb_ensure_writable(skb, max(offset + priv->len, 0)):
> max() converts negative values to 0, making it a no-op.
Are you sure?
> - skb_store_bits(skb, offset, src, priv->len):
> A negative offset that exceeds skb headroom writes out of bounds.
Sure, but how can that happen? This should be explained here,
because I am NOT seeing a bug in the first place.
> Add proper validation after the csum condition block:
> - Negative offsets: ensure they fall within skb_headroom(skb)
> (bridge/vlan rules legitimately access the Ethernet header)
> - Positive offsets: ensure offset + len does not exceed skb->len
Large offset/len should make skb_copy_bits return an error.
> Also remove the max() wrapper from skb_ensure_writable() since
> the new validation guarantees the offset is within range.
No, this patch still breaks test cases we have. Please figure out
if there is a bug in this code, and if there is, explain it in a way
that I can understand (e.g. provide broken example that triggers OOB).
Then, git clone https://git.netfilter.org/nftables and make sure the
tests pass.
> + if (skb_ensure_writable(skb, offset + priv->len) ||
ensure_writable has unsigned arg, so this -14 + 6 will asks for
4GB and this aborts here.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-05-28 16:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-28 15:28 [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths Siho Lee
2026-05-28 16:08 ` Florian Westphal
-- strict thread matches above, loose matches on Subject: below --
2026-05-28 13:39 [PATCH net] netfilter: nft_payload: move offset bounds check outside csum condition Siho Lee
2026-05-28 14:12 ` Florian Westphal
2026-05-28 15:28 ` [PATCH v2 net] netfilter: nft_payload: validate offset for all csum_type paths Siho Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox