From: "Chris Mason" <mason@kernel.org>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
bpf@vger.kernel.org, netdev@vger.kernel.org
Cc: eddyz87@gmail.com, memxor@gmail.com, martin.lau@linux.dev,
song@kernel.org, yonghong.song@linux.dev, jolsa@kernel.org,
emil@etsalapatis.com, ihor.solodrai@linux.dev,
john.fastabend@gmail.com, sdf@fomichev.me, davem@davemloft.net,
edumazet@kernel.org, kuba@kernel.org, pabeni@redhat.com,
willemb@google.com, horms@kernel.org, nhudson@akamai.com,
linux-kernel@vger.kernel.org, mason@kernel.org
Subject: [PATCH bpf 2/2] bpf: Keep skb->transport_header for ESP offload
Date: Sat, 05 Dec 2026 07:58:41 -0500 [thread overview]
Message-ID: <20261205012513.15379-3-mason@kernel.org> (raw)
In-Reply-To: <20261205012513.15379-1-mason@kernel.org>
A decap with bpf_skb_adjust_room() corrupts a non-GSO packet if ESP still
has to encrypt it.
The transport header has to stay at the ESP header until esp_xmit() runs.
bpf_skb_net_shrink() checks for ESP on GSO packets, but not on others:
sch_handle_egress()
bpf_skb_net_shrink() /* decap of IP | IP | ESP | UDP */
bpf_skb_clear_encap() /* transport_header: ESP -> UDP */
validate_xmit_xfrm()
esp_xmit() /* writes the SPI over the UDP header */
The fix used here is to check for a pending ESP offload on non-GSO
packets too.
Fixes: ec20dee2f2c4 ("bpf: Clear decap state on skb_adjust_room shrink path")
Fixes: 33be492c2e23 ("bpf: Use the inner transport header after a decap")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Mason <mason@kernel.org>
---
net/core/filter.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 892e20291283d..001837ff24eb6 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -3880,9 +3880,15 @@ static int bpf_skb_net_shrink(struct sk_buff *skb, u32 off, u32 len_diff,
shinfo->gso_type |= SKB_GSO_DODGY;
shinfo->gso_segs = 0;
} else {
- /* For non-GSO packets, clear encapsulation if decap flags are set */
- if (flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK |
- BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK))
+ struct xfrm_offload *xo = xfrm_offload(skb);
+
+ /*
+ * For non-GSO packets, clear encapsulation if decap flags are
+ * set, unless ESP still has to encrypt the packet.
+ */
+ if ((flags & (BPF_F_ADJ_ROOM_DECAP_L4_MASK |
+ BPF_F_ADJ_ROOM_DECAP_IPXIP_MASK)) &&
+ (!xo || (xo->flags & CRYPTO_DONE)))
bpf_skb_clear_encap(skb, off);
}
prev parent reply other threads:[~2026-12-05 12:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-05 12:56 [PATCH bpf 0/2] bpf: fix skb->transport_header after a decap Chris Mason
2026-12-05 12:57 ` [PATCH bpf 1/2] bpf: Don't use an unset inner transport header Chris Mason
2026-12-05 13:30 ` sashiko-bot
2026-12-05 14:32 ` Chris Mason
2026-12-05 12:58 ` Chris Mason [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261205012513.15379-3-mason@kernel.org \
--to=mason@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=eddyz87@gmail.com \
--cc=edumazet@kernel.org \
--cc=emil@etsalapatis.com \
--cc=horms@kernel.org \
--cc=ihor.solodrai@linux.dev \
--cc=john.fastabend@gmail.com \
--cc=jolsa@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=memxor@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=nhudson@akamai.com \
--cc=pabeni@redhat.com \
--cc=sdf@fomichev.me \
--cc=song@kernel.org \
--cc=willemb@google.com \
--cc=yonghong.song@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.