mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: daniel.zahka@gmail.com
Cc: kuba@kernel.org, willemdebruijn.kernel@gmail.com,
	davem@davemloft.net, edumazet@kernel.org, pabeni@redhat.com,
	horms@kernel.org, corbet@lwn.net, skhan@linuxfoundation.org,
	rdunlap@infradead.org, donald.hunter@gmail.com,
	andrew+netdev@lunn.ch, shuah@kernel.org, netdev@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
	linux-kselftest@vger.kernel.org, willemb@google.com
Subject: Re: [PATCH net-next v5 1/6] psp: support rx rekey operation
Date: Sat, 21 Nov 2026 23:03:01 +0000	[thread overview]
Message-ID: <179530218118.3135.6547111851222246419@kernel.org> (raw)
In-Reply-To: <20261118-psp-v5-1-b9ec840e0296@gmail.com>

Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The uAPI doc for the rx-assoc op in
  Documentation/netlink/specs/psp.yaml now reads "If the socket already…
- [Low] psp_assocs_key_rotated() (net/psp/psp_sock.c) now does a plain
  read-modify-write `pas->prev_generation |= ~PSP_GEN_VALID_MASK` on…

--

psp: support rx rekey operation

This commit lets rx-assoc run on a socket that already has full PSP
state. It creates a new psp_assoc that keeps the existing Tx state and
gets new Rx state. The previous Rx SPI and generation are kept as a
fallback, so packets sent by the peer before it switches keys are still
accepted.

> diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
> index f3266763c3253..d5713f5d1af7e 100644
> --- a/Documentation/netlink/specs/psp.yaml
> +++ b/Documentation/netlink/specs/psp.yaml
> @@ -265,7 +265,9 @@ operations:
>  
>      -
>        name: rx-assoc
> -      doc: Allocate a new Rx key + SPI pair, associate it with a socket.
> +      doc: |
> +        Allocate a new Rx key + SPI pair, associate it with a socket.
> +        If the socket already has PSP state, rekey its Rx direction.

[Severity: Low]
Does this doc match the behaviour for every socket that has PSP state?
psp_sock_rx_rekey() in net/psp/psp_sock.c rejects the rekey unless both
directions are set up:

	if (!prev->tx.spi || !prev->peer_tx) {
		NL_SET_ERR_MSG(extack, "Socket PSP state is not fully established");
		return -EBUSY;
	}

So a second rx-assoc on a socket that only has Rx state still fails with
-EBUSY.

psp.rst describes this precondition, but the YAML spec, which ynl and
the generated docs use, does not. Should the op doc say something like
"If the socket already has fully established PSP state, rekey its Rx
direction."?

>        attribute-set: assoc
>        do:
>          request:

[ ... ]

> diff --git a/net/psp/psp_sock.c b/net/psp/psp_sock.c
> index f2cba3fa3a235..c1e38845f08c3 100644
> --- a/net/psp/psp_sock.c
> +++ b/net/psp/psp_sock.c

[ ... ]

> @@ -302,8 +333,21 @@ void psp_assocs_key_rotated(struct psp_dev *psd)
>  	 */
>  	list_for_each_entry_safe(pas, next, &psd->prev_assocs, assocs_list) {
>  		pas->generation |= ~PSP_GEN_VALID_MASK;
> +		pas->prev_generation |= ~PSP_GEN_VALID_MASK;
>  		psd->stats.stales++;
>  	}
> +
> +	/* Don't allow SPI from two generations ago to alias one from the
> +	 * current generation. Rx rekeying under the same device key generation
> +	 * is currently permitted, so skip if the previous SPI is from just one
> +	 * generation ago.
> +	 */
> +	list_for_each_entry(pas, &psd->active_assocs, assocs_list) {
> +		if ((pas->rx.spi ^ pas->prev_spi) &
> +		    cpu_to_be32(PSP_SPI_KEY_PHASE))
> +			pas->prev_generation |= ~PSP_GEN_VALID_MASK;
> +	}

[Severity: Low]
Can these plain writes to prev_generation race with the Rx datapath?

These assocs are still published through sk->psp_assoc. The only lock
held here is psd->lock, which the pre-hook of psp_nl_key_rotate_doit()
takes.

The reader in psp_pse_matches_pas() runs without psd->lock and without
READ_ONCE():

	(pas->prev_spi && pas->prev_spi == pse->spi &&
	 pas->prev_generation == pse->generation));

It is reached from paths that hold only the socket lock or RCU:

  tcp_v4_do_rcv() / tcp_v6_do_rcv()
    -> psp_sk_rx_policy_check()
      -> __psp_sk_rx_policy_check()
        -> psp_pse_matches_pas()

  psp_twsk_rx_policy_check()  (RCU only)
    -> __psp_sk_rx_policy_check()
      -> psp_pse_matches_pas()

So a key-rotate running while PSP packets arrive on an rx-rekeyed socket
is an unannotated data race that KCSAN would report. The field is a u8,
so it can't tear, and the result is unordered against the rotation in
any case.

The existing pas->generation write already works this way. This patch
applies the same pattern to a new field that the datapath reads, and
adds a second write site in the active_assocs loop.

Would it make sense to use WRITE_ONCE() here and READ_ONCE() in
psp_pse_matches_pas()?

> +
>  	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
>  	list_splice_init(&psd->active_assocs, &psd->prev_assocs);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261118-psp-v5-0-b9ec840e0296%40gmail.com

  reply	other threads:[~2026-11-21 23:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 14:08 [PATCH net-next v5 0/6] psp: support rekeying psp protected tcp connections Daniel Zahka
2026-11-18 14:08 ` [PATCH net-next v5 1/6] psp: support rx rekey operation Daniel Zahka
2026-11-21 23:03   ` netdev-bot+sashiko [this message]
2026-11-18 14:08 ` [PATCH net-next v5 2/6] psp: support tx " Daniel Zahka
2026-11-18 14:08 ` [PATCH net-next v5 3/6] psp: document lock ordering with the netdev instance lock Daniel Zahka
2026-11-18 14:08 ` [PATCH net-next v5 4/6] psp: defer tx key deletions for SADB drivers Daniel Zahka
2026-11-21 23:03   ` netdev-bot+sashiko
2026-11-18 14:08 ` [PATCH net-next v5 5/6] selftests: drv-net: psp: factor out psp connection setup Daniel Zahka
2026-11-18 14:08 ` [PATCH net-next v5 6/6] selftests: drv-net: psp: add rekey tests Daniel Zahka
2026-11-21 23:03   ` netdev-bot+sashiko

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=179530218118.3135.6547111851222246419@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=andrew+netdev@lunn.ch \
    --cc=corbet@lwn.net \
    --cc=daniel.zahka@gmail.com \
    --cc=davem@davemloft.net \
    --cc=donald.hunter@gmail.com \
    --cc=edumazet@kernel.org \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rdunlap@infradead.org \
    --cc=shuah@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=willemb@google.com \
    --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

all inboxes | Powered by JetHome®