From: Ilya Maximets <i.maximets@ovn.org>
To: Kyle Zeng <kylebot@openai.com>, dev@openvswitch.org
Cc: netdev@vger.kernel.org, aconole@redhat.com, echaudro@redhat.com,
i.maximets@ovn.org, davem@davemloft.net, kuba@kernel.org,
edumazet@kernel.org, pabeni@redhat.com, horms@kernel.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH net v4] net: openvswitch: make transport checksums writable
Date: Mon, 23 Nov 2026 05:12:19 +0100 [thread overview]
Message-ID: <ccfbd34e-ce6e-4517-bce1-c68e5ac2bb50@ovn.org> (raw)
In-Reply-To: <20261120191115.39932-1-kylebot@openai.com>
On 11/20/26 8:11 PM, Kyle Zeng wrote:
> OVS can still rewrite an IP address after transport-header extraction
> fails. The checksum helpers check skb->len, which includes non-linear
> data, before directly accessing the L4 checksum. If the transport header
> was not pulled into the linear head, the checksum update can read or
> write beyond it.
>
> Call skb_ensure_writable() before IPv4 TCP/UDP and IPv6 TCP/UDP/ICMPv6
> checksum updates. Save the original addresses and reload header pointers,
> since even a failed pull can move the skb head.
>
> Keep failures nonfatal to preserve the existing policy of rewriting IP
> addresses when the transport header is unavailable. A failed pull or
> unshare may leave a stale checksum or CHECKSUM_PARTIAL seed; the receiver
> may discard the packet.
>
> The issue was found by an LLM.
>
> Fixes: ccb1352e76cf ("net: Add Open vSwitch kernel components.")
> Fixes: 3fdbd1ce11e5 ("openvswitch: add ipv6 'set' action")
> Suggested-by: Ilya Maximets <i.maximets@ovn.org>
> Cc: stable@vger.kernel.org
> Signed-off-by: Kyle Zeng <kylebot@openai.com>
> ---
> v4:
> - Document that both IPv6 checksum addresses must be outside the skb.
> - Use the IPv6 address fields' sizes in the final copies.
>
> v3: https://lore.kernel.org/r/20261113232158.61174-1-kylebot@openai.com
> - Select source and destination addresses with booleans instead of
> calculating offsets. Keep the saved IPv6 address across head movement.
> - Remove the redundant IPv6 fragment check and correct tab alignment.
> - Move testing details below the separator and clean up attribution.
>
> v2: https://lore.kernel.org/r/20261107040238.27606-1-kylebot@openai.com
> v1: https://lore.kernel.org/r/20261030042304.74291-1-kylebot@openai.com
>
> I have a reproducer for this issue and can share through DM.
>
> net/openvswitch/actions.c | 80 +++++++++++++++++++++++++--------------
> 1 file changed, 52 insertions(+), 28 deletions(-)
>
> diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
> index 12e339cbf791..7691f262294d 100644
> --- a/net/openvswitch/actions.c
> +++ b/net/openvswitch/actions.c
> @@ -319,20 +319,22 @@ static int pop_nsh(struct sk_buff *skb, struct sw_flow_key *key)
> return 0;
> }
>
> -static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
> - __be32 addr, __be32 new_addr)
> +static void update_ip_l4_checksum(struct sk_buff *skb, __be32 addr,
> + __be32 new_addr)
> {
> - int transport_len = skb->len - skb_transport_offset(skb);
> + struct iphdr *nh = ip_hdr(skb);
>
> if (nh->frag_off & htons(IP_OFFSET))
> return;
>
> if (nh->protocol == IPPROTO_TCP) {
> - if (likely(transport_len >= sizeof(struct tcphdr)))
> + if (likely(!skb_ensure_writable(skb, skb_transport_offset(skb) +
> + sizeof(struct tcphdr))))
> inet_proto_csum_replace4(&tcp_hdr(skb)->check, skb,
> addr, new_addr, true);
> } else if (nh->protocol == IPPROTO_UDP) {
> - if (likely(transport_len >= sizeof(struct udphdr))) {
> + if (likely(!skb_ensure_writable(skb, skb_transport_offset(skb) +
> + sizeof(struct udphdr)))) {
> struct udphdr *uh = udp_hdr(skb);
>
> if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
> @@ -345,32 +347,37 @@ static void update_ip_l4_checksum(struct sk_buff *skb, struct iphdr *nh,
> }
> }
>
> -static void set_ip_addr(struct sk_buff *skb, struct iphdr *nh,
> - __be32 *addr, __be32 new_addr)
> +/* May move the skb head; callers must reload packet pointers. */
> +static void set_ip_addr(struct sk_buff *skb, __be32 new_addr, bool saddr)
> {
> - update_ip_l4_checksum(skb, nh, *addr, new_addr);
> - csum_replace4(&nh->check, *addr, new_addr);
> + __be32 old_addr = saddr ? ip_hdr(skb)->saddr : ip_hdr(skb)->daddr;
> +
> + update_ip_l4_checksum(skb, old_addr, new_addr);
> + csum_replace4(&ip_hdr(skb)->check, old_addr, new_addr);
> +
> skb_clear_hash(skb);
> ovs_ct_clear(skb, NULL);
> - *addr = new_addr;
> +
> + if (saddr)
> + ip_hdr(skb)->saddr = new_addr;
> + else
> + ip_hdr(skb)->daddr = new_addr;
> }
>
> +/* Neither addr nor new_addr may point into the skb, since
> + * skb_ensure_writable() can move the skb head even on failure.
The 'even on failure' part is not necessary here, as the values are
never used on failure of skb_ensure_writable(). But it's not worth
re-spinning just for this.
Reviewed-by: Ilya Maximets <i.maximets@ovn.org>
prev parent reply other threads:[~2026-11-23 4:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 19:11 [PATCH net v4] net: openvswitch: make transport checksums writable Kyle Zeng
2026-11-23 4:12 ` Ilya Maximets [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=ccfbd34e-ce6e-4517-bce1-c68e5ac2bb50@ovn.org \
--to=i.maximets@ovn.org \
--cc=aconole@redhat.com \
--cc=davem@davemloft.net \
--cc=dev@openvswitch.org \
--cc=echaudro@redhat.com \
--cc=edumazet@kernel.org \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kylebot@openai.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=stable@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox