From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Daniel Zahka <daniel.zahka@gmail.com>,
Donald Hunter <donald.hunter@gmail.com>,
Jakub Kicinski <kuba@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Simon Horman <horms@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Andrew Lunn <andrew+netdev@lunn.ch>
Cc: "Saeed Mahameed" <saeedm@nvidia.com>,
"Leon Romanovsky" <leon@kernel.org>,
"Tariq Toukan" <tariqt@nvidia.com>,
"Boris Pismenny" <borisp@nvidia.com>,
"Kuniyuki Iwashima" <kuniyu@google.com>,
"Willem de Bruijn" <willemb@google.com>,
"David Ahern" <dsahern@kernel.org>,
"Neal Cardwell" <ncardwell@google.com>,
"Patrisious Haddad" <phaddad@nvidia.com>,
"Raed Salem" <raeds@nvidia.com>,
"Jianbo Liu" <jianbol@nvidia.com>,
"Dragos Tatulea" <dtatulea@nvidia.com>,
"Rahul Rameshbabu" <rrameshbabu@nvidia.com>,
"Stanislav Fomichev" <sdf@fomichev.me>,
"Toke Høiland-Jørgensen" <toke@redhat.com>,
"Alexander Lobakin" <aleksander.lobakin@intel.com>,
"Jacob Keller" <jacob.e.keller@intel.com>,
netdev@vger.kernel.org
Subject: Re: [PATCH v3 08/19] net: psp: add socket security association code
Date: Sun, 06 Jul 2025 12:47:16 -0400 [thread overview]
Message-ID: <686aa894a8b6e_3ad0f32946d@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <20250702171326.3265825-9-daniel.zahka@gmail.com>
Daniel Zahka wrote:
> From: Jakub Kicinski <kuba@kernel.org>
>
> Add the ability to install PSP Rx and Tx crypto keys on TCP
> connections. Netlink ops are provided for both operations.
> Rx side combines allocating a new Rx key and installing it
> on the socket. Theoretically these are separate actions,
> but in practice they will always be used one after the
> other. We can add distinct "alloc" and "install" ops later.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> Co-developed-by: Daniel Zahka <daniel.zahka@gmail.com>
> Signed-off-by: Daniel Zahka <daniel.zahka@gmail.com>
> ---
>
> Notes:
> v3:
> - lift pse/pas comparison code into new function:
> psp_pse_matches_pas().
> - explicitly mark rcu critical section psp_reply_set_decrypted()
> - use rcu_dereference_proteced() instead of rcu_read_lock() in
> psp_sk_assoc_free() and psp_twsk_assoc_free()
> - rename psp_is_nondata() to psp_is_allowed_nondata()
> - check for sk_is_inet() before casting to inet_twsk()
> - psp_reply_set_decrypted() should not call psp_sk_assoc()
> - lift common code into psp_sk_get_assoc_rcu()
> - Fix exports with EXPORT_IPV6_MOD_GPL()
>
> v2:
> - add pas->dev_id == pse->dev_id to policy checks
> - __psp_sk_rx_policy_check() now allows pure ACKs, FINs, and RSTs to
> be non-psp authenticated before "PSP Full" state.
> - assign tw_validate_skb funtion during psp_twsk_init()
> - psp_skb_get_rcu() also checks if sk is a tcp timewait sock when
> looking for psp assocs.
> - scan ofo queue non-psp data during psp_sock_recv_queue_check()
> - add tcp_write_collapse_fence() to psp_sock_assoc_set_tx()
> v1:
> - https://lore.kernel.org/netdev/20240510030435.120935-7-kuba@kernel.org/
>
> Documentation/netlink/specs/psp.yaml | 71 +++++++
> include/net/psp/functions.h | 113 +++++++++--
> include/net/psp/types.h | 58 ++++++
> include/uapi/linux/psp.h | 21 ++
> net/psp/Kconfig | 1 +
> net/psp/Makefile | 2 +-
> net/psp/psp-nl-gen.c | 39 ++++
> net/psp/psp-nl-gen.h | 7 +
> net/psp/psp.h | 22 +++
> net/psp/psp_main.c | 11 +-
> net/psp/psp_nl.c | 244 +++++++++++++++++++++++
> net/psp/psp_sock.c | 276 +++++++++++++++++++++++++++
> 12 files changed, 852 insertions(+), 13 deletions(-)
> create mode 100644 net/psp/psp_sock.c
>
> diff --git a/Documentation/netlink/specs/psp.yaml b/Documentation/netlink/specs/psp.yaml
> index 054cc02b65ad..57b24cd6f3f1 100644
> --- a/Documentation/netlink/specs/psp.yaml
> +++ b/Documentation/netlink/specs/psp.yaml
> @@ -38,6 +38,44 @@ attribute-sets:
> type: u32
> enum: version
> enum-as-flags: true
> + -
> + name: assoc
> + attributes:
> + -
> + name: dev-id
> + doc: PSP device ID.
> + type: u32
> + checks:
> + min: 1
> + -
> + name: version
> + doc: |
> + PSP versions (AEAD and protocol version) used by this association,
> + dictates the size of the key.
> + type: u32
> + enum: version
> + -
> + name: rx-key
> + type: nest
> + nested-attributes: keys
> + -
> + name: tx-key
> + type: nest
> + nested-attributes: keys
> + -
> + name: sock-fd
> + doc: Sockets which should be bound to the association immediately.
> + type: u32
> + -
> + name: keys
> + attributes:
> + -
> + name: key
> + type: binary
> + -
> + name: spi
> + doc: Security Parameters Index (SPI) of the association.
> + type: u32
>
> operations:
> list:
> @@ -107,6 +145,39 @@ operations:
> notify: key-rotate
> mcgrp: use
>
> + -
> + name: rx-assoc
> + doc: Allocate a new Rx key + SPI pair, associate it with a socket.
> + attribute-set: assoc
> + do:
> + request:
> + attributes:
> + - dev-id
> + - version
> + - sock-fd
> + reply:
> + attributes:
> + - dev-id
> + - version
Why return the same values as passed in the request?
> + - rx-key
> + pre: psp-assoc-device-get-locked
> + post: psp-device-unlock
> + -
> + name: tx-assoc
> + doc: Add a PSP Tx association.
> + attribute-set: assoc
> + do:
> + request:
> + attributes:
> + - dev-id
> + - version
Version must be the same for rx and tx alloc. It is already set for
rx, so no need to pass explicitly. Just adds the need to for a sanity
check in the handler.
> + - tx-key
> + - sock-fd
> + reply:
> + attributes: []
> + pre: psp-assoc-device-get-locked
> + post: psp-device-unlock
> +
> mcast-groups:
> list:
> -
> +static inline bool
> +psp_pse_matches_pas(struct psp_skb_ext *pse, struct psp_assoc *pas)
> +{
> + return pse && pas->rx.spi == pse->spi &&
> + pas->generation == pse->generation &&
> + pas->version == pse->version &&
> + pas->dev_id == pse->dev_id;
Since struct psp_skb_ext is 64 bits, could almost implement this as
a single 64-bit match. The only outlier is spi, which is rx.spi.
Which also indicates that this is psp_pse_matches_pas_rx.
Still, the other three fields could be a single 32b comparison.
Not sure if worth the effort (using a union or cast, say).
> +struct psp_assoc {
> + struct psp_dev *psd;
> +
> + u16 dev_id;
> + u8 generation;
> + u8 version;
> + u8 key_sz;
implied by version?
> + u8 peer_tx;
> +
> + u32 upgrade_seq;
> +
> + struct psp_key_parsed tx;
> + struct psp_key_parsed rx;
> +
> + refcount_t refcnt;
> + struct rcu_head rcu;
> + struct work_struct work;
> + struct list_head assocs_list;
> +
> + u8 drv_data[] __aligned(8);
> +};
> +
> +int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
> + struct sk_buff *skb, struct genl_info *info)
> +{
> + struct socket *socket;
> + struct psp_dev *psd;
> + struct nlattr *id;
> + struct sock *sk;
> + int fd, err;
> +
> + if (GENL_REQ_ATTR_CHECK(info, PSP_A_ASSOC_SOCK_FD))
> + return -EINVAL;
> +
> + fd = nla_get_u32(info->attrs[PSP_A_ASSOC_SOCK_FD]);
> + socket = sockfd_lookup(fd, &err);
> + if (!socket)
> + return err;
> +
> + sk = socket->sk;
> + if (sk->sk_family != AF_INET && sk->sk_family != AF_INET6) {
> + NL_SET_ERR_MSG_ATTR(info->extack,
> + info->attrs[PSP_A_ASSOC_SOCK_FD],
> + "Unsupported socket family");
Should this also check sk_type?
> +
> +struct psp_dev *psd_get_for_sock(struct sock *sk)
Same as other support functions, consider spelling it out fully as
psp_dev_get_for_sock.
> +{
> + struct dst_entry *dst;
> + struct psp_dev *psd;
> +
> + dst = sk_dst_get(sk);
> + if (!dst)
> + return NULL;
> +
> + rcu_read_lock();
> + psd = rcu_dereference(dst->dev->psp_dev);
> + if (psd && !psp_dev_tryget(psd))
> + psd = NULL;
> + rcu_read_unlock();
> +
> + dst_release(dst);
> +
> + return psd;
> +}
> +void psp_reply_set_decrypted(struct sk_buff *skb)
> +{
> + struct psp_assoc *pas;
> +
> + rcu_read_lock();
> + pas = psp_sk_get_assoc_rcu(skb->sk);
> + if (pas && pas->tx.spi)
> + skb->decrypted = 1;
> + rcu_read_unlock();
> +}
> +EXPORT_IPV6_MOD_GPL(psp_reply_set_decrypted)
semicolon
> --
> 2.47.1
>
next prev parent reply other threads:[~2025-07-06 16:47 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-02 17:13 [PATCH v3 00/19] add basic PSP encryption for TCP connections Daniel Zahka
2025-07-02 17:13 ` [PATCH v3 01/19] psp: add documentation Daniel Zahka
2025-07-06 14:46 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 02/19] psp: base PSP device support Daniel Zahka
2025-07-06 15:31 ` Willem de Bruijn
2025-07-07 21:02 ` Jakub Kicinski
2025-07-08 1:08 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 03/19] net: modify core data structures for PSP datapath support Daniel Zahka
2025-07-06 15:59 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 04/19] tcp: add datapath logic for PSP with inline key exchange Daniel Zahka
2025-07-06 16:16 ` Willem de Bruijn
2025-07-07 18:12 ` Daniel Zahka
2025-07-08 1:11 ` Willem de Bruijn
2025-07-10 11:58 ` Daniel Zahka
2025-07-10 13:57 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 05/19] psp: add op for rotation of device key Daniel Zahka
2025-07-06 16:17 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 06/19] net: move sk_validate_xmit_skb() to net/core/dev.c Daniel Zahka
2025-07-06 16:20 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 07/19] net: tcp: allow tcp_timewait_sock to validate skbs before handing to device Daniel Zahka
2025-07-06 16:23 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 08/19] net: psp: add socket security association code Daniel Zahka
2025-07-06 16:47 ` Willem de Bruijn [this message]
2025-07-07 21:10 ` Jakub Kicinski
2025-07-14 15:10 ` Daniel Zahka
2025-07-07 21:20 ` Jakub Kicinski
2025-07-02 17:13 ` [PATCH v3 09/19] net: psp: update the TCP MSS to reflect PSP packet overhead Daniel Zahka
2025-07-06 16:49 ` Willem de Bruijn
2025-07-06 17:15 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 10/19] psp: track generations of device key Daniel Zahka
2025-07-06 16:56 ` Willem de Bruijn
2025-07-07 21:19 ` Jakub Kicinski
2025-07-08 1:06 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 11/19] net/mlx5e: Support PSP offload functionality Daniel Zahka
2025-07-11 12:54 ` Cosmin Ratiu
2025-07-11 17:41 ` Daniel Zahka
2025-07-02 17:13 ` [PATCH v3 12/19] net/mlx5e: Implement PSP operations .assoc_add and .assoc_del Daniel Zahka
2025-07-11 12:57 ` Cosmin Ratiu
2025-07-02 17:13 ` [PATCH v3 13/19] psp: provide encapsulation helper for drivers Daniel Zahka
2025-07-06 16:59 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 14/19] net/mlx5e: Implement PSP Tx data path Daniel Zahka
2025-07-11 13:06 ` Cosmin Ratiu
2025-07-02 17:13 ` [PATCH v3 15/19] net/mlx5e: Add PSP steering in local NIC RX Daniel Zahka
2025-07-11 12:59 ` Cosmin Ratiu
2025-07-02 17:13 ` [PATCH v3 16/19] net/mlx5e: Configure PSP Rx flow steering rules Daniel Zahka
2025-07-02 17:13 ` [PATCH v3 17/19] psp: provide decapsulation and receive helper for drivers Daniel Zahka
2025-07-06 17:07 ` Willem de Bruijn
2025-07-02 17:13 ` [PATCH v3 18/19] net/mlx5e: Add Rx data path offload Daniel Zahka
2025-07-11 13:01 ` Cosmin Ratiu
2025-07-02 17:13 ` [PATCH v3 19/19] net/mlx5e: Implement PSP key_rotate operation Daniel Zahka
2025-07-03 13:30 ` [PATCH v3 00/19] add basic PSP encryption for TCP connections Tariq Toukan
2025-07-11 13:11 ` Cosmin Ratiu
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=686aa894a8b6e_3ad0f32946d@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=aleksander.lobakin@intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=borisp@nvidia.com \
--cc=corbet@lwn.net \
--cc=daniel.zahka@gmail.com \
--cc=davem@davemloft.net \
--cc=donald.hunter@gmail.com \
--cc=dsahern@kernel.org \
--cc=dtatulea@nvidia.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jacob.e.keller@intel.com \
--cc=jianbol@nvidia.com \
--cc=kuba@kernel.org \
--cc=kuniyu@google.com \
--cc=leon@kernel.org \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=phaddad@nvidia.com \
--cc=raeds@nvidia.com \
--cc=rrameshbabu@nvidia.com \
--cc=saeedm@nvidia.com \
--cc=sdf@fomichev.me \
--cc=tariqt@nvidia.com \
--cc=toke@redhat.com \
--cc=willemb@google.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;
as well as URLs for NNTP newsgroup(s).