Netdev List
 help / color / mirror / Atom feed
From: Simon Horman <horms@kernel.org>
To: steffen.klassert@secunet.com
Cc: 'Simon Horman' <horms@kernel.org>,
	netdev@vger.kernel.org, sd@queasysnail.net,
	tobias@strongswan.org, herbert@gondor.apana.org.au,
	devel@linux-ipsec.org
Subject: Re: [PATCH ipsec-next v2] esp: Consolidate esp4 and esp6
Date: Sat,  9 May 2026 15:00:21 +0100	[thread overview]
Message-ID: <20260509140020.1312473-2-horms@kernel.org> (raw)
In-Reply-To: <afr4ipktV91sA8WU@secunet.com>

From: 'Simon Horman' <horms@kernel.org>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev
---
esp: Consolidate esp4 and esp6

This commit merges the common code from esp4.c and esp6.c into xfrm_esp.c to
reduce duplication. It adapts the input and output encapsulation paths to
use indirect function calls.

> diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
> index 9f75313734f8c..9d6e030510860 100644
> --- a/net/ipv6/esp6.c
> +++ b/net/ipv6/esp6.c
[ ... ]
> +static int esp6_input_encap(struct sk_buff *skb, struct xfrm_state *x)
> +{
> +	const struct ipv6hdr *ip6h = ipv6_hdr(skb);
> +	int offset = skb_network_offset(skb) + sizeof(*ip6h);
> +	struct xfrm_encap_tmpl *encap = x->encap;
> +	int hdr_len = skb_network_header_len(skb);
> +	u8 nexthdr = ip6h->nexthdr;
> +	__be16 frag_off, source;
> +	struct udphdr *uh;
> +	struct tcphdr *th;
> +	int ret;
>  
> +	ret = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
> +	if (ret == -1)
> +		return ret;
>  
> +	ret += hdr_len;
>  
> +	uh = (void *)(skb->data + ret);
> +	th = (void *)(skb->data + ret);

If hdr_len is added to ret before computing the uh and th pointers, does this
cause the pointers to overshoot the transport header by hdr_len bytes?

If uh->source reads from inside the decrypted ESP payload instead of the actual
UDP header, it seems this would almost always mismatch encap->encap_sport.
Could this lead to the kernel unconditionally calling km_new_mapping() on
every received packet, breaking IPv6 NAT-T?

> diff --git a/net/xfrm/xfrm_esp.c b/net/xfrm/xfrm_esp.c
> new file mode 100644
> index 0000000000000..4f75e1ace3bbc
> --- /dev/null
> +++ b/net/xfrm/xfrm_esp.c
[ ... ]
> +#ifdef CONFIG_INET_ESPINTCP
> +static int esp_output_tcp_finish(struct xfrm_state *x, struct sk_buff *skb)
> +{
[ ... ]
> +#else
> +static int esp_output_tail_tcp(struct xfrm_state *x, struct sk_buff *skb)
> +{
> +	WARN_ON(1);
> +	return -EOPNOTSUPP;
> +}
> +#endif
[ ... ]
> +#ifdef CONFIG_INET_ESPINTCP
> +static struct ip_esp_hdr *esp_output_tcp_encap(struct xfrm_state *x,
> +					       struct sk_buff *skb,
> +					       struct esp_info *esp)
[ ... ]
> +#else
> +static struct ip_esp_hdr *esp_output_tcp_encap(struct xfrm_state *x,
> +					       struct sk_buff *skb,
> +					       struct esp_info *esp)
> +{
> +	return ERR_PTR(-EOPNOTSUPP);
> +}
> +#endif

Since the TCP encapsulation methods are guarded exclusively by
CONFIG_INET_ESPINTCP, does this break IPv6 ESP-in-TCP if
CONFIG_INET6_ESPINTCP is enabled but the IPv4 equivalent is disabled?

If CONFIG_INET_ESPINTCP is not enabled, these functions fall back to returning
-EOPNOTSUPP. Should these preprocessor guards check for both
CONFIG_INET_ESPINTCP and CONFIG_INET6_ESPINTCP?

  parent reply	other threads:[~2026-05-09 14:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-06  8:15 [PATCH ipsec-next v2] esp: Consolidate esp4 and esp6 Steffen Klassert
2026-05-09 13:56 ` Simon Horman
2026-05-10  8:06   ` Steffen Klassert
2026-05-09 14:00 ` Simon Horman [this message]
2026-05-10 11:20 ` David Laight

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=20260509140020.1312473-2-horms@kernel.org \
    --to=horms@kernel.org \
    --cc=devel@linux-ipsec.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=netdev@vger.kernel.org \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    --cc=tobias@strongswan.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