From: Daniel Zahka <daniel.zahka@gmail.com>
To: David Carlier <devnexen@gmail.com>, kuba@kernel.org
Cc: willemdebruijn.kernel@gmail.com, davem@davemloft.net,
edumazet@google.com, pabeni@redhat.com, horms@kernel.org,
raeds@nvidia.com, kees@kernel.org, cratiu@nvidia.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] psp: reject packets carrying unsupported PSP optional fields
Date: Thu, 30 Apr 2026 06:32:20 -0400 [thread overview]
Message-ID: <700329b9-e4b5-434e-9678-5a7f067a535a@gmail.com> (raw)
In-Reply-To: <20260430062033.20428-1-devnexen@gmail.com>
On 4/30/26 2:20 AM, David Carlier wrote:
> psp_dev_rcv() documents that it does not support optional PSP fields
> but never enforces it. The helper unconditionally strips a fixed
> PSP_ENCAP_HLEN, so a frame whose PSP header carries options is
> silently mis-decapsulated: option bytes spill into the inner packet
> head and parsing fails downstream on a corrupted skb instead of being
> rejected early.
>
> Validate hdrlen, crypt_offset and PSPHDR_VERFL_VIRT, and hoist the
> psph read above skb_ext_add() so rejected packets do not pick up an
> SKB_EXT_PSP extension only to drop it. Both in-tree callers gate on
> hardware-validated, opt-less PSP, so this is hardening rather than a
> reachable corruption path.
>
> Fixes: 0eddb8023cee ("psp: provide decapsulation and receive helper for drivers")
> Cc: stable@vger.kernel.org
> Signed-off-by: David Carlier <devnexen@gmail.com>
> ---
> net/psp/psp_main.c | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/net/psp/psp_main.c b/net/psp/psp_main.c
> index 524978dfb8fd..53d7e14c054a 100644
> --- a/net/psp/psp_main.c
> +++ b/net/psp/psp_main.c
> @@ -321,12 +321,20 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv)
> if (unlikely(uh->dest != htons(PSP_DEFAULT_UDP_PORT)))
> return -EINVAL;
>
> + psph = (struct psphdr *)(skb->data + l2_hlen + l3_hlen +
> + sizeof(struct udphdr));
> +
> + /* Fixed-length decap; reject optional fields rather than mis-decapsulate. */
> +
> + if (unlikely(psph->hdrlen != PSP_HDRLEN_NOOPT ||
> + psph->crypt_offset ||
> + (psph->verfl & PSPHDR_VERFL_VIRT)))
> + return -EINVAL;
> +
> pse = skb_ext_add(skb, SKB_EXT_PSP);
> if (!pse)
> return -EINVAL;
>
> - psph = (struct psphdr *)(skb->data + l2_hlen + l3_hlen +
> - sizeof(struct udphdr));
> pse->spi = psph->spi;
> pse->dev_id = dev_id;
> pse->generation = generation;
Thanks. There is a bit of a gray area in regards to how much we need to
validate here, because callers ought to use this only downstream of a
real PSP device, and only when that device has emitted some metadata
that the skb was at least parsed as PSP and decrypted correctly. That
being said, the handling of psp hdrlen is definitely a bug, because even
valid values can cause corruption during decap as you noted. I think we
should fix it by validating that it is less than the remaining bytes
after the psp-udp header, and then stripping the correct header length
accordingly.
For the other two, I'm not sure they are really necessary. Mandating
that crypt off is 0 is too restrictive as this function should work just
fine with non-zero values. We could validate that it isn't too long or
misaligned with the payload, but it may be better to have callers know
their NICs PSP implementation and decide if that is necessary. Similar
story with the VC present bit.
In any case, I think this function will also need a comment update
giving some more context for caller, and we can mention that the whole
psp header will be stripped away according the psp hdrlen, and that any
vc or options will be ignored and discarded.
For a fix, you'll need to target the net tree with this patch, (i.e.
"PATCH net").
next prev parent reply other threads:[~2026-04-30 10:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-30 6:20 [PATCH] psp: reject packets carrying unsupported PSP optional fields David Carlier
2026-04-30 10:32 ` Daniel Zahka [this message]
2026-04-30 10:59 ` David CARLIER
2026-05-01 13:00 ` [PATCH net v2] psp: strip variable-length PSP header in psp_dev_rcv() David Carlier
2026-05-01 13:53 ` Willem de Bruijn
2026-05-01 14:13 ` Daniel Zahka
2026-05-01 14:39 ` David CARLIER
2026-05-02 0:00 ` Jakub Kicinski
2026-05-02 0:00 ` Jakub Kicinski
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=700329b9-e4b5-434e-9678-5a7f067a535a@gmail.com \
--to=daniel.zahka@gmail.com \
--cc=cratiu@nvidia.com \
--cc=davem@davemloft.net \
--cc=devnexen@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=raeds@nvidia.com \
--cc=stable@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
/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