Re: [PATCH net-next v5 1/6] psp: support rx rekey operation
From: netdev-bot+sashiko
Date: Sat Nov 21 2026 - 18:03:16 EST
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