Skip to contentSkip to conversation

psp: introduce socket-less associations

PATCH Superseded Todd Freed 6 participants 64 messages Nov 11 – Nov 18

Subsystems (14)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Todd Freed

author
#0 lore raw

cover psp: introduce socket-less associations

psp associations today are bound to a tcp socket when created. traffic on that socket is encapsulated in transport-mode psp, and encrypted.

this series adds associations which aren't bound to a socket, which allows psp encapsulation and encryption to be applied to forwarded traffic. you can use this to transparently apply psp tunnels to flows, with help from userspace to manage the tc rules and orchestrate key exchange.

the lifecycle of socket-less associations is managed over the psp netlink family. socket-less associations are stored in a small registry, and are addressable by id. the registry does not contain socket associations.

socket-less associations are on the device's association lists, like socket associations. rx ones are therefore marked stale by key rotation in the same way. in this series, nothing acts on socket-less rx associations on key rotation. instead, userspace should replace decap rules for a SPI before its device key has been rotated twice. a follow-up will bring enforcement.

series structure,

1, 2/ prepares psp to work with non-tcp packets

3, 4/ adds the netlink commands for managing socket-less associations

5/ adds a METADATA_PSP dst which carries the socket-less psp association on an skb for tx, and the transmit checks for it

6, 7/ keep mirred and bpf from sending decrypted skbs from egress to ingress, since skb->decrypted depends on direction

8/ limit time-wait psp socket validator to sockets actually in time-wait. the new psp actions check for presence of the validator

9/ adds the act_psp tc actions, psp encap and psp decap. in software, encap is egress only.

10/ adds flower matches on psp header fields, for rx matching

11, 12/ add drv-net tests (netdevsim and hardware)

13/ makes tc-testing run dependsOn probes outside the test namespace, where they currently always fail

14/ adds tc-testing tests

15/ Documentation for socket-less psp associations

a following series adds hardware offload of the psp actions and flower matches, psp tunnel mode (which is offload only and therefore not included here), encap on ingress (also offload only), and the mlx5 implementation for switchdev mode. It's available in the tree below.

relation to the psp fixes in net:

this series is based on net-next, and overlaps with "psp, tls: don't send offloaded contents in cleartext" in net:

https://lore.kernel.org/netdev/[email protected]

when net is merged into net-next:

- net/psp/psp_main.c conflicts around psp_dev_encap_ok(), which both
add: net's only allows tcp, this series' (patch 2) takes any l4 protocol. keep this series' version of the function, and its comments above it and above psp_dev_encapsulate().
- tools/testing/selftests/drivers/net/psp.py and tools/testing/selftests/drivers/net/config conflict: keep both sides (imports, constants, the list of test cases; the NET_ACT_* options).

relation to the netfilter fixes in nf-next:

packets which a psp device decrypted don't have to end in a local psp socket. they can already be forwarded or bridged today, but with socket-less associations that is the intended use, e.g. a router that decaps and forwards. netfilter handles two cases itself, outside the ip stack paths which the net series fixes, and would send such a packet's decrypted contents in clear text:

- the bridge refragments packets which bridge conntrack reassembled (br_ip6_fragment(), nf_br_ip_fragment()), without the check of "net:
don't fragment decrypted skbs".
- the reject code builds its own icmp errors and tcp resets (nf_reject_skb_v4_unreach() and friends), without icmp_send() and icmpv6_send(), which the net series' icmp patches cover.

a separate series to nf-next applies the net series' rules to both:

"netfilter: bridge: don't refragment decrypted skbs" "netfilter: reject: don't reply to decrypted skbs"

https://lore.kernel.org/netfilter-devel/[email protected]

it doesn't depend on this series, and the two don't conflict.

trees:

the full tree, with the net fixes, the nf-next series, this series and the mlx5 offload series, and the conflicts above resolved, is at:

https://github.com/toddfreed/psptc branch psptc

iproute2 tree, with support for the psp action and the psp flower matches, based on iproute2-next. the selftests need it:

https://github.com/toddfreed/iproute2-psptc branch tc-psp

testing:

- netdevsim: drivers/net psp.py passes (57 tests), and tc-testing psp.json (17 tests).
- mlx5 (ConnectX-7, FW 28.48), two hosts: drivers/net psp.py passes:
46 pass, 8 skip (GMAC versions not supported by the device), 3 xfail (netdevsim only).
- each patch builds without warnings with gcc and clang, allmodconfig, W=1.
Todd Freed (15):
psp: get netns from net_device instead of sock
psp: take the psp nexthdr from the packet on encap
psp: declare psp_assoc_set_tx() in psp.h
psp: add support for socket-less psp associations
net: add METADATA_PSP dst to carry a psp association on an skb net/sched: act_mirred: don't send decrypted skbs from egress to
ingress
bpf: don't redirect decrypted skbs from egress to ingress
psp: only give time-wait sockets of psp connections a validator net/sched: add act_psp for psp transport mode
net/sched: flower: add psp_spi, psp_ver, and psp_dev matches
selftests: drv-net: psp: test socket-less associations and the tc psp
action
selftests: drv-net: psp: test that software encap on ingress drops
selftests: tc-testing: run dependsOn probes outside the test namespace
selftests: tc-testing: add tests for the psp action
Documentation: networking: psp: document socket-less associations

 Documentation/netlink/specs/psp.yaml          |  98 ++-
 Documentation/netlink/specs/tc.yaml           |  14 +
 Documentation/networking/psp.rst              | 139 +++-
 MAINTAINERS                                   |   3 +
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |   2 +-
 .../net/ethernet/mellanox/mlx5/core/en_main.c |  33 +
 drivers/net/netdevsim/psp.c                   |   2 +-
 include/linux/skbuff.h                        |   4 +
 include/net/dst_metadata.h                    |  19 +
 include/net/flow_dissector.h                  |  18 +
 include/net/psp/functions.h                   |  91 ++-
 include/net/psp/types.h                       |   1 +
 include/net/tc_act/tc_psp.h                   |  23 +
 include/uapi/linux/pkt_cls.h                  |   6 +
 include/uapi/linux/psp.h                      |   6 +
 include/uapi/linux/tc_act/tc_psp.h            |  28 +
 net/core/dev.c                                |  48 +-
 net/core/dst.c                                |   5 +
 net/core/filter.c                             |   9 +
 net/core/flow_dissector.c                     |  27 +
 net/psp/Makefile                              |   2 +-
 net/psp/psp-nl-gen.c                          |  60 ++
 net/psp/psp-nl-gen.h                          |   8 +
 net/psp/psp.h                                 |   7 +
 net/psp/psp_assoc.c                           | 120 +++
 net/psp/psp_main.c                            |  54 +-
 net/psp/psp_nl.c                              | 261 ++++++
 net/psp/psp_sock.c                            |  32 +-
 net/sched/Kconfig                             |  13 +
 net/sched/Makefile                            |   1 +
 net/sched/act_mirred.c                        |   6 +
 net/sched/act_psp.c                           | 439 ++++++++++
 net/sched/cls_flower.c                        |  64 ++
 tools/testing/selftests/drivers/net/config    |   5 +
 tools/testing/selftests/drivers/net/psp.py    | 750 +++++++++++++++++-
 tools/testing/selftests/tc-testing/config     |   2 +
 .../tc-testing/tc-tests/actions/psp.json      | 459 +++++++++++
 tools/testing/selftests/tc-testing/tdc.py     |   2 +-
 tools/testing/selftests/tc-testing/tdc.sh     |   1 +
 39 files changed, 2812 insertions(+), 50 deletions(-)
 create mode 100644 include/net/tc_act/tc_psp.h
 create mode 100644 include/uapi/linux/tc_act/tc_psp.h
 create mode 100644 net/psp/psp_assoc.c
 create mode 100644 net/sched/act_psp.c
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/psp.json

base-commit: ed04b202027249e2769420893220f54a56e0c59a

Signature · 1 line
2.53.0-Meta
author
#1 lore raw

PATCH 1/15 psp: get netns from net_device instead of sock

every psp skb is related to a socket today, but that will no longer be true once a psp association can be attached to the skb by other means, such as tc flower rules added later in the series.

get the netns from the transmitting device instead.

for the outer source port range, psp_write_headers() now explicitly uses sock_net(sk) in the socket case specifically, to maintain the existing behavior.

---
 drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c | 2 +-
 drivers/net/netdevsim/psp.c                                 | 2 +-
 net/psp/psp_main.c                                          | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +1 -1
index 348fd7a96261..8b474f75dd61 100644
@@ -165,7 +165,7 @@ bool mlx5e_psp_handle_tx_skb(struct net_device *netdev,
 			     struct mlx5e_accel_tx_psp_state *psp_st)
 {
 	struct mlx5e_priv *priv = netdev_priv(netdev);
-	struct net *net = sock_net(skb->sk);
+	struct net *net = dev_net(netdev);
 
 	if (!mlx5e_psp_set_state(priv, skb, psp_st))
 		return true;
drivers/net/netdevsim/psp.c +1 -1
index b7452c49b581..0701f38aee6d 100644
@@ -36,7 +36,7 @@ nsim_do_psp(struct sk_buff *skb, struct netdevsim *ns,
 		goto out_unlock;
 	}
 
-	net = sock_net(skb->sk);
+	net = dev_net(ns->netdev);
 	if (!psp_dev_encapsulate(net, skb, pas->tx.spi, pas->version, 0)) {
 		rc = SKB_DROP_REASON_PSP_OUTPUT;
 		goto out_unlock;
net/psp/psp_main.c +1 -1
index 273b010d2355..e09f6fec948d 100644
@@ -221,7 +221,7 @@ static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi,
 		/* These operations are cheap, no need to cache the result
 		 * in another socket field.
 		 */
-		inet_get_local_port_range(net, &min, &max);
+		inet_get_local_port_range(sock_net(sk), &min, &max);
 		/* Since this is being sent on the wire obfuscate hash a bit
 		 * to minimize possibility that any useful information to an
 		 * attacker is leaked. Only upper 16 bits are relevant in the
Signature · 1 line
2.53.0-Meta
author
#42 lore raw

PATCH 10/15 net/sched: flower: add psp_spi, psp_ver, and psp_dev matches

In reply to Todd Freed

Add a flow dissector key filled from the PSP Rx state (SKB_EXT_PSP) the device attached to a decrypted packet, and corresponding flower matches. SPI the packet was decrypted with (psp_spi, with a mask), PSP version (psp_ver), and the ID of the PSP device which decrypted it (psp_dev).

For example, to take the packets of one Rx association, (created with rx-spi-alloc), and remove their PSP state so that they can be forwarded,

tc filter add dev eth0 ingress protocol ipv6 flower
psp_spi 0x80000001 psp_ver 0 psp_dev 1 action psp decap

Together these matches tie a rule to one association, in a form which hw can match on (offload comes in a follow-up series). The SPI is only unique on its PSP device, and an association has one PSP version. This matches the per-packet check that psp sockets have against its association, with one exception - the generation of the device key is not checked.

this means that a rule matching packets that correspond to an rx association which is stale (two rotations have passed), can still match.

It is therefore important that a rule which matches a SPI should be replaced before the device key has had two rotations. follow up work will bring enforcement of this based on key rotation events.

Note that this only ever matches packets which were decrypted, even if the mask is 0. So "psp_spi 0/0" matches any decrypted PSP packet.

---
 Documentation/netlink/specs/tc.yaml | 14 +++++++
 include/linux/skbuff.h              |  4 ++
 include/net/flow_dissector.h        | 18 ++++++++
 include/uapi/linux/pkt_cls.h        |  5 +++
 net/core/flow_dissector.c           | 27 ++++++++++++
 net/sched/cls_flower.c              | 64 +++++++++++++++++++++++++++++
 6 files changed, 132 insertions(+)
Documentation/netlink/specs/tc.yaml +14 -0
index b6ccc645b0e3..044938316ffd 100644
@@ -2908,6 +2908,20 @@ attribute-sets:
         byte-order: big-endian
         enum: flower-key-ctrl-flags
         enum-as-flags: true
+      -
+        name: key-psp-spi
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-psp-spi-mask
+        type: u32
+        byte-order: big-endian
+      -
+        name: key-psp-version
+        type: u8
+      -
+        name: key-psp-dev
+        type: u32
   -
     name: flower-key-enc-opts-attrs
     name-prefix: tca-flower-key-enc-opts-
include/linux/skbuff.h +4 -0
index 73365c5de6f9..e65de3f5c136 100644
@@ -1660,6 +1660,10 @@ void skb_flow_dissect_hash(const struct sk_buff *skb,
 			   struct flow_dissector *flow_dissector,
 			   void *target_container);
 
+void skb_flow_dissect_psp(const struct sk_buff *skb,
+			  struct flow_dissector *flow_dissector,
+			  void *target_container);
+
 static inline __u32 skb_get_hash_net(const struct net *net, struct sk_buff *skb)
 {
 	if (!skb->l4_hash && !skb->sw_hash)
include/net/flow_dissector.h +18 -0
index ced79dc8e856..151ae03d5ad5 100644
@@ -339,6 +339,23 @@ struct flow_dissector_key_cfm {
 	u8	opcode;
 };
 
+/**
+ * struct flow_dissector_key_psp - PSP Rx state of a decrypted packet
+ * @spi: SPI of the PSP association the packet was decrypted with
+ * @dev_id: ID of the PSP device which decrypted the packet
+ * @version: PSP version (enum psp_version) the packet was decrypted with
+ * @present: packet was decrypted by a PSP device
+ *
+ * Taken from the PSP Rx state the device attached to the skb, not from the
+ * packet, which no longer carries the PSP header.
+ */
+struct flow_dissector_key_psp {
+	__be32	spi;
+	u16	dev_id;
+	u8	version;
+	u8	present;
+};
+
 #define FLOW_DIS_CFM_MDL_MASK GENMASK(7, 5)
 #define FLOW_DIS_CFM_MDL_MAX 7
 
@@ -376,6 +393,7 @@ enum flow_dissector_key_id {
 	FLOW_DISSECTOR_KEY_L2TPV3, /* struct flow_dissector_key_l2tpv3 */
 	FLOW_DISSECTOR_KEY_CFM, /* struct flow_dissector_key_cfm */
 	FLOW_DISSECTOR_KEY_IPSEC, /* struct flow_dissector_key_ipsec */
+	FLOW_DISSECTOR_KEY_PSP, /* struct flow_dissector_key_psp */
 
 	FLOW_DISSECTOR_KEY_MAX,
 };
include/uapi/linux/pkt_cls.h +5 -0
index 14cff8f5da74..0cfa7425404b 100644
@@ -561,6 +561,11 @@ enum {
 	TCA_FLOWER_KEY_ENC_FLAGS,	/* be32 */
 	TCA_FLOWER_KEY_ENC_FLAGS_MASK,	/* be32 */
 
+	TCA_FLOWER_KEY_PSP_SPI,		/* be32 */
+	TCA_FLOWER_KEY_PSP_SPI_MASK,	/* be32 */
+	TCA_FLOWER_KEY_PSP_VERSION,	/* u8, enum psp_version */
+	TCA_FLOWER_KEY_PSP_DEV,		/* u32, PSP device ID */
+
 	__TCA_FLOWER_MAX,
 };
 
net/core/flow_dissector.c +27 -0
index 1be6c739e3c7..95d3fa3b1568 100644
@@ -28,6 +28,7 @@
 #include <linux/ptp_classify.h>
 #include <net/flow_dissector.h>
 #include <net/pkt_cls.h>
+#include <net/psp/types.h>
 #include <scsi/fc/fc_fcoe.h>
 #include <uapi/linux/batadv_packet.h>
 #include <linux/bpf.h>
@@ -511,6 +512,32 @@ void skb_flow_dissect_hash(const struct sk_buff *skb,
 }
 EXPORT_SYMBOL(skb_flow_dissect_hash);
 
+void skb_flow_dissect_psp(const struct sk_buff *skb,
+			  struct flow_dissector *flow_dissector,
+			  void *target_container)
+{
+#if IS_ENABLED(CONFIG_INET_PSP)
+	struct flow_dissector_key_psp *key;
+	struct psp_skb_ext *pse;
+
+	if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PSP))
+		return;
+
+	pse = skb_ext_find(skb, SKB_EXT_PSP);
+	if (!pse)
+		return;
+
+	key = skb_flow_dissector_target(flow_dissector,
+					FLOW_DISSECTOR_KEY_PSP,
+					target_container);
+	key->spi = pse->spi;
+	key->dev_id = pse->dev_id;
+	key->version = pse->version;
+	key->present = 1;
+#endif
+}
+EXPORT_SYMBOL(skb_flow_dissect_psp);
+
 static enum flow_dissect_ret
 __skb_flow_dissect_mpls(const struct sk_buff *skb,
 			struct flow_dissector *flow_dissector,
net/sched/cls_flower.c +64 -0

106 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
author
#22 lore raw

PATCH 6/15 net/sched: act_mirred: don't send decrypted skbs from egress to ingress

In reply to Todd Freed

on transmit, skb->decrypted means the device must encrypt the packet. For example, a packet of a ktls or psp offload socket, or, with the tc psp action added later in this series, one which psp encap attached a tx association to.

on receive, skb->decrypted means the device decrypted the packet.

a packet redirected or mirrored from egress to ingress is by definition not going to the device that would encrypt it, and on ingress skb->decrypted now (incorrectly, for this packet) indicates it was decrypted by the device.

this is less of a problem with socket offloads, whose packets are by definition originated locally; more of a problem with socket-less psp, which can also apply to forwarded traffic.

mirred also drops the dst, which for socket-less psp carries the tx association. clearing the bit instead would let the packet be forwarded in clear text, so that wouldn't work.

don't send decrypted skbs from egress to ingress: a redirected one is dropped, a mirrored one isn't copied.

---
 net/sched/act_mirred.c | 6 ++++++
 1 file changed, 6 insertions(+)
net/sched/act_mirred.c +6 -0
index 1c98e4d81ebe..52c3eeab381a 100644
@@ -285,6 +285,12 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
 		goto err_cant_do;
 	}
 
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */
+	if (unlikely(want_ingress && !at_ingress && skb_is_decrypted(skb)))
+		goto err_cant_do;
+
 	/* we could easily avoid the clone only if called by ingress and clsact;
 	 * since we can't easily detect the clsact caller, skip clone only for
 	 * ingress - that covers the TC S/W datapath.
Signature · 1 line
2.53.0-Meta
author
#25 lore raw

PATCH 7/15 bpf: don't redirect decrypted skbs from egress to ingress

In reply to Todd Freed

on transmit, skb->decrypted means the device must encrypt the packet. For example, a packet of a ktls or psp offload socket, or, with the tc psp action added later in this series, one which psp encap attached a tx association to.

on receive, skb->decrypted means the device decrypted the packet.

bpf_redirect() and bpf_clone_redirect() with BPF_F_INGRESS send the packet to a device's receive path with the bit still set, where it indicates the packet was decrypted by the device.

this is less of a problem with socket offloads, whose packets are by definition generated locally; more of a problem with socket-less psp, which can also apply to forwarded traffic.

in addition, the redirect drops the dst (skb_scrub_packet()), which for socket-less psp carries the tx association.

drop decrypted skbs which bpf redirects from egress to ingress. this matches the behavior of mirred, since the previous patch.

---
 net/core/filter.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/core/filter.c +9 -0
index aca8160b26a1..a178a9dd3007 100644
@@ -2226,6 +2226,15 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
 static int __bpf_redirect(struct sk_buff *skb, struct net_device *dev,
 			  u32 flags)
 {
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */
+	if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
+		     skb_is_decrypted(skb))) {
+		kfree_skb(skb);
+		return -EINVAL;
+	}
+
 	if (dev_is_mac_header_xmit(dev))
 		return __bpf_redirect_common(skb, dev, flags);
 	else
Signature · 1 line
2.53.0-Meta
author
#3 lore raw

PATCH 2/15 psp: take the psp nexthdr from the packet on encap

In reply to Todd Freed

psp sockets support has thus far been limited to tcp, and psp_dev_encapsulate() hardcodes IPPROTO_TCP as the psp nexthdr

socket-less psp associations will also support udp traffic. populate the psp nexthdr from the ip header of the original packet instead.

with the psp nexthdr taken from the fixed header, psp_dev_encapsulate() indicates some cases which are unsupported,

- ipv6 extension headers present. more generally, any packet whose transport header isn't right after the fixed ip header. some of these could be supported in the future. not a behavior change for psp sockets.
- ipv4 fragments. non-initial fragments have no l4 header, so this cannot work. not a behavior change for psp sockets.
- already encapsulated for a tunnel (skb->encapsulation). their inner headers are already set up.

both callers of psp_dev_encapsulate(), mlx5 and netdevsim, drop the packet when it returns false.

mlx5e also fixes up the tcp checksum of gso skbs for the device, which is only valid for tcp. have the stack segment other gso skbs, e.g. udp from socket-less associations, in software. likewise the device only completes a tcp or udp checksum behind the psp header: have the stack checksum the other CHECKSUM_PARTIAL skbs.

---
 .../net/ethernet/mellanox/mlx5/core/en_main.c | 33 ++++++++++++
 net/psp/psp_main.c                            | 50 ++++++++++++++++---
 2 files changed, 75 insertions(+), 8 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +33 -0
index c3c2c5720c6f..d091de1a5992 100644
@@ -5132,6 +5132,23 @@ static netdev_features_t mlx5e_tunnel_features_check(struct mlx5e_priv *priv,
 	return features & ~(NETIF_F_CSUM_MASK | NETIF_F_GSO_MASK);
 }
 
+/* The L4 protocol right after the fixed IP header, which the PSP Tx path
+ * requires, is one the device can complete the checksum of
+ */
+static bool mlx5e_psp_l4_csum_ok(const struct sk_buff *skb)
+{
+	u8 proto;
+
+	if (skb->protocol == htons(ETH_P_IP))
+		proto = ip_hdr(skb)->protocol;
+	else if (skb->protocol == htons(ETH_P_IPV6))
+		proto = ipv6_hdr(skb)->nexthdr;
+	else
+		return false;
+
+	return proto == IPPROTO_TCP || proto == IPPROTO_UDP;
+}
+
 netdev_features_t mlx5e_features_check(struct sk_buff *skb,
 				       struct net_device *netdev,
 				       netdev_features_t features)
@@ -5140,6 +5157,22 @@ netdev_features_t mlx5e_features_check(struct sk_buff *skb,
 
 	features = vlan_features_check(skb, features);
 
+	/* The PSP tx path fixes up the TCP checksum of a GSO skb for the
+	 * device, which is only valid for TCP, and the device only completes
+	 * a TCP or UDP checksum behind the PSP header. Have the stack segment
+	 * and checksum other skbs.
+	 */
+	if ((skb_is_gso(skb) || skb->ip_summed == CHECKSUM_PARTIAL) &&
+	    mlx5e_psp_is_offload(skb, netdev)) {
+		if (skb_is_gso(skb) &&
+		    !(skb_shinfo(skb)->gso_type &
+		      (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
+			features &= ~NETIF_F_GSO_MASK;
+		if (skb->ip_summed == CHECKSUM_PARTIAL &&
+		    !mlx5e_psp_l4_csum_ok(skb))
+			features &= ~NETIF_F_CSUM_MASK;
+	}
+
 	/* Validate if the tunneled packet is being offloaded by HW */
 	if (skb->encapsulation &&
 	    (features & NETIF_F_CSUM_MASK || features & NETIF_F_GSO_MASK))
net/psp/psp_main.c +42 -8

86 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
author
#7 lore raw

PATCH 3/15 psp: declare psp_assoc_set_tx() in psp.h

In reply to Todd Freed

socket-less psp associations will need to install a tx key the same way sockets do.

make psp_assoc_set_tx() non-static, add a declaration within net/psp

---
 net/psp/psp.h      |  3 +++
 net/psp/psp_sock.c | 15 ++++++++++++---
 2 files changed, 15 insertions(+), 3 deletions(-)
net/psp/psp.h +3 -0
index b123c2427905..de4be3320009 100644
@@ -24,6 +24,9 @@ void psp_nl_notify_disassoc(struct psp_dev *psd, struct net *net);
 struct psp_assoc *psp_assoc_create(struct psp_dev *psd);
 struct psp_dev *psp_dev_get_for_sock(struct sock *sk);
 void psp_dev_tx_key_del(struct psp_dev *psd, struct psp_assoc *pas);
+int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,
+		     struct psp_key_parsed *key,
+		     struct netlink_ext_ack *extack);
 int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 			  struct psp_key_parsed *key,
 			  struct netlink_ext_ack *extack);
net/psp/psp_sock.c +12 -3
index f2cba3fa3a23..d04146273bf2 100644
@@ -185,9 +185,18 @@ int psp_sock_assoc_set_rx(struct sock *sk, struct psp_assoc *pas,
 	return err;
 }
 
-static int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,
-			    struct psp_key_parsed *key,
-			    struct netlink_ext_ack *extack)
+/**
+ * psp_assoc_set_tx() - install a Tx key for an association
+ * @psd:	PSP device, must be locked
+ * @pas:	association, must belong to @psd and not have a Tx key yet
+ * @key:	Tx SPI and key
+ * @extack:	netlink extended ack
+ *
+ * Return: 0 on success, negative errno otherwise.
+ */
+int psp_assoc_set_tx(struct psp_dev *psd, struct psp_assoc *pas,
+		     struct psp_key_parsed *key,
+		     struct netlink_ext_ack *extack)
 {
 	int err;
 
Signature · 1 line
2.53.0-Meta
author
#50 lore raw

PATCH 13/15 selftests: tc-testing: run dependsOn probes outside the test namespace

In reply to Todd Freed

a test's dependsOn probe runs as an execute stage command, but is run before the test's namespace is created. nsPlugin prefixes the command with "ip netns exec tcut", which causes the command to fail. this makes every test with a probe that requires nsPlugin skipped currently. for example the mirred blockid tests and the tunnel_key nofrag test.

probes are meant to check what tc and the kernel supports, not anything in the test's namespace. run them as their own stage ("probe"), which makes them run in the base namespace.

---
 tools/testing/selftests/tc-testing/tdc.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/tc-testing/tdc.py +1 -1
index 511d66c36a2a..541caf984519 100755
@@ -399,7 +399,7 @@ def run_one_test(pm, args, index, tidx):
     if 'dependsOn' in tidx:
         if (args.verbose > 0):
             print('probe command for test skip')
-        (p, procout) = exec_cmd(tidx, args, pm, 'execute', tidx['dependsOn'])
+        (p, procout) = exec_cmd(tidx, args, pm, 'probe', tidx['dependsOn'])
         if p:
             if (p.returncode != 0):
                 res = TestResult(tidx['id'], tidx['name'])
Signature · 1 line
2.53.0-Meta
author
#33 lore raw

PATCH 8/15 psp: only give time-wait sockets of psp connections a validator

In reply to Todd Freed

psp_twsk_init() sets tw_validate_xmit_skb on tcp time-wait sockets. today, that becomes set whether or not the socket has psp offload, which is not needed but is harmless. psp_validate_xmit() passes such packets.

but a validator makes a socket look like it has an encryption offload of its own, and the tc psp action, added in the next patch, relies on that:
encap refuses the packets of such a socket, and sk_validate_xmit_skb() drops a packet with a psp association whose socket has a validator.

set the validator only when the socket has a psp association.

---
 net/psp/psp_sock.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/psp/psp_sock.c +6 -2
index 609b06c7af65..664955bfb4fd 100644
@@ -330,10 +330,14 @@ void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk)
 {
 	struct psp_assoc *pas = psp_sk_assoc(sk);
 
-	if (pas)
+	if (pas) {
 		refcount_inc(&pas->refcnt);
+		/* Only for PSP connections: a validator makes the socket
+		 * look like it has an encryption offload of its own
+		 */
+		tw->tw_validate_xmit_skb = psp_validate_xmit;
+	}
 	rcu_assign_pointer(tw->psp_assoc, pas);
-	tw->tw_validate_xmit_skb = psp_validate_xmit;
 }
 
 void psp_twsk_assoc_free(struct inet_timewait_sock *tw)
Signature · 1 line
2.53.0-Meta
author
#48 lore raw

PATCH 12/15 selftests: drv-net: psp: test that software encap on ingress drops

In reply to Todd Freed

encap on ingress is hardware offload only. In software, the packet is dropped.

Verify it on traffic of a client behind a veth, with encap on the veth's
ingress: forwarded, the packets must not reach the remote in clear text, and to a local address, they must not reach the local socket.

data_tc_encap_routed routed packets are dropped by encap, IPv4 and
IPv6
data_tc_encap_local so are packets to a local address

---
 tools/testing/selftests/drivers/net/config |   2 +
 tools/testing/selftests/drivers/net/psp.py | 159 ++++++++++++++++++++-
 2 files changed, 159 insertions(+), 2 deletions(-)
tools/testing/selftests/drivers/net/config +2 -0
index baf1c9d0dd13..b39de6e64263 100644
@@ -5,6 +5,7 @@ CONFIG_DUMMY=m
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
 CONFIG_MACSEC=m
+CONFIG_NET_ACT_GACT=m
 CONFIG_NET_ACT_MIRRED=m
 CONFIG_NET_ACT_PSP=m
 CONFIG_NET_ACT_SKBEDIT=m
@@ -25,5 +26,6 @@ CONFIG_NET_SCH_PRIO=m
 CONFIG_PPP=y
 CONFIG_PPPOE=y
 CONFIG_TLS=y
+CONFIG_VETH=m
 CONFIG_VLAN_8021Q=m
 CONFIG_XDP_SOCKETS=y
tools/testing/selftests/drivers/net/psp.py +157 -2

177 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
author
#56 lore raw

PATCH 15/15 Documentation: networking: psp: document socket-less associations

In reply to Todd Freed

Describe PSP associations, and how they differ for the socket and tc use cases.

Document the new netlink commands for manging socket-less associations.

Document the psp tc action, and flower psp_spi, psp_ver, and psp_dev matches.

Add a new section to describe pre-existing PSP device stats.

---
 Documentation/networking/psp.rst | 139 +++++++++++++++++++++++++++----
 1 file changed, 123 insertions(+), 16 deletions(-)
Documentation/networking/psp.rst +123 -16
index 0f9b6b73f244..79b101db5dfc 100644
@@ -69,20 +69,42 @@ The PSP netlink family defines operations to retrieve information
 about the PSP devices available on the system, configure them and
 access PSP related statistics.
 
-Securing a connection
----------------------
-
-PSP encryption is currently only supported for TCP connections.
-Rx and Tx keys are allocated separately. First the ``rx-assoc``
-Netlink command needs to be issued, specifying a target TCP socket.
-Kernel will allocate a new PSP Rx key from the NIC and associate it
-with given socket. At this stage socket will accept both PSP-secured
-and plain text TCP packets.
+PSP Associations
+----------------
 
-Tx keys are installed using the ``tx-assoc`` Netlink command.
-Once the Tx keys are installed, all data read from the socket will
-be PSP-secured. In other words act of installing Tx keys has a secondary
-effect on the Rx direction.
+PSP encryption and decryption happen in the context of an association.
+An association holds the PSP device, PSP version, and either Rx state
+for decrypting and authenticating packets (the SPI, and for sockets the
+Rx key), a Tx key for encrypting packets, or both.
+
+Associations are used in two ways. First, a TCP socket can be bound to
+an association, and all packets flowing over that socket inherit its
+association. Second, socket-less associations, either Rx or Tx, are
+used with tc. This allows PSP for forwarded traffic, or for non-TCP
+traffic. A tc action attaches a Tx association to packets. An Rx
+association reserves an SPI: the device decrypts packets sent to it,
+and a tc filter matches the SPI, version and PSP device a packet was
+decrypted with.
+
+An association is of one type or the other; that is, sockets may not
+use socket-less associations, and tc actions do not address associations
+which are attached to a socket. Device statistics count both.
+
+Securing a socket connection
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+PSP encryption can be enabled for TCP sockets. Other kinds of sockets
+are not supported. For a TCP socket, Rx and Tx keys are allocated
+separately. First the ``rx-assoc`` Netlink command needs to be issued,
+specifying a target TCP socket. Kernel will allocate a new PSP Rx key
+from the NIC, create an association with it, and bind it to the given
+socket. At this stage socket will accept both PSP-secured and plain text
+TCP packets.
+
+The Tx key is installed into the socket's association with the
+``tx-assoc`` Netlink command. Once it is installed, all data read from
+the socket will be PSP-secured. In other words act of installing Tx keys
+has a secondary effect on the Rx direction.
 
 There is an intermediate period after ``tx-assoc`` successfully
 returns and before the TCP socket encounters it's first PSP
@@ -140,6 +162,55 @@ The PSP assoc state of a socket is not reset when the connection is
 torn down. ``connect()`` on a socket that has PSP assoc state will
 return ``-EINVAL``.
 
+Socket-less associations
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Associations which are not bound to a socket are managed with these
+netlink commands:
+
+- ``rx-spi-alloc`` allocates an Rx SPI and key, like ``rx-assoc`` but
+  without a socket. It also creates an Rx association, which records the
+  SPI, the version and the device key generation, and returns its ID.
+  The key should be passed to the peer out of band, and installed with
+  ``assoc-add``.
+- ``assoc-add`` adds a Tx association with the peer's SPI and key, and
+  returns its ID.
+- ``assoc-del`` deletes an association. tc actions and packets which still
+  reference it keep it alive. The device keeps decrypting the SPI of a
+  deleted Rx association until its device key is rotated out: remove the
+  decap rule to stop taking its packets.
+- ``assoc-get`` reports associations, never their keys, and for Rx
+  associations whether key rotation has made them stale.
+
+The ``psp`` tc action attaches these associations to packets:
+
+- ``psp encap assoc ID`` attaches a Tx association. The packet must then
+  be transmitted on the main netdev of the association's PSP device, which
+  encrypts it (``mirred egress redirect``). If the association is removed
+  before transmit, or if the packet is transmitted on any other device,
+  it will be dropped, rather than sent in the clear. Encap on ingress is
+  hardware offload only.
+
+- ``psp decap`` removes the PSP Rx state (the ``SKB_EXT_PSP`` extension and
+  ``skb->decrypted``) of a decrypted packet, so that it can be forwarded. It
+  takes no association. Its filter should match ``psp_spi``, ``psp_ver``
+  and ``psp_dev``.
+
+The flower classifier matches what a packet was decrypted with:
+``psp_spi SPI[/MASK]``, ``psp_ver VERSION`` and ``psp_dev DEV_ID``, the
+ID of the PSP device which decrypted it. These never match a clear text
+packet, so ``psp_spi 0/0`` matches any packet decrypted with PSP.
+Together they tie a decap rule to one Rx association.
+
+Once the device key an SPI was created from has been rotated twice, that
+association is considered stale. Unlike sockets, tc does not handle key
+rotation. userspace should replace such rules before two rotations.
+
+The device adds 40 bytes to each packet on transmit: the UDP and PSP
+headers, and the ICV. The operator must size the MTU of the traffic
+source for this. A packet which would not fit the PSP device's MTU once
+encapsulated is dropped on transmit.
+
 Rotation notifications
 ----------------------
 
@@ -149,6 +220,38 @@ The PSP netlink family will generate a notification whenever keys
 are rotated. The applications are expected to re-establish connections
 before keys are rotated again.
 
+Fragments
+---------
+
+PSP transport mode does not support IP fragments, either for sockets or
+socket-less associations.
+
+Statistics
+----------
+
+The ``get-stats`` netlink command reports the PSP device statistics:
+kernel statistics (key rotations, stale events), and the device statistics
+defined by the PSP specification. The device statistics count what the
+device decrypts and encrypts.
+
+The tc action counts the packets it processes and the ones it drops
+(``tc -s``). Encapsulated packets dropped on transmit count in the
+device's ``tx_dropped``. Drops are reported with these drop reasons:
+
+- ``SKB_DROP_REASON_PSP_OUTPUT``: encap ran on ingress in software, or
+  failed to parse the packet, or it is an IPv4 fragment or has IPv6
+  extension headers, which transport mode doesn't support, or it is
+  already encapsulated for a tunnel, already marked decrypted, or of a
+  socket with its own encryption offload; or an encapsulated packet
+  reached a device which isn't its PSP device's netdev, or its PSP
+  device was unregistered while it was queued.
+- ``SKB_DROP_REASON_PKT_TOO_BIG``: an encapsulated packet would not fit
+  the device's MTU once the device adds the PSP encapsulation.
+
+A packet encapsulated on egress which lost its association on the way is
+dropped on transmit by ``sk_validate_xmit_skb()``, without a specific drop
+reason.
+
 Kernel implementation
 =====================
 
@@ -177,14 +280,18 @@ device key twice), to avoid potentially using a SPI+key which previous
 OS instance already had access to.
 
 Drivers must use ``psp_skb_get_assoc_rcu()`` to check if PSP Tx offload
-was requested for given skb. On Rx drivers should allocate and populate
-the ``SKB_EXT_PSP`` skb extension, and set the skb->decrypted bit to 1.
+was requested for given skb. The association comes from the skb's socket
+or, for socket-less associations, from a ``METADATA_PSP`` dst which the
+core keeps on the skb for the driver to use. On Rx drivers should
+allocate and populate the ``SKB_EXT_PSP`` skb extension, and set the
+``skb->decrypted`` bit to 1.
 
 Kernel implementation notes
 ---------------------------
 
 PSP implementation follows the TLS offload more closely than the IPsec
-offload, with per-socket state, and the use of skb->decrypted to prevent
+offload, with per-socket state (or per-association state, for
+socket-less associations), and the use of ``skb->decrypted`` to prevent
 clear text leaks.
 
 PSP device is separate from netdev, to make it possible to "delegate"
Signature · 1 line
2.53.0-Meta
author
#46 lore raw

PATCH 11/15 selftests: drv-net: psp: test socket-less associations and the tc psp action

In reply to Todd Freed

Cover the socket-less association commands and the tc psp action.

The data path tests connect a plain local TCP socket to a PSP socket of the responder, and give the local side PSP with tc and socket-less
associations: on ingress, flower psp_spi, psp_ver and psp_dev match what was decrypted with the local Rx SPI, and psp decap removes its PSP state; on egress, psp encap attaches the Tx association to the socket's packets, which the device encrypts.

Test cases,

assoc_sockless_basic rx-spi-alloc / assoc-add / get / dump / del,
only the SPI is ever reported
assoc_sockless_stale key rotation marks socket-less Rx assocs
stale, and not Tx ones

  assoc_sockless_bad       bad device, key size, missing key
  assoc_sockless_tc        encap only takes a Tx association, decap none
  data_tc_basic_send       data to the responder and its acks back, for

each PSP version and IP version
data_tc_no_decap decrypted packets don't reach a plain socket
data_tc_assoc_del associations deleted while tc uses them,
encap holding its Tx one
data_tc_decap_match decap only takes the packets of the filter's
SPI, version and device
data_tc_encap_wrong_dev packets redirected to another device drop data_tc_encap_short_hdr an IPv4 packet shorter than its header
length is dropped by encap
data_tc_encap_too_big packets which won't fit the MTU once
encapsulated are dropped, with and without GSO
data_tc_encap_psp_sock packets of a PSP socket, which are marked
decrypted, are dropped by psp encap action
data_tc_encap_ingress packets with an assoc aren't redirected from
egress to ingress
removal_device_tc PSP device removed while tc holds associations

Note that the tc tests require a newer tc, which has support for the psp action and the flower psp matches. If it's detected that tc is missing that support, the tc tests simply skip.

---
 tools/testing/selftests/drivers/net/config |   3 +
 tools/testing/selftests/drivers/net/psp.py | 593 ++++++++++++++++++++-
 2 files changed, 593 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/config +3 -0
index 4838adf27fa1..baf1c9d0dd13 100644
@@ -1,9 +1,12 @@
 CONFIG_CONFIGFS_FS=y
 CONFIG_DEBUG_INFO_BTF=y
 CONFIG_DEBUG_INFO_BTF_MODULES=n
+CONFIG_DUMMY=m
 CONFIG_INET_PSP=y
 CONFIG_IPV6=y
 CONFIG_MACSEC=m
+CONFIG_NET_ACT_MIRRED=m
+CONFIG_NET_ACT_PSP=m
 CONFIG_NET_ACT_SKBEDIT=m
 CONFIG_NET_CLS_ACT=y
 CONFIG_NET_CLS_BPF=y
tools/testing/selftests/drivers/net/psp.py +590 -3

619 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
author
#53 lore raw

PATCH 14/15 selftests: tc-testing: add tests for the psp action

In reply to Todd Freed

Add / replace / delete / flush psp decap actions, check that encap without an association, associations which don't exist, and decap with an association are rejected, and add flower filters matching on psp_spi, psp_ver and psp_dev, out of range psp_ver and psp_dev rejected.

Creating associations takes the PSP netlink family and a PSP device, the drv-net psp.py test covers actions using them.

The tests need a tc with the psp action and the flower psp_* keys; they skip without it (dependsOn).

---
 tools/testing/selftests/tc-testing/config     |   2 +
 .../tc-testing/tc-tests/actions/psp.json      | 459 ++++++++++++++++++
 tools/testing/selftests/tc-testing/tdc.sh     |   1 +
 3 files changed, 462 insertions(+)
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/psp.json
tools/testing/selftests/tc-testing/config +2 -0
index 0e5618be0335..7828161cc3c8 100644
@@ -101,6 +101,8 @@ CONFIG_NET_ACT_TUNNEL_KEY=m
 CONFIG_NET_ACT_CT=m
 CONFIG_NET_ACT_MPLS=m
 CONFIG_NET_ACT_GATE=m
+CONFIG_INET_PSP=y
+CONFIG_NET_ACT_PSP=m
 CONFIG_NET_IFE_SKBMARK=m
 CONFIG_NET_IFE_SKBPRIO=m
 CONFIG_NET_IFE_SKBTCINDEX=m
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +459 -0

459 lines not on this page · raw message

tools/testing/selftests/tc-testing/tdc.sh +1 -0
index 25cdc256287d..433af92364ac 100755
@@ -24,6 +24,7 @@ try_modprobe act_mpls
 try_modprobe act_nat
 try_modprobe act_pedit
 try_modprobe act_police
+try_modprobe act_psp
 try_modprobe act_sample
 try_modprobe act_simple
 try_modprobe act_skbedit
Signature · 1 line
2.53.0-Meta
author
#38 lore raw

PATCH 9/15 net/sched: add act_psp for psp transport mode

In reply to Todd Freed

adds tc action act_psp for psp transport mode encapsulation and encryption.

encap attaches a psp tx association to the skb as a METADATA_PSP dst. The packet must then be transmitted on the association's PSP device's main netdev, which encrypts it: encap on that netdev's egress, or a redirect there from another netdev's egress. Any other device drops it.

encap on ingress is hardware offload only, like tunnel mode: in software, the action drops the packet. an ingress-encapped packet would go through the stack with only its METADATA_PSP dst to keep it from leaving in clear text, and many paths replace the dst: routing, netfilter, bpf redirects, tc actions on the way out.

on egress, encap sets skb->decrypted, so that sk_validate_xmit_skb() drops the packet if it loses the METADATA_PSP dst on the way. mirred and bpf don't send such a packet back to ingress (previous patches).

Some kinds of packets are not supported and will be dropped,

- ipv4 fragments. encap inserts udp+psp between the l3 and l4 headers, so transport mode can't carry fragments. tunnel mode psp, which a later series adds, does support them.
- ipv6 packets with extension headers, including fragments. some extension headers could be supported in the future.
- packets already encapsulated for a tunnel (skb->encapsulation). some tunnel types could be supported in the future.
- packets which are too large. on transmit, packets which won't fit the device's mtu once encapsulated are dropped (see the METADATA_PSP patch). the traffic's mtu needs to leave room for the psp encap.
- packets with another encryption offload: already marked decrypted, or of a psp or ktls offload socket, for which sk_validate_xmit_skb() would apply the socket's validator instead of checking the association. a socket can gain an offload while its packet is queued, so sk_validate_xmit_skb() also drops a packet with a METADATA_PSP dst whose socket has a validator.

decap removes the PSP Rx state of a packet the device decrypted. to match packets of only one association, a rule should match the psp header fields corresponding to the association, e.g. psp_spi / psp_ver / psp_dev. those flower matches are added in a subsequent patch.

---
 MAINTAINERS                        |   3 +
 include/net/tc_act/tc_psp.h        |  23 ++
 include/uapi/linux/pkt_cls.h       |   1 +
 include/uapi/linux/tc_act/tc_psp.h |  28 ++
 net/core/dev.c                     |  13 +-
 net/sched/Kconfig                  |  13 +
 net/sched/Makefile                 |   1 +
 net/sched/act_psp.c                | 439 +++++++++++++++++++++++++++++
 8 files changed, 519 insertions(+), 2 deletions(-)
 create mode 100644 include/net/tc_act/tc_psp.h
 create mode 100644 include/uapi/linux/tc_act/tc_psp.h
 create mode 100644 net/sched/act_psp.c
MAINTAINERS +3 -0
index 76fb13c8730b..a8e45efd8baf 100644
@@ -22533,8 +22533,11 @@ F:	Documentation/netlink/specs/psp.yaml
 F:	Documentation/networking/psp.rst
 F:	include/net/psp/
 F:	include/net/psp.h
+F:	include/net/tc_act/tc_psp.h
 F:	include/uapi/linux/psp.h
+F:	include/uapi/linux/tc_act/tc_psp.h
 F:	net/psp/
+F:	net/sched/act_psp.c
 K:	struct\ psp(_assoc|_dev|hdr)\b
 
 PSTORE FILESYSTEM
include/net/tc_act/tc_psp.h new file +23 -0
new file mode 100644
index 000000000000..8640d7685475
@@ -0,0 +1,23 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __NET_TC_PSP_H
+#define __NET_TC_PSP_H
+
+#include <net/act_api.h>
+#include <net/dst_metadata.h>
+#include <linux/tc_act/tc_psp.h>
+
+struct tcf_psp_params {
+	struct rcu_head		rcu;
+	int			action;
+	int			psp_action;
+	struct metadata_dst	*md;
+};
+
+struct tcf_psp {
+	struct tc_action		common;
+	struct tcf_psp_params __rcu	*params;
+};
+
+#define to_psp(a) ((struct tcf_psp *)a)
+
+#endif /* __NET_TC_PSP_H */
include/uapi/linux/pkt_cls.h +1 -0
index 28d94b11d1aa..14cff8f5da74 100644
@@ -139,6 +139,7 @@ enum tca_id {
 	TCA_ID_MPLS,
 	TCA_ID_CT,
 	TCA_ID_GATE,
+	TCA_ID_PSP,
 	/* other actions go here */
 	__TCA_ID_MAX = 255
 };
include/uapi/linux/tc_act/tc_psp.h new file +28 -0
new file mode 100644
index 000000000000..e58ebcae77be
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef __LINUX_TC_PSP_H
+#define __LINUX_TC_PSP_H
+
+#include <linux/pkt_cls.h>
+
+#define TCA_PSP_ACT_ENCAP	1	/* attach a PSP association */
+#define TCA_PSP_ACT_DECAP	2	/* drop PSP Rx state */
+
+struct tc_psp {
+	tc_gen;
+};
+
+enum {
+	TCA_PSP_UNSPEC,
+	TCA_PSP_TM,
+	TCA_PSP_PARMS,
+	TCA_PSP_PAD,
+	TCA_PSP_ACTION,		/* u32, TCA_PSP_ACT_* */
+	TCA_PSP_ASSOC_ID,	/* u32, encap only: Tx association ID from
+				 * the PSP netlink family (assoc-add)
+				 */
+	__TCA_PSP_MAX,
+};
+
+#define TCA_PSP_MAX (__TCA_PSP_MAX - 1)
+
+#endif
net/core/dev.c +11 -2
index 2cca5f0d302f..353c0409b3c0 100644
@@ -4154,13 +4154,22 @@ static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
 	sk_validate = NULL;
 	if (sk) {
 		if (sk_fullsock(sk))
-			sk_validate = sk->sk_validate_xmit_skb;
+			sk_validate = READ_ONCE(sk->sk_validate_xmit_skb);
 		else if (sk_is_inet(sk) && sk->sk_state == TCP_TIME_WAIT)
 			sk_validate = inet_twsk(sk)->tw_validate_xmit_skb;
 	}
 
 	if (sk_validate) {
-		skb = sk_validate(sk, dev, skb);
+		/* act_psp doesn't give an association to the packets of a
+		 * socket with its own offload, but the socket can gain one
+		 * while such a packet is queued
+		 */
+		if (unlikely(skb_psp_md(skb))) {
+			kfree_skb_reason(skb, SKB_DROP_REASON_PSP_OUTPUT);
+			skb = NULL;
+		} else {
+			skb = sk_validate(sk, dev, skb);
+		}
 	} else if (unlikely(skb_psp_md(skb))) {
 		int psp = psp_xmit_md(skb, dev);
 
net/sched/Kconfig +13 -0
index 6ddff028b81a..35f9d76c4cae 100644
@@ -939,6 +939,19 @@ config NET_ACT_GATE
 	  To compile this code as a module, choose M here: the
 	  module will be called act_gate.
 
+config NET_ACT_PSP
+	tristate "PSP encryption tc action"
+	depends on NET_CLS_ACT && INET_PSP
+	help
+	  Say Y here to allow PSP associations, created through the PSP
+	  netlink family, to be attached to packets. PSP capable devices can
+	  then encrypt them on transmit. Enables transparent psp tunnels for
+	  forwarded traffic.
+
+	  If unsure, say N.
+	  To compile this code as a module, choose M here: the
+	  module will be called act_psp.
+
 config NET_IFE_SKBMARK
 	tristate "Support to encoding decoding skb mark on IFE action"
 	depends on NET_ACT_IFE
net/sched/Makefile +1 -0
index 5078ea84e6ad..9fe8cc0abfdf 100644
@@ -31,6 +31,7 @@ obj-$(CONFIG_NET_IFE_SKBTCINDEX)	+= act_meta_skbtcindex.o
 obj-$(CONFIG_NET_ACT_TUNNEL_KEY)+= act_tunnel_key.o
 obj-$(CONFIG_NET_ACT_CT)	+= act_ct.o
 obj-$(CONFIG_NET_ACT_GATE)	+= act_gate.o
+obj-$(CONFIG_NET_ACT_PSP)	+= act_psp.o
 obj-$(CONFIG_NET_SCH_FIFO)	+= sch_fifo.o
 obj-$(CONFIG_NET_SCH_HTB)	+= sch_htb.o
 obj-$(CONFIG_NET_SCH_HFSC)	+= sch_hfsc.o
net/sched/act_psp.c new file +439 -0

439 lines not on this page · raw message

Signature · 1 line
2.53.0-Meta
author
#9 lore raw

PATCH 4/15 psp: add support for socket-less psp associations

In reply to Todd Freed

currently, a psp association is bound to a tcp socket when it is created, and can hold both an rx and a tx key.

add a small registry of un-bound associations. These have either an rx or tx flavor, and are referenced by an id. other parts of the stack can then attach them to packets. see the subsequent patches, where the tc psp action does just this.

an rx association records the spi, version, and device key generation, primarily for describe (assoc-get). a tc filter matches these fields with the flower keys psp_spi, psp_ver, and psp_dev instead of referencing the association by id, to facilitate hw offload. these matches are added in a subsequent patch.

adds the following new netlink commands for managing these associations. note, these are admin-only and restricted to the netns of the psp device

rx-spi-alloc allocate an rx spi + derived key, and publish an rx
association for it, returns its id. the key is delivered to the peer out of band
assoc-add create a tx association and install a tx key, returns
its id
assoc-del drop the registry's reference to an association
assoc-get get / dump associations ; only the spi is reported

assoc-get and assoc-del operate on both rx and tx associations.

socket associations do not go into the registry, and these apis do not address them. so for example, assoc-get does not list them.

socket-less associations are on the device's association lists, like socket associations. they are therefore marked stale by key rotation in the same way, except tx ones: they hold the peer's key, which the rotation of the device key doesn't affect. assoc-get reports it (stale), so that user space can identify such entries.

key material enters through netlink and is never reported back. no key is stored for rx associations, and users reference associations by id and never handle keys

published associations are dropped from the registry when their psp device is unregistered.

---
 Documentation/netlink/specs/psp.yaml |  98 +++++++++-
 include/net/psp/functions.h          |  10 +
 include/net/psp/types.h              |   1 +
 include/uapi/linux/psp.h             |   6 +
 net/psp/Makefile                     |   2 +-
 net/psp/psp-nl-gen.c                 |  60 ++++++
 net/psp/psp-nl-gen.h                 |   8 +
 net/psp/psp.h                        |   4 +
 net/psp/psp_assoc.c                  | 120 ++++++++++++
 net/psp/psp_main.c                   |   2 +
 net/psp/psp_nl.c                     | 261 +++++++++++++++++++++++++++
 net/psp/psp_sock.c                   |   9 +-
 12 files changed, 577 insertions(+), 4 deletions(-)
 create mode 100644 net/psp/psp_assoc.c
Documentation/netlink/specs/psp.yaml +96 -2
index f3266763c325..d7b8469a82c3 100644
@@ -103,6 +103,21 @@ attribute-sets:
         name: sock-fd
         doc: Sockets which should be bound to the association immediately.
         type: u32
+      -
+        name: id
+        doc: |
+          ID of an association which is not bound to a socket.
+          Such associations can be attached to packets with the tc psp action.
+        type: u32
+        checks:
+          min: 1
+      -
+        name: stale
+        doc: |
+          Key rotation has retired the device key the association was
+          created under. The device no longer decrypts the SPI of such an
+          association.
+        type: flag
   -
     name: keys
     attributes:
@@ -132,8 +147,9 @@ attribute-sets:
         name: stale-events
         type: uint
         doc: |
-          Number of times a socket's Rx got shut down due to using
-          a key which went stale (fully rotated out).
+          Number of times an Rx association, of a socket or socket-less,
+          got shut down due to using a key which went stale (fully rotated
+          out).
           Kernel statistic.
       -
         name: rx-packets
@@ -350,6 +366,84 @@ operations:
           attributes: []
         pre: psp-device-get-locked
         post: psp-device-unlock
+    -
+      name: rx-spi-alloc
+      doc: |
+        Allocate a new Rx key + SPI pair without binding it to a socket.
+        The key is derived by the device and must be passed to the peer
+        out of band, to be installed there with assoc-add. Also adds an
+        Rx association, which records the SPI, version, and the device
+        key generation, and returns its ID. A tc rule can check
+        decrypted packets against these fields with the flower psp_spi,
+        psp_dev and psp_ver keys.
+      attribute-set: assoc
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+        reply:
+          attributes:
+            - id
+            - dev-id
+            - rx-key
+        pre: psp-assoc-device-get-locked-admin
+        post: psp-device-unlock
+    -
+      name: assoc-add
+      doc: |
+        Add a PSP Tx association which is not bound to a socket.
+        Returns the ID of the new association.
+      attribute-set: assoc
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - dev-id
+            - version
+            - tx-key
+        reply:
+          attributes:
+            - id
+            - dev-id
+        pre: psp-assoc-device-get-locked-admin
+        post: psp-device-unlock
+    -
+      name: assoc-del
+      doc: |
+        Delete a PSP association which is not bound to a socket, Tx or Rx.
+        Packets and tc actions which still reference it keep it alive.
+      attribute-set: assoc
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - id
+        reply:
+          attributes: []
+    -
+      name: assoc-get
+      doc: |
+        Get / dump associations which are not bound to a socket.
+        Key material is never reported: Tx associations carry tx-key and
+        Rx associations rx-key, with the SPI only.
+      attribute-set: assoc
+      flags: [admin-perm]
+      do:
+        request:
+          attributes:
+            - id
+        reply: &assoc-all
+          attributes:
+            - id
+            - dev-id
+            - version
+            - tx-key
+            - rx-key
+            - stale
+      dump:
+        reply: *assoc-all
 
 mcast-groups:
   list:
include/net/psp/functions.h +10 -0
index 410adb6718c1..d0789a9694bc 100644
@@ -23,6 +23,16 @@ int psp_dev_rcv(struct sk_buff *skb, u16 dev_id, u8 generation, bool strip_icv);
 
 /* Kernel-facing API */
 void psp_assoc_put(struct psp_assoc *pas);
+struct psp_assoc *psp_assoc_get_by_id(struct net *net, u32 id);
+
+/* An association from the ID registry is either a Tx one, from assoc-add,
+ * or an Rx one, from rx-spi-alloc. PSP SPIs are never 0.
+ */
+static inline bool psp_assoc_is_tx(const struct psp_assoc *pas)
+{
+	DEBUG_NET_WARN_ON_ONCE(!pas->id);    /* only socket-less ones */
+	return pas->tx.spi != 0;
+}
 
 #if IS_ENABLED(CONFIG_INET_PSP)
 unsigned int psp_key_size(u32 version);
include/net/psp/types.h +1 -0
index b8905efbd604..49fa36ad9583 100644
@@ -154,6 +154,7 @@ struct psp_key_parsed {
 
 struct psp_assoc {
 	struct psp_dev *psd;
+	u32 id;
 
 	u16 dev_id;
 	u8 generation;
include/uapi/linux/psp.h +6 -0
index 1c8899cd4da5..54b50324211b 100644
@@ -44,6 +44,8 @@ enum {
 	PSP_A_ASSOC_RX_KEY,
 	PSP_A_ASSOC_TX_KEY,
 	PSP_A_ASSOC_SOCK_FD,
+	PSP_A_ASSOC_ID,
+	PSP_A_ASSOC_STALE,
 
 	__PSP_A_ASSOC_MAX,
 	PSP_A_ASSOC_MAX = (__PSP_A_ASSOC_MAX - 1)
@@ -87,6 +89,10 @@ enum {
 	PSP_CMD_GET_STATS,
 	PSP_CMD_DEV_ASSOC,
 	PSP_CMD_DEV_DISASSOC,
+	PSP_CMD_RX_SPI_ALLOC,
+	PSP_CMD_ASSOC_ADD,
+	PSP_CMD_ASSOC_DEL,
+	PSP_CMD_ASSOC_GET,
 
 	__PSP_CMD_MAX,
 	PSP_CMD_MAX = (__PSP_CMD_MAX - 1)
net/psp/Makefile +1 -1
index eb5ff3c5bfb2..d7f026f937cb 100644
@@ -2,4 +2,4 @@
 
 obj-$(CONFIG_INET_PSP) += psp.o
 
-psp-y := psp_main.o psp_nl.o psp_sock.o psp-nl-gen.o
+psp-y := psp_main.o psp_nl.o psp_sock.o psp_assoc.o psp-nl-gen.o
net/psp/psp-nl-gen.c +60 -0

72 lines not on this page · raw message

net/psp/psp-nl-gen.h +8 -0
index 24d51bff997f..27474f1ce112 100644
@@ -24,6 +24,9 @@ int psp_assoc_device_get_locked(const struct genl_split_ops *ops,
 int psp_device_get_locked_dev_assoc(const struct genl_split_ops *ops,
 				    struct sk_buff *skb,
 				    struct genl_info *info);
+int psp_assoc_device_get_locked_admin(const struct genl_split_ops *ops,
+				      struct sk_buff *skb,
+				      struct genl_info *info);
 void
 psp_device_unlock(const struct genl_split_ops *ops, struct sk_buff *skb,
 		  struct genl_info *info);
@@ -38,6 +41,11 @@ int psp_nl_get_stats_doit(struct sk_buff *skb, struct genl_info *info);
 int psp_nl_get_stats_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 int psp_nl_dev_assoc_doit(struct sk_buff *skb, struct genl_info *info);
 int psp_nl_dev_disassoc_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_rx_spi_alloc_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_assoc_add_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_assoc_del_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_assoc_get_doit(struct sk_buff *skb, struct genl_info *info);
+int psp_nl_assoc_get_dumpit(struct sk_buff *skb, struct netlink_callback *cb);
 
 enum {
 	PSP_NLGRP_MGMT,
net/psp/psp.h +4 -0
index de4be3320009..cadeb1ad04a2 100644
@@ -35,6 +35,10 @@ int psp_sock_assoc_set_tx(struct sock *sk, struct psp_dev *psd,
 			  struct netlink_ext_ack *extack);
 void psp_assocs_key_rotated(struct psp_dev *psd);
 
+int psp_assoc_publish(struct psp_assoc *pas);
+void psp_assoc_unpublish(struct psp_assoc *pas);
+struct psp_assoc *psp_assoc_get_next(struct net *net, unsigned long *index);
+
 static inline void psp_dev_get(struct psp_dev *psd)
 {
 	refcount_inc(&psd->refcnt);
net/psp/psp_assoc.c new file +120 -0

120 lines not on this page · raw message

net/psp/psp_main.c +2 -0
index 1eb1617aaf2b..40d3e9897b94 100644
@@ -151,6 +151,8 @@ void psp_dev_unregister(struct psp_dev *psd)
 		if (psp_assoc_needs_tx_key_del(pas))
 			psp_dev_tx_key_del(psd, pas);
 		list_del(&pas->assocs_list);
+		if (pas->id)
+			psp_assoc_unpublish(pas);
 	}
 
 	list_for_each_entry_safe(entry, entry_tmp, &psd->assoc_dev_list,
net/psp/psp_nl.c +261 -0

273 lines not on this page · raw message

net/psp/psp_sock.c +8 -1
index d04146273bf2..609b06c7af65 100644
@@ -140,6 +140,7 @@ void psp_assoc_put(struct psp_assoc *pas)
 	if (pas && refcount_dec_and_test(&pas->refcnt))
 		call_rcu(&pas->rcu, psp_assoc_free_queue);
 }
+EXPORT_SYMBOL_GPL(psp_assoc_put);
 
 void psp_sk_assoc_free(struct sock *sk)
 {
@@ -310,7 +311,13 @@ void psp_assocs_key_rotated(struct psp_dev *psd)
 	 * be able to Rx any traffic.
 	 */
 	list_for_each_entry_safe(pas, next, &psd->prev_assocs, assocs_list) {
-		pas->generation |= ~PSP_GEN_VALID_MASK;
+		/* A socket-less Tx association holds the peer's key, which
+		 * the rotation of the device key doesn't affect
+		 */
+		if (pas->id && psp_assoc_is_tx(pas))
+			continue;
+		WRITE_ONCE(pas->generation,
+			   pas->generation | ~PSP_GEN_VALID_MASK);
 		psd->stats.stales++;
 	}
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);
Signature · 1 line
2.53.0-Meta
author
#18 lore raw

PATCH 5/15 net: add METADATA_PSP dst to carry a psp association on an skb

In reply to Todd Freed

Add a metadata_dst type holding a reference to a psp association, so that an association can be attached to an skb that has no socket, e.g. by a tc rule.

change psp_skb_get_assoc_rcu() to check for METADATA_PSP then fall back to the socket, so that existing driver tx paths (mlx5, netdevsim) encrypt such packets without any changes.

once an skb has been marked for psp xmit, it is necessary to ensure that it is transmitted on the correct device, otherwise it may go onto the wire in cleartext. for packets on a psp socket, sk_validate_xmit_skb() handles this.

for socket-less psp packets, the psp metadata dst carries this information. but __dev_queue_xmit() normally releases the dst before queueing. add a new check for a psp metadata dst at that point. if it's the wrong device, drop the packet ; if it's the right device, save the dst so that the driver can use it.

the right device is the psp device's main netdev: devices associated with it (dev-assoc, e.g. veth or netkit) have its psp_dev too, but forward the packet rather than encrypt it, and drop the dst on the way. prevent xmit on those.

also check that the packet will still fit the device's mtu once the device adds the psp encapsulation (udp+psp+icv, 40 bytes), and drop it with SKB_DROP_REASON_PKT_TOO_BIG otherwise. note that no icmp error is sent in this case. psp sockets do leave room for it (psp_sk_overhead()).

check a packet with a METADATA_PSP dst again at dequeue, in sk_validate_xmit_skb(): the psp device may have been unregistered while the packet was queued, and its keys deleted.

---
 include/net/dst_metadata.h  | 19 +++++++++
 include/net/psp/functions.h | 81 ++++++++++++++++++++++++++++++++++++-
 net/core/dev.c              | 35 +++++++++++++---
 net/core/dst.c              |  5 +++
 4 files changed, 133 insertions(+), 7 deletions(-)
include/net/dst_metadata.h +19 -0
index f45d1e3163f0..73755bce2df0 100644
@@ -13,6 +13,7 @@ enum metadata_type {
 	METADATA_HW_PORT_MUX,
 	METADATA_MACSEC,
 	METADATA_XFRM,
+	METADATA_PSP,
 };
 
 struct hw_port_info {
@@ -30,6 +31,14 @@ struct xfrm_md_info {
 	struct dst_entry *dst_orig;
 };
 
+/**
+ * struct psp_md_info - PSP association to encrypt a packet with
+ * @pas: association, the metadata_dst holds a reference on it
+ */
+struct psp_md_info {
+	struct psp_assoc *pas;
+};
+
 struct metadata_dst {
 	struct dst_entry		dst;
 	enum metadata_type		type;
@@ -38,6 +47,7 @@ struct metadata_dst {
 		struct hw_port_info	port_info;
 		struct macsec_info	macsec_info;
 		struct xfrm_md_info	xfrm_info;
+		struct psp_md_info	psp_info;
 	} u;
 };
 
@@ -51,6 +61,13 @@ static inline struct metadata_dst *skb_metadata_dst(const struct sk_buff *skb)
 	return NULL;
 }
 
+static inline bool skb_psp_md(const struct sk_buff *skb)
+{
+	struct metadata_dst *md_dst = skb_metadata_dst(skb);
+
+	return md_dst && md_dst->type == METADATA_PSP;
+}
+
 static inline struct ip_tunnel_info *
 skb_tunnel_info(const struct sk_buff *skb)
 {
@@ -125,6 +142,8 @@ static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a,
 	case METADATA_XFRM:
 		return memcmp(&a->u.xfrm_info, &b->u.xfrm_info,
 			      sizeof(a->u.xfrm_info));
+	case METADATA_PSP:
+		return a->u.psp_info.pas != b->u.psp_info.pas;
 	default:
 		return 1;
 	}
include/net/psp/functions.h +80 -1

119 lines not on this page · raw message

net/core/dev.c +29 -6
index 9665f3b2f5cb..2cca5f0d302f 100644
@@ -111,6 +111,7 @@
 #include <net/pkt_cls.h>
 #include <net/checksum.h>
 #include <net/xfrm.h>
+#include <net/psp/functions.h>
 #include <net/tcx.h>
 #include <linux/highmem.h>
 #include <linux/init.h>
@@ -4134,9 +4135,13 @@ int skb_csum_hwoffload_help(struct sk_buff *skb,
 }
 EXPORT_SYMBOL(skb_csum_hwoffload_help);
 
-/* Checks if this SKB belongs to an HW offloaded socket
- * and whether any SW fallbacks are required based on dev.
- * Check decrypted mark in case skb_orphan() cleared socket.
+/* Validate an skb for device encryption offload. If the skb belongs to an HW
+ * offloaded socket, apply the socket's callback. Otherwise, an skb which
+ * carries a PSP association is checked again against dev: the PSP device may
+ * have been unregistered while the skb was queued. An skb marked decrypted
+ * (to be encrypted by the device) without either is dropped rather than sent
+ * in clear text. The mark survives losing the socket to skb_orphan(), or the
+ * PSP metadata dst to routing.
  */
 static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
 					    struct net_device *dev)
@@ -4156,6 +4161,15 @@ static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
 
 	if (sk_validate) {
 		skb = sk_validate(sk, dev, skb);
+	} else if (unlikely(skb_psp_md(skb))) {
+		int psp = psp_xmit_md(skb, dev);
+
+		if (psp <= 0) {
+			kfree_skb_reason(skb, psp == -EMSGSIZE ?
+					 SKB_DROP_REASON_PKT_TOO_BIG :
+					 SKB_DROP_REASON_PSP_OUTPUT);
+			skb = NULL;
+		}
 	} else if (unlikely(skb_is_decrypted(skb))) {
 		pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
 		kfree_skb(skb);
@@ -4981,7 +4995,7 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 	struct net_device *dev = skb->dev;
 	struct netdev_queue *txq = NULL;
 	enum skb_drop_reason reason;
-	int cpu, rc = -ENOMEM;
+	int cpu, psp, rc = -ENOMEM;
 	bool again = false;
 	struct Qdisc *q;
 
@@ -5030,10 +5044,19 @@ int __dev_queue_xmit(struct sk_buff *skb, struct net_device *sb_dev)
 			txq = netdev_tx_queue_mapping(dev, skb);
 	}
 #endif
+	psp = psp_xmit_md(skb, dev);
+	if (unlikely(psp < 0)) {
+		reason = psp == -EMSGSIZE ? SKB_DROP_REASON_PKT_TOO_BIG :
+					    SKB_DROP_REASON_PSP_OUTPUT;
+		rc = psp;
+		goto drop;
+	}
+
 	/* If device/qdisc don't need skb->dst, release it right now while
-	 * its hot in this cpu cache.
+	 * its hot in this cpu cache. A PSP metadata dst carries the packet's
+	 * association to the driver, so keep it in that case.
 	 */
-	if (dev->priv_flags & IFF_XMIT_DST_RELEASE)
+	if ((dev->priv_flags & IFF_XMIT_DST_RELEASE) && likely(!psp))
 		skb_dst_drop(skb);
 	else
 		skb_dst_force(skb);
net/core/dst.c +5 -0
index 092861133023..38ad136cb46f 100644
@@ -26,6 +26,7 @@
 
 #include <net/dst.h>
 #include <net/dst_metadata.h>
+#include <net/psp/functions.h>
 
 int dst_discard_out(struct net *net, struct sock *sk, struct sk_buff *skb)
 {
@@ -313,6 +314,8 @@ void metadata_dst_free(struct metadata_dst *md_dst)
 #endif
 	if (md_dst->type == METADATA_XFRM)
 		dst_release(md_dst->u.xfrm_info.dst_orig);
+	if (md_dst->type == METADATA_PSP)
+		psp_assoc_put(md_dst->u.psp_info.pas);
 	kfree(md_dst);
 }
 EXPORT_SYMBOL_GPL(metadata_dst_free);
@@ -349,6 +352,8 @@ void metadata_dst_free_percpu(struct metadata_dst __percpu *md_dst)
 #endif
 		if (one_md_dst->type == METADATA_XFRM)
 			dst_release(one_md_dst->u.xfrm_info.dst_orig);
+		if (one_md_dst->type == METADATA_PSP)
+			psp_assoc_put(one_md_dst->u.psp_info.pas);
 	}
 	free_percpu(md_dst);
 }
Signature · 1 line
2.53.0-Meta
maintainer
#34 lore raw

Re: [PATCH net-next v1 08/15] psp: only give time-wait sockets of psp connections a validator

In reply to Todd Freed
Quoted 4 lines · Todd Freed

psp_twsk_init() sets tw_validate_xmit_skb on tcp time-wait sockets. today, that becomes set whether or not the socket has psp offload, which is not needed but is harmless. psp_validate_xmit() passes such packets.

This can get sent as a standalone patch. I would probably tag it as a fix too, even though it is benign. I can't remember why we (I) didn't put the validation hook under the branch, but looking at it now, it just looks like a bug.

Quoted 17 lines

but a validator makes a socket look like it has an encryption offload of its own, and the tc psp action, added in the next patch, relies on that:
encap refuses the packets of such a socket, and sk_validate_xmit_skb() drops a packet with a psp association whose socket has a validator.

set the validator only when the socket has a psp association.

---
 net/psp/psp_sock.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
net/psp/psp_sock.c +0 -0
index 609b06c7af65..664955bfb4fd 100644

net/psp/psp_sock.c void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk) · line 337

Quoted 9 lines
net/psp/psp_sock.c +4 -1
@@ -330,10 +330,14 @@ void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk)
 {
 	struct psp_assoc *pas = psp_sk_assoc(sk);
 
-	if (pas)
+	if (pas) {
 		refcount_inc(&pas->refcnt);
+		/* Only for PSP connections: a validator makes the socket
+		 * look like it has an encryption offload of its own
+		 */

comment nit: for my taste, having a comment that starts with "Only for PSP connections:" two lines under an if (pas) branch feels unnecessary.

Quoted 7 lines
net/psp/psp_sock.c +2 -1
+		tw->tw_validate_xmit_skb = psp_validate_xmit;
+	}
 	rcu_assign_pointer(tw->psp_assoc, pas);
-	tw->tw_validate_xmit_skb = psp_validate_xmit;
 }
 
 void psp_twsk_assoc_free(struct inet_timewait_sock *tw)
maintainer
#10 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to Todd Freed
Quoted 36 lines · Todd Freed

currently, a psp association is bound to a tcp socket when it is created, and can hold both an rx and a tx key.

add a small registry of un-bound associations. These have either an rx or tx flavor, and are referenced by an id. other parts of the stack can then attach them to packets. see the subsequent patches, where the tc psp action does just this.

an rx association records the spi, version, and device key generation, primarily for describe (assoc-get). a tc filter matches these fields with the flower keys psp_spi, psp_ver, and psp_dev instead of referencing the association by id, to facilitate hw offload. these matches are added in a subsequent patch.

adds the following new netlink commands for managing these associations. note, these are admin-only and restricted to the netns of the psp device

rx-spi-alloc allocate an rx spi + derived key, and publish an rx
association for it, returns its id. the key is delivered to the peer out of band
assoc-add create a tx association and install a tx key, returns
its id
assoc-del drop the registry's reference to an association
assoc-get get / dump associations ; only the spi is reported

assoc-get and assoc-del operate on both rx and tx associations.

socket associations do not go into the registry, and these apis do not address them. so for example, assoc-get does not list them.

socket-less associations are on the device's association lists, like socket associations. they are therefore marked stale by key rotation in the same way, except tx ones: they hold the peer's key, which the rotation of the device key doesn't affect. assoc-get reports it (stale), so that user space can identify such entries.

Quoted 7 lines

key material enters through netlink and is never reported back. no key is stored for rx associations, and users reference associations by id and never handle keys

published associations are dropped from the registry when their psp device is unregistered.

I think the design could be improved by not reusing struct psp_assoc for the socketless rx spi accounting, and by not placing the socketless tx assoc on the active, prev, and stale lists next to the socket associations. I'll try to comment inline to give you a better idea of what I'm talking about.

In general, what I'd like to minimize is having one object used for three different things, where each usecase has its own subset of fields active, and then having a bunch of glue in places like psp_assocs_key_rotated(), where you have to check if the assoc is socketless, followed by if it is tx or rx.

[...]

Quoted 17 lines
net/psp/psp_nl.c +17 -0
+int psp_nl_rx_spi_alloc_doit(struct sk_buff *skb, struct genl_info *info)
+{
+	struct psp_dev *psd = info->user_ptr[0];
+	struct psp_key_parsed key;
+	struct psp_assoc *pas;
+	struct sk_buff *rsp;
+	u32 version;
+	int err;
+
+	if (GENL_REQ_ATTR_CHECK(info, PSP_A_ASSOC_VERSION))
+		return -EINVAL;
+
+	version = nla_get_u32(info->attrs[PSP_A_ASSOC_VERSION]);
+	if (!(psd->caps->versions & (1 << version))) {
+		NL_SET_BAD_ATTR(info->extack, info->attrs[PSP_A_ASSOC_VERSION]);
+		return -EOPNOTSUPP;
+	}

net/psp/psp_nl.c int psp_nl_tx_assoc_doit(struct sk_buff *skb, struct genl_info *info) · line 942

Quoted 10 lines
net/psp/psp_nl.c +10 -0
+
+	rsp = psp_nl_reply_new(info);
+	if (!rsp)
+		return -ENOMEM;
+
+	err = psd->ops->rx_spi_alloc(psd, version, &key, info->extack);
+	if (err)
+		goto err_free_rsp;
+
+	pas = psp_assoc_create(psd);

I'm not sure the kernel actually needs any bookkeeping at all for these generic rx spi allocations. You could probably just pass the spi, dev id, key, and probably rotation count (as a device key generation of sorts) to the user without creating a kernel object. For socket psp_assocs, the rx state is consulted on the datapath before queueing to the socket. For tx state in all psp_assocs, there is the possibility that an SADB handle needs to be cleaned up. Neither of those apply here or in the rest of the series as I understand it.

I figure the tc ingress rule can just take the spi and dev id by value rather than needing a reference to an object that we create here.

Quoted 32 lines
net/psp/psp_nl.c +32 -0
+	if (!pas) {
+		err = -ENOMEM;
+		goto err_free_rsp;
+	}
+	pas->version = version;
+	pas->rx.spi = key.spi;
+
+	err = psp_assoc_publish(pas);
+	if (err)
+		goto err_put_pas;
+
+	if (nla_put_u32(rsp, PSP_A_ASSOC_ID, pas->id) ||
+	    nla_put_u32(rsp, PSP_A_ASSOC_DEV_ID, psd->id) ||
+	    psp_nl_put_key(rsp, PSP_A_ASSOC_RX_KEY, version, &key)) {
+		psp_assoc_unpublish(pas);
+		err = -EMSGSIZE;
+		goto err_put_pas;
+	}
+
+	psp_assoc_put(pas);
+	memzero_explicit(&key, sizeof(key));
+
+	return psp_nl_reply_send(rsp, info);
+
+err_put_pas:
+	psp_assoc_put(pas);
+err_free_rsp:
+	memzero_explicit(&key, sizeof(key));
+	nlmsg_free(rsp);
+	return err;
+}
+

[...]

Quoted 5 lines
net/psp/psp_sock.c +0 -1
@@ -310,7 +311,13 @@ void psp_assocs_key_rotated(struct psp_dev *psd)
 	 * be able to Rx any traffic.
 	 */
 	list_for_each_entry_safe(pas, next, &psd->prev_assocs, assocs_list) {
-		pas->generation |= ~PSP_GEN_VALID_MASK;

net/psp/psp_sock.c void psp_assocs_key_rotated(struct psp_dev *psd) · line 323

Quoted 10 lines
net/psp/psp_sock.c +7 -0
+		/* A socket-less Tx association holds the peer's key, which
+		 * the rotation of the device key doesn't affect
+		 */
+		if (pas->id && psp_assoc_is_tx(pas))
+			continue;
+		WRITE_ONCE(pas->generation,
+			   pas->generation | ~PSP_GEN_VALID_MASK);
 		psd->stats.stales++;
 	}
 	list_splice_init(&psd->prev_assocs, &psd->stale_assocs);

I would create a separate list for the socketless tx assocs, so that SADB handles can be flushed on psp_dev_unregister(). Then you can just leave this function untouched, because invalidating the generation is only for __psp_sk_rx_policy_check(), which isn't used by the socketless rx assocs.

maintainer
#59 lore raw
In reply to Todd Freed
Quoted 3 lines · Todd Freed

psp associations today are bound to a tcp socket when created. traffic on that socket is encapsulated in transport-mode psp, and encrypted.

You can start sentences with capital letters in cover letters and commit messages.

Quoted 38 lines

this series adds associations which aren't bound to a socket, which allows psp encapsulation and encryption to be applied to forwarded traffic. you can use this to transparently apply psp tunnels to flows, with help from userspace to manage the tc rules and orchestrate key exchange.

the lifecycle of socket-less associations is managed over the psp netlink family. socket-less associations are stored in a small registry, and are addressable by id. the registry does not contain socket associations.

socket-less associations are on the device's association lists, like socket associations. rx ones are therefore marked stale by key rotation in the same way. in this series, nothing acts on socket-less rx associations on key rotation. instead, userspace should replace decap rules for a SPI before its device key has been rotated twice. a follow-up will bring enforcement.

series structure,

1, 2/ prepares psp to work with non-tcp packets

3, 4/ adds the netlink commands for managing socket-less associations

5/ adds a METADATA_PSP dst which carries the socket-less psp association on an skb for tx, and the transmit checks for it

6, 7/ keep mirred and bpf from sending decrypted skbs from egress to ingress, since skb->decrypted depends on direction

8/ limit time-wait psp socket validator to sockets actually in time-wait. the new psp actions check for presence of the validator

9/ adds the act_psp tc actions, psp encap and psp decap. in software, encap is egress only.

10/ adds flower matches on psp header fields, for rx matching

Quoted 9 lines

11, 12/ add drv-net tests (netdevsim and hardware)

13/ makes tc-testing run dependsOn probes outside the test namespace, where they currently always fail

14/ adds tc-testing tests

15/ Documentation for socket-less psp associations

Some of these can probably stand alone like the bpf decrypted, psp encap helper, and timewait validation, and be submitted first to shorten the series. That's just a suggestion though. If there are dependencies on the main series you can ignore.

#11 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to Daniel Zahka
Quoted 11 lines

I'm not sure the kernel actually needs any bookkeeping at all for these generic rx spi allocations. You could probably just pass the spi, dev id, key, and probably rotation count (as a device key generation of sorts) to the user without creating a kernel object. For socket psp_assocs, the rx state is consulted on the datapath before queueing to the socket. For tx state in all psp_assocs, there is the possibility that an SADB handle needs to be cleaned up. Neither of those apply here or in the rest of the series as I understand it.

I figure the tc ingress rule can just take the spi and dev id by value rather than needing a reference to an object that we create here.

That is how it works in this series. The tc psp decap rule (ingress) does not make reference to an rx assoc ; instead, it should have flower matches on psp_spi, psp_ver, and psp_dev. That effectively ties it to packets from just one rx assoc.

So why keep track of rx assoc objects at all? Two considerations.

1/ don't accept packets that correspond to a stale association. That is, even if the device decrypted the packet, it should be dropped if the device key which minted the assoc's SPI is two rotations behind. For psp socket offload that is enforced in __psp_sk_rx_policy_check() with the pas->generation check.

The spec permits SPIs to be reused immediately after two rotations. So the device could decrypt a packet with a SPI that is more than two rotations old in that case, or if a previous packet is being replayed, for example.

2/ hardware offload. the solution to #1 should be able to be fully offloaded to the device. psp tunnel mode will be hw offload only, and is implemented in the eswitch with connect-x.

We could add a psp_gen flower match to replicate the pas->generation check, but the device has no access to the pas and can't offload that.

Keeping track of the rx assoc means that the kernel can take action on the "this assoc is now stale" event. Possibly by enumerating the tc rules and either deleting them, or marking them stale for userspace to reap.

-Todd

maintainer
#12 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

Quoted 17 lines · Todd Bert Freed
Quoted 11 lines

I'm not sure the kernel actually needs any bookkeeping at all for these generic rx spi allocations. You could probably just pass the spi, dev id, key, and probably rotation count (as a device key generation of sorts) to the user without creating a kernel object. For socket psp_assocs, the rx state is consulted on the datapath before queueing to the socket. For tx state in all psp_assocs, there is the possibility that an SADB handle needs to be cleaned up. Neither of those apply here or in the rest of the series as I understand it.

I figure the tc ingress rule can just take the spi and dev id by value rather than needing a reference to an object that we create here.

That is how it works in this series. The tc psp decap rule (ingress) does not make reference to an rx assoc ; instead, it should have flower matches on psp_spi, psp_ver, and psp_dev. That effectively ties it to packets from just one rx assoc.

Quoted 8 lines

So why keep track of rx assoc objects at all? Two considerations.

1/ don't accept packets that correspond to a stale association. That is, even if the device decrypted the packet, it should be dropped if the device key which minted the assoc's SPI is two rotations behind. For psp socket offload that is enforced in __psp_sk_rx_policy_check() with the pas->generation check.

I asked why we needed to keep track of socketless rx assoc objects. The above applies to the existing transport mode code, which is my point. The rx state from the assoc is looked up from the datapath. It doesn't seem like that is the case in this series.

Quoted 4 lines

The spec permits SPIs to be reused immediately after two rotations. So the device could decrypt a packet with a SPI that is more than two rotations old in that case, or if a previous packet is being replayed, for example.

A SPI that is two generations old will cause and auth error on rx. The hazard is that an old tc rule with a SPI from two generations ago can alias a different SPI from this generation. Userspace can just flush old rules before doing a key rotation. That is why I suggested including a 'rotations' attribute, although that is probably not even necessary to keep track of which rules need to be flushed.

Quoted 11 lines

2/ hardware offload. the solution to #1 should be able to be fully offloaded to the device. psp tunnel mode will be hw offload only, and is implemented in the eswitch with connect-x.

We could add a psp_gen flower match to replicate the pas->generation check, but the device has no access to the pas and can't offload that.

Keeping track of the rx assoc means that the kernel can take action on the "this assoc is now stale" event. Possibly by enumerating the tc rules and either deleting them, or marking them stale for userspace to reap.

I think it makes more sense for userspace to just get rid of the rules before rotating the keys.

Quoted 1 line

-Todd

#13 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

Quoted 2 lines

I think it makes more sense for userspace to just get rid of the rules before rotating the keys.

Ok. I will drop the rx assoc objects. The robust userspace protocol will be some combination of using cookies for state recovery from a rule dump, and using chains to flush old-generation rules at once.

-Todd

#14 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to Daniel Zahka
Quoted 5 lines

I think the design could be improved by not reusing struct psp_assoc for the socketless rx spi accounting, and by not placing the socketless tx assoc on the active, prev, and stale lists next to the socket associations. I'll try to comment inline to give you a better idea of what I'm talking about.

Sounds good, I will do this.

Quoted 5 lines

I would create a separate list for the socketless tx assocs, so that SADB handles can be flushed on psp_dev_unregister(). Then you can just leave this function untouched, because invalidating the generation is only for __psp_sk_rx_policy_check(), which isn't used by the socketless rx assocs.

This sounds good as well.

-Todd

#2 lore raw

Re: [PATCH net-next v1 01/15] psp: get netns from net_device instead of sock

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

every psp skb is related to a socket today, but that will no longer be true once a psp association can be attached to the skb by other means, such as tc flower rules added later in the series.

get the netns from the transmitting device instead.

for the outer source port range, psp_write_headers() now explicitly uses sock_net(sk) in the socket case specifically, to maintain the existing behavior.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#4 lore raw

Re: [PATCH net-next v1 02/15] psp: take the psp nexthdr from the packet on encap

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] mlx5e: psp software GSO on tunneled skbs bypasses psp_dev_encap_ok() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] mlx5e: psp software GSO on tunneled skbs bypasses psp_dev_encap_ok()
--

commit 1d6df14f6316e027ee333bf0c262d7f9842ccd5c
Author: Todd Freed <[email protected]>

psp: take the psp nexthdr from the packet on encap

This commit populates the PSP next header from the original IP header in psp_dev_encapsulate() instead of hardcoding IPPROTO_TCP, rejects packets that cannot be encapsulated (IPv6 extension headers, IPv4 fragments, and already-encapsulated packets), and updates mlx5e_features_check() to fall back to software GSO and checksumming for unsupported protocols.

Quoted 4 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +0 -0
index c3c2c5720c6f3..d091de1a5992b 100644

[ ... ]

Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +5 -0
@@ -5140,6 +5157,22 @@ netdev_features_t mlx5e_features_check(struct sk_buff *skb,
 
 	features = vlan_features_check(skb, features);
 
+	/* The PSP tx path fixes up the TCP checksum of a GSO skb for the
+	 * device, which is only valid for TCP, and the device only completes
+	 * a TCP or UDP checksum behind the PSP header. Have the stack segment
+	 * and checksum other skbs.
+	 */

drivers/net/ethernet/mellanox/mlx5/core/en_main.c netdev_features_t mlx5e_features_check(struct sk_buff *skb, · line 5174

Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_main.c +10 -0
+	if ((skb_is_gso(skb) || skb->ip_summed == CHECKSUM_PARTIAL) &&
+	    mlx5e_psp_is_offload(skb, netdev)) {
+		if (skb_is_gso(skb) &&
+		    !(skb_shinfo(skb)->gso_type &
+		      (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)))
+			features &= ~NETIF_F_GSO_MASK;
+		if (skb->ip_summed == CHECKSUM_PARTIAL &&
+		    !mlx5e_psp_l4_csum_ok(skb))
+			features &= ~NETIF_F_CSUM_MASK;
+	}

[Severity: Medium]
Can clearing NETIF_F_CSUM_MASK and NETIF_F_GSO_MASK on an already encapsulated GSO skb (skb->encapsulation == 1) cause software tunnel GSO to strip skb->encapsulation and bypass the check in psp_dev_encap_ok()?

For a PSP-offloaded GSO packet encapsulated in a tunnel such as GRE, mlx5e_psp_l4_csum_ok() sees IPPROTO_GRE and clears NETIF_F_CSUM_MASK, which also clears NETIF_F_GSO_MASK in harmonize_features(). validate_xmit_skb() then runs software tunnel GSO (gre_gso_segment()), which completes the inner checksums in software, leaves seg->encapsulation as 0, points seg->transport_header at the outer GRE header right after the outer IP header, and for SKB_GSO_GRE_CSUM sets seg->ip_summed to CHECKSUM_PARTIAL.

When those segments reach mlx5e_psp_handle_tx_skb() -> psp_dev_encapsulate(), psp_dev_encap_ok() sees seg->encapsulation == 0 and network_len == ip_hdrlen(seg), so it encapsulates the outer GRE packet with nexthdr = IPPROTO_GRE instead of dropping it. In the mlx5e TX path, mlx5e_psp_set_swp() leaves eseg->swp_inner_l4_offset as 0 for IPPROTO_GRE while mlx5e_psp_txwqe_build_eseg_csum() still sets MLX5_ETH_WQE_L4_INNER_CSUM because seg->ip_summed == CHECKSUM_PARTIAL, producing corrupted frames or hardware TX descriptor syndromes.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#8 lore raw

Re: [PATCH net-next v1 03/15] psp: declare psp_assoc_set_tx() in psp.h

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

socket-less psp associations will need to install a tx key the same way sockets do.

make psp_assoc_set_tx() non-static, add a declaration within net/psp

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#15 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines

currently, a psp association is bound to a tcp socket when it is created, and can hold both an rx and a tx key.

add a small registry of un-bound associations. These have either an rx or tx flavor, and are referenced by an id. other parts of the stack can then attach them to packets. see the subsequent patches, where the tc psp action does just this.

an rx association records the spi, version, and device key generation, primarily for describe (assoc-get). a tc filter matches these fields with the flower keys psp_spi, psp_ver, and psp_dev instead of referencing the association by id, to facilitate hw offload. these matches are added in a subsequent patch.

Quoted 7 lines

adds the following new netlink commands for managing these associations. [ ... ]

published associations are dropped from the registry when their psp device is unregistered.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#19 lore raw

Re: [PATCH net-next v1 05/15] net: add METADATA_PSP dst to carry a psp association on an skb

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] net: out-of-bounds read in…

Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] net: out-of-bounds read in skb_metadata_dst_cmp() [1] --

commit bf04d738461897fa25a1f7c67c60f36977a2704d
Author: Todd Freed <[email protected]>

net: add METADATA_PSP dst to carry a psp association on an skb

This commit adds a METADATA_PSP metadata_dst type to hold a reference to a PSP association on socket-less skbs and validates target device and MTU constraints during transmission.

Quoted 4 lines
include/net/dst_metadata.h +0 -0
index f45d1e3163f00..73755bce2df06 100644

[ ... ]

include/net/dst_metadata.h static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a, · line 149

Quoted 9 lines
include/net/dst_metadata.h +2 -0
@@ -125,6 +142,8 @@ static inline int skb_metadata_dst_cmp(const struct sk_buff *skb_a,
 	case METADATA_XFRM:
 		return memcmp(&a->u.xfrm_info, &b->u.xfrm_info,
 			      sizeof(a->u.xfrm_info));
+	case METADATA_PSP:
+		return a->u.psp_info.pas != b->u.psp_info.pas;
 	default:
 		return 1;
 	}

[Severity: Critical]
This problem wasn't introduced by this patch, but can skb_metadata_dst_cmp() trigger an out-of-bounds read [1] by casting skb_dst() without checking DST_METADATA?

include/net/dst_metadata.h:skb_metadata_dst_cmp() {
	...
	a = (const struct metadata_dst *) skb_dst(skb_a);
	b = (const struct metadata_dst *) skb_dst(skb_b);

	if (!a != !b || a->type != b->type)
		return 1;
	...
}

When loopback_xmit() preserves a standard rtable via skb_dst_force() and the packet enters gro_list_prepare(), skb_metadata_dst_cmp() downcasts the rtable to struct metadata_dst without using skb_metadata_dst(). Because struct metadata_dst is larger than struct rtable, reading a->type and the union members (such as METADATA_IP_TUNNEL's tun_info and options_len) reads past the rtable slab object, which can crash the kernel if the access crosses an unmapped page boundary.

[1] https://sashiko.dev/#/bug/linux-cad8ab9c-3c7e-48ba-8546-0bb9ceb5d8be

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#23 lore raw

Re: [PATCH net-next v1 06/15] net/sched: act_mirred: don't send decrypted skbs from egress to ingress

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 16 lines

on transmit, skb->decrypted means the device must encrypt the packet. For example, a packet of a ktls or psp offload socket, or, with the tc psp action added later in this series, one which psp encap attached a tx association to.

on receive, skb->decrypted means the device decrypted the packet.

a packet redirected or mirrored from egress to ingress is by definition not going to the device that would encrypt it, and on ingress skb->decrypted now (incorrectly, for this packet) indicates it was decrypted by the device.

this is less of a problem with socket offloads, whose packets are by definition originated locally; more of a problem with socket-less psp, which can also apply to forwarded traffic.

Quoted 8 lines

mirred also drops the dst, which for socket-less psp carries the tx association. clearing the bit instead would let the packet be forwarded in clear text, so that wouldn't work.

don't send decrypted skbs from egress to ingress: a redirected one is dropped, a mirrored one isn't copied.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#26 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] bpf: non-standard multi-line comment style in __bpf_redirect() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: non-standard multi-line comment style in __bpf_redirect() --

commit a5cc3bc1e6d8f72d0aefee8fc281286777a450a4
Author: Todd Freed <[email protected]>

bpf: don't redirect decrypted skbs from egress to ingress

This commit drops packets with skb->decrypted set when BPF redirects them from egress to ingress in __bpf_redirect().

net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2231

Quoted 11 lines
net/core/filter.c +3 -0
index aca8160b26a1a..a178a9dd30070 100644
@@ -2226,6 +2226,15 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
 static int __bpf_redirect(struct sk_buff *skb, struct net_device *dev,
 			  u32 flags)
 {
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */

[Severity: Low]
This isn't a bug, but BPF code uses the multi-line comment style with the opening /* on its own line.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#35 lore raw

Re: [PATCH net-next v1 08/15] psp: only give time-wait sockets of psp connections a validator

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 4 lines

psp_twsk_init() sets tw_validate_xmit_skb on tcp time-wait sockets. today, that becomes set whether or not the socket has psp offload, which is not needed but is harmless. psp_validate_xmit() passes such packets.

Quoted 8 lines

but a validator makes a socket look like it has an encryption offload of its own, and the tc psp action, added in the next patch, relies on that:
encap refuses the packets of such a socket, and sk_validate_xmit_skb() drops a packet with a psp association whose socket has a validator.

set the validator only when the socket has a psp association.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#39 lore raw

Re: [PATCH net-next v1 09/15] net/sched: add act_psp for psp transport mode

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [High] net/sched: act_psp sets GSO transport_header without pulling L4 header - [Low] net/sched: act_psp…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [High] net/sched: act_psp sets GSO transport_header without pulling L4 header
- [Low] net/sched: act_psp: missing get_fill_size() callback in act_psp_ops
--

commit 53d19883448f901e4c3022f6ff521b64c7a129a7
Author: Todd Freed <[email protected]>

net/sched: add act_psp for psp transport mode

This commit introduces the act_psp traffic control action to attach PSP Tx associations via METADATA_PSP dsts on egress and strip PSP Rx extensions on decap.

Quoted 6 lines
net/sched/act_psp.c new file +0 -0
new file mode 100644
index 0000000000000..4ff54203c9f51
@@ -0,0 +1,439 @@

[ ... ]

Quoted 36 lines
net/sched/act_psp.c new file +36 -0
+static bool tcf_psp_set_transport_header(struct sk_buff *skb)
+{
+	unsigned int off = skb_network_offset(skb);
+	const struct iphdr *iph;
+	unsigned int hlen, len;
+
+	switch (skb->protocol) {
+	case htons(ETH_P_IP):
+		if (!pskb_may_pull(skb, off + sizeof(*iph)))
+			return false;
+		iph = ip_hdr(skb);
+		if (iph->version != 4 || iph->ihl < 5 || ip_is_fragment(iph))
+			return false;
+		hlen = iph->ihl * 4;
+		len = ntohs(iph->tot_len);
+		if (!pskb_may_pull(skb, off + hlen))
+			return false;
+		break;
+	case htons(ETH_P_IPV6):
+		if (!pskb_may_pull(skb, off + sizeof(struct ipv6hdr)))
+			return false;
+		if (ipv6_hdr(skb)->version != 6 ||
+		    ipv6_ext_hdr(ipv6_hdr(skb)->nexthdr))
+			return false;
+		hlen = sizeof(struct ipv6hdr);
+		len = hlen + ntohs(ipv6_hdr(skb)->payload_len);
+		break;
+	default:
+		return false;
+	}
+
+	/* The device takes the length of the payload from the packet: it must
+	 * hold the IP length, and L2 padding, e.g. of a minimum size frame,
+	 * must not be encrypted as payload. A GSO skb's header doesn't always
+	 * carry its length (BIG TCP).
+	 */

net/sched/act_psp.c line 81

Quoted 10 lines
net/sched/act_psp.c new file +10 -0
+	if (!skb_is_gso(skb)) {
+		if (len < hlen || skb->len - off < len)
+			return false;
+		if (pskb_trim_rcsum(skb, off + len))
+			return false;
+	}
+
+	skb_set_transport_header(skb, off + hlen);
+	return true;
+}

[Severity: High]
Can tcf_psp_set_transport_header() set skb->transport_header on a GSO packet without pulling the L4 header into linear data?

tcf_psp_set_transport_header() only pulls off + hlen bytes before updating skb->transport_header to off + hlen. If a GSO packet enters egress with an unset transport_header (for example, a decapsulated GSO packet bridged after gro_cells_receive() calls skb_unset_transport_header()) or with a smaller initial transport_header offset from virtio_net_hdr_to_skb(), qdisc_pkt_len_segs_init() does not pull the L4 header at off + hlen.

Immediately after sch_handle_egress() in __dev_queue_xmit(), psp_xmit_md() -> skb_gso_validate_network_len() -> skb_gso_network_seglen() -> skb_gso_transport_seglen() calls tcp_hdrlen(skb), reading tcp_hdr(skb)->doff past skb->tail, and mlx5e_psp_handle_tx_skb() writes to inner_tcp_hdr(skb)->check out of bounds. In addition, unconditionally overwriting skb->transport_header to off + hlen defeats the skb_network_header_len(skb) check in psp_dev_encap_ok().

[ ... ]

Quoted 38 lines
net/sched/act_psp.c new file +38 -0
+static int tcf_psp_dump(struct sk_buff *skb, struct tc_action *a,
+			int bind, int ref)
+{
+	unsigned char *b = skb_tail_pointer(skb);
+	struct tcf_psp *p = to_psp(a);
+	struct tcf_psp_params *params;
+	struct tc_psp opt = {
+		.index    = p->tcf_index,
+		.refcnt   = refcount_read(&p->tcf_refcnt) - ref,
+		.bindcnt  = atomic_read(&p->tcf_bindcnt) - bind,
+	};
+	struct tcf_t t;
+
+	rcu_read_lock();
+	params = rcu_dereference(p->params);
+	opt.action = params->action;
+
+	if (nla_put(skb, TCA_PSP_PARMS, sizeof(opt), &opt) ||
+	    nla_put_u32(skb, TCA_PSP_ACTION, params->psp_action))
+		goto nla_put_failure;
+
+	if (params->md &&
+	    nla_put_u32(skb, TCA_PSP_ASSOC_ID, params->md->u.psp_info.pas->id))
+		goto nla_put_failure;
+
+	tcf_tm_dump(&t, &p->tcf_tm);
+	if (nla_put_64bit(skb, TCA_PSP_TM, sizeof(t), &t, TCA_PSP_PAD))
+		goto nla_put_failure;
+	rcu_read_unlock();
+
+	return skb->len;
+
+nla_put_failure:
+	rcu_read_unlock();
+	nlmsg_trim(skb, b);
+	return -1;
+}
+

net/sched/act_psp.c line 403

Quoted 10 lines
net/sched/act_psp.c new file +10 -0
+static struct tc_action_ops act_psp_ops = {
+	.kind		=	"psp",
+	.id		=	TCA_ID_PSP,
+	.owner		=	THIS_MODULE,
+	.act		=	tcf_psp_act,
+	.dump		=	tcf_psp_dump,
+	.init		=	tcf_psp_init,
+	.cleanup	=	tcf_psp_cleanup,
+	.size		=	sizeof(struct tcf_psp),
+};

[Severity: Low]
Should act_psp_ops implement .get_fill_size?

Without .get_fill_size, tcf_action_fill_size() only budgets tcf_action_shared_attrs_size() and does not account for TCA_PSP_PARMS, TCA_PSP_ACTION, and TCA_PSP_ASSOC_ID (up to 40 bytes) emitted by tcf_psp_dump(), which can under-size the notification skb allocated in tcf_add_notify_msg(), tcf_del_notify_msg(), and tcf_get_notify() when shared attributes such as rate estimators and 64-bit stats are present.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#43 lore raw

Re: [PATCH net-next v1 10/15] net/sched: flower: add psp_spi, psp_ver, and psp_dev matches

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 22 lines

Add a flow dissector key filled from the PSP Rx state (SKB_EXT_PSP) the device attached to a decrypted packet, and corresponding flower matches. SPI the packet was decrypted with (psp_spi, with a mask), PSP version (psp_ver), and the ID of the PSP device which decrypted it (psp_dev).

For example, to take the packets of one Rx association, (created with rx-spi-alloc), and remove their PSP state so that they can be forwarded,

tc filter add dev eth0 ingress protocol ipv6 flower
psp_spi 0x80000001 psp_ver 0 psp_dev 1 action psp decap

Together these matches tie a rule to one association, in a form which hw can match on (offload comes in a follow-up series). The SPI is only unique on its PSP device, and an association has one PSP version. This matches the per-packet check that psp sockets have against its association, with one exception - the generation of the device key is not checked.

this means that a rule matching packets that correspond to an rx association which is stale (two rotations have passed), can still match.

Quoted 8 lines

It is therefore important that a rule which matches a SPI should be replaced before the device key has had two rotations. follow up work will bring enforcement of this based on key rotation events.

Note that this only ever matches packets which were decrypted, even if the mask is 0. So "psp_spi 0/0" matches any decrypted PSP packet.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#47 lore raw

Re: [PATCH net-next v1 11/15] selftests: drv-net: psp: test socket-less associations and the tc psp action

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] selftests: drv-net: psp: hand-rolled sysctl and polling helpers in psp.py --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] selftests: drv-net: psp: hand-rolled sysctl and polling helpers in psp.py
--

commit 97820709dd90b6f5b2af8e09b179cf5d698f9d28
Author: Todd Freed <[email protected]>

selftests: drv-net: psp: test socket-less associations and the tc psp action

This commit adds selftests covering PSP socket-less associations and the tc psp action for control and data paths.

Quoted 4 lines
tools/testing/selftests/drivers/net/psp.py +0 -0
index 473500901879b..fb75444100515 100755

[ ... ]

Quoted 7 lines
tools/testing/selftests/drivers/net/psp.py +3 -0
@@ -683,6 +685,591 @@ def data_mss_adjust(cfg, ipver):
     _data_mss_adjust(cfg, ipver)
 
 
+#
+# Socket-less associations and the tc psp action
+#

[ ... ]

Quoted 10 lines
tools/testing/selftests/drivers/net/psp.py +10 -0
+def _wait_data_outq(s, exp_len, timeout=5):
+    """ Like _check_data_outq() but leave time for retransmits """
+    outq = 0
+    end = time.monotonic() + timeout
+    while time.monotonic() < end:
+        outq = _get_outq(s)
+        if outq == exp_len:
+            break
+        time.sleep(0.05)
+    ksft_eq(outq, exp_len)

[ ... ]

tools/testing/selftests/drivers/net/psp.py def data_mss_adjust(cfg, ipver): · line 1202

Quoted 13 lines
tools/testing/selftests/drivers/net/psp.py +13 -0
+def data_tc_encap_ingress(cfg):
+    """ Test packets with an assoc aren't redirected to ingress """
+    _init_psp_dev(cfg)
+    _require_tc_psp(cfg)
+
+    _, tx = _sockless_assocs(cfg)
+    # Traffic to a local address leaves through lo, and comes back on its
+    # ingress. With the dst gone, input routing takes a loopback source for
+    # a martian, and needs accept_local for a local one.
+    sysctl = "net.ipv4.conf.lo.accept_local"
+    old = cmd(f"sysctl -n {sysctl}").stdout.strip()
+    cmd(f"sysctl -w {sysctl}=1")
+    defer(cmd, f"sysctl -w {sysctl}={old}")

[Severity: Low]
This isn't a bug, but could data_tc_encap_ingress() use ctl_file_write('/proc/sys/net/ipv4/conf/lo/accept_local', 1) from lib.py instead of spawning sysctl subprocesses to read, write, and restore the setting? Similarly, _wait_data_outq() duplicates the polling loop in _check_data_outq() and could parameterize _check_data_outq() or use ksft_busy_wait().

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11
#49 lore raw

Re: [PATCH net-next v1 12/15] selftests: drv-net: psp: test that software encap on ingress drops

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

encap on ingress is hardware offload only. In software, the packet is dropped.

Verify it on traffic of a client behind a veth, with encap on the veth's
ingress: forwarded, the packets must not reach the remote in clear text, and to a local address, they must not reach the local socket.

Quoted 5 lines

data_tc_encap_routed routed packets are dropped by encap, IPv4 and
IPv6
data_tc_encap_local so are packets to a local address

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=12
#51 lore raw

Re: [PATCH net-next v1 13/15] selftests: tc-testing: run dependsOn probes outside the test namespace

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] selftests: tc-testing: missing Fixes: trailer for dependsOn probe fix in run_one_test() --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] selftests: tc-testing: missing Fixes: trailer for dependsOn probe fix in run_one_test()
--

commit b366286cfdfd21956025890cdfcc1c16cfe59bd5
Author: Todd Freed <[email protected]>

Quoted 8 lines

selftests: tc-testing: run dependsOn probes outside the test namespace

a test's dependsOn probe runs as an execute stage command, but is run before the test's namespace is created. nsPlugin prefixes the command with "ip netns exec tcut", which causes the command to fail. this makes every test with a probe that requires nsPlugin skipped currently. for example the mirred blockid tests and the tunnel_key nofrag test.

Quoted 5 lines

probes are meant to check what tc and the kernel supports, not anything in the test's namespace. run them as their own stage ("probe"), which makes them run in the base namespace.

[Severity: Low]
Since this fixes dependsOn probes running with the "execute" stage after per-test namespaces replaced the shared tcut namespace, consider adding a
Fixes: tag:

Fixes 98cfbe4234a4 ("selftests/tc-testing: localize test resources")
Fixes 7f3f86402609 ("selftests: tc-testing: add "depends_on" property to skip tests")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=13
#54 lore raw

Re: [PATCH net-next v1 14/15] selftests: tc-testing: add tests for the psp action

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

Add / replace / delete / flush psp decap actions, check that encap without an association, associations which don't exist, and decap with an association are rejected, and add flower filters matching on psp_spi, psp_ver and psp_dev, out of range psp_ver and psp_dev rejected.

Quoted 7 lines

Creating associations takes the PSP netlink family and a PSP device, the drv-net psp.py test covers actions using them.

The tests need a tc with the psp action and the flower psp_* keys; they skip without it (dependsOn).

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=14
#57 lore raw

Re: [PATCH net-next v1 15/15] Documentation: networking: psp: document socket-less associations

In reply to Todd Freed
Sashiko has reviewed this patch and found no issues.
Quoted 11 lines

Describe PSP associations, and how they differ for the socket and tc use cases.

Document the new netlink commands for manging socket-less associations.

Document the psp tc action, and flower psp_spi, psp_ver, and psp_dev matches.

Add a new section to describe pre-existing PSP device stats.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=15
#60 lore raw
In reply to Daniel Zahka
Quoted 4 lines

Some of these can probably stand alone like the bpf decrypted, psp encap helper, and timewait validation, and be submitted first to shorten the series. That's just a suggestion though. If there are dependencies on the main series you can ignore.

Ok, I will re-post 6, 7, and 8 as Fixes to net.

-Todd

maintainer
#61 lore raw
In reply to Todd Freed
Quoted 56 lines · Todd Freed

psp associations today are bound to a tcp socket when created. traffic on that socket is encapsulated in transport-mode psp, and encrypted.

this series adds associations which aren't bound to a socket, which allows psp encapsulation and encryption to be applied to forwarded traffic. you can use this to transparently apply psp tunnels to flows, with help from userspace to manage the tc rules and orchestrate key exchange.

the lifecycle of socket-less associations is managed over the psp netlink family. socket-less associations are stored in a small registry, and are addressable by id. the registry does not contain socket associations.

socket-less associations are on the device's association lists, like socket associations. rx ones are therefore marked stale by key rotation in the same way. in this series, nothing acts on socket-less rx associations on key rotation. instead, userspace should replace decap rules for a SPI before its device key has been rotated twice. a follow-up will bring enforcement.

series structure,

1, 2/ prepares psp to work with non-tcp packets

3, 4/ adds the netlink commands for managing socket-less associations

5/ adds a METADATA_PSP dst which carries the socket-less psp association on an skb for tx, and the transmit checks for it

6, 7/ keep mirred and bpf from sending decrypted skbs from egress to ingress, since skb->decrypted depends on direction

8/ limit time-wait psp socket validator to sockets actually in time-wait. the new psp actions check for presence of the validator

9/ adds the act_psp tc actions, psp encap and psp decap. in software, encap is egress only.

10/ adds flower matches on psp header fields, for rx matching

11, 12/ add drv-net tests (netdevsim and hardware)

13/ makes tc-testing run dependsOn probes outside the test namespace, where they currently always fail

14/ adds tc-testing tests

15/ Documentation for socket-less psp associations

a following series adds hardware offload of the psp actions and flower matches, psp tunnel mode (which is offload only and therefore not included here), encap on ingress (also offload only), and the mlx5 implementation for switchdev mode. It's available in the tree below.

Quoted 5 lines

relation to the psp fixes in net:

this series is based on net-next, and overlaps with "psp, tls: don't send offloaded contents in cleartext" in net:

I looked at the net/sched bits also looks like the two sashikos already caught at least two issues i would have brought up. I have started a test run on our test system to see if anything pops up; i dont suspect anything will show up, but if it does, I will followup to this posting.
My suggestion is you address the issues brought up by the sashikos and spin v2. I will review when you post a v2 and possibly add my reviewed-by.
In v2:
If you have, or can capture, the decapped-GSO packet shape that leaves the L4 header non-linear (gro_cells/vnet_hdr decap bridged to the act_psp
egress), attaching it to the v2 would be useful evidence for the GSO fix.

cheers,
jamal

Quoted 128 lines

https://lore.kernel.org/netdev/[email protected]

when net is merged into net-next:

- net/psp/psp_main.c conflicts around psp_dev_encap_ok(), which both
add: net's only allows tcp, this series' (patch 2) takes any l4 protocol. keep this series' version of the function, and its comments above it and above psp_dev_encapsulate().
- tools/testing/selftests/drivers/net/psp.py and tools/testing/selftests/drivers/net/config conflict: keep both sides (imports, constants, the list of test cases; the NET_ACT_* options).

relation to the netfilter fixes in nf-next:

packets which a psp device decrypted don't have to end in a local psp socket. they can already be forwarded or bridged today, but with socket-less associations that is the intended use, e.g. a router that decaps and forwards. netfilter handles two cases itself, outside the ip stack paths which the net series fixes, and would send such a packet's decrypted contents in clear text:

- the bridge refragments packets which bridge conntrack reassembled (br_ip6_fragment(), nf_br_ip_fragment()), without the check of "net:
don't fragment decrypted skbs".
- the reject code builds its own icmp errors and tcp resets (nf_reject_skb_v4_unreach() and friends), without icmp_send() and icmpv6_send(), which the net series' icmp patches cover.

a separate series to nf-next applies the net series' rules to both:

"netfilter: bridge: don't refragment decrypted skbs" "netfilter: reject: don't reply to decrypted skbs"

https://lore.kernel.org/netfilter-devel/[email protected]

it doesn't depend on this series, and the two don't conflict.

trees:

the full tree, with the net fixes, the nf-next series, this series and the mlx5 offload series, and the conflicts above resolved, is at:

https://github.com/toddfreed/psptc branch psptc

iproute2 tree, with support for the psp action and the psp flower matches, based on iproute2-next. the selftests need it:

https://github.com/toddfreed/iproute2-psptc branch tc-psp

testing:

- netdevsim: drivers/net psp.py passes (57 tests), and tc-testing psp.json (17 tests).
- mlx5 (ConnectX-7, FW 28.48), two hosts: drivers/net psp.py passes:
46 pass, 8 skip (GMAC versions not supported by the device), 3 xfail (netdevsim only).
- each patch builds without warnings with gcc and clang, allmodconfig, W=1.
Todd Freed (15):
psp: get netns from net_device instead of sock
psp: take the psp nexthdr from the packet on encap
psp: declare psp_assoc_set_tx() in psp.h
psp: add support for socket-less psp associations
net: add METADATA_PSP dst to carry a psp association on an skb net/sched: act_mirred: don't send decrypted skbs from egress to
ingress
bpf: don't redirect decrypted skbs from egress to ingress
psp: only give time-wait sockets of psp connections a validator net/sched: add act_psp for psp transport mode
net/sched: flower: add psp_spi, psp_ver, and psp_dev matches
selftests: drv-net: psp: test socket-less associations and the tc psp
action
selftests: drv-net: psp: test that software encap on ingress drops
selftests: tc-testing: run dependsOn probes outside the test namespace
selftests: tc-testing: add tests for the psp action
Documentation: networking: psp: document socket-less associations

 Documentation/netlink/specs/psp.yaml          |  98 ++-
 Documentation/netlink/specs/tc.yaml           |  14 +
 Documentation/networking/psp.rst              | 139 +++-
 MAINTAINERS                                   |   3 +
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |   2 +-
 .../net/ethernet/mellanox/mlx5/core/en_main.c |  33 +
 drivers/net/netdevsim/psp.c                   |   2 +-
 include/linux/skbuff.h                        |   4 +
 include/net/dst_metadata.h                    |  19 +
 include/net/flow_dissector.h                  |  18 +
 include/net/psp/functions.h                   |  91 ++-
 include/net/psp/types.h                       |   1 +
 include/net/tc_act/tc_psp.h                   |  23 +
 include/uapi/linux/pkt_cls.h                  |   6 +
 include/uapi/linux/psp.h                      |   6 +
 include/uapi/linux/tc_act/tc_psp.h            |  28 +
 net/core/dev.c                                |  48 +-
 net/core/dst.c                                |   5 +
 net/core/filter.c                             |   9 +
 net/core/flow_dissector.c                     |  27 +
 net/psp/Makefile                              |   2 +-
 net/psp/psp-nl-gen.c                          |  60 ++
 net/psp/psp-nl-gen.h                          |   8 +
 net/psp/psp.h                                 |   7 +
 net/psp/psp_assoc.c                           | 120 +++
 net/psp/psp_main.c                            |  54 +-
 net/psp/psp_nl.c                              | 261 ++++++
 net/psp/psp_sock.c                            |  32 +-
 net/sched/Kconfig                             |  13 +
 net/sched/Makefile                            |   1 +
 net/sched/act_mirred.c                        |   6 +
 net/sched/act_psp.c                           | 439 ++++++++++
 net/sched/cls_flower.c                        |  64 ++
 tools/testing/selftests/drivers/net/config    |   5 +
 tools/testing/selftests/drivers/net/psp.py    | 750 +++++++++++++++++-
 tools/testing/selftests/tc-testing/config     |   2 +
 .../tc-testing/tc-tests/actions/psp.json      | 459 +++++++++++
 tools/testing/selftests/tc-testing/tdc.py     |   2 +-
 tools/testing/selftests/tc-testing/tdc.sh     |   1 +
 39 files changed, 2812 insertions(+), 50 deletions(-)
 create mode 100644 include/net/tc_act/tc_psp.h
 create mode 100644 include/uapi/linux/tc_act/tc_psp.h
 create mode 100644 net/psp/psp_assoc.c
 create mode 100644 net/sched/act_psp.c
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/psp.json

base-commit: ed04b202027249e2769420893220f54a56e0c59a --
2.53.0-Meta

maintainer
#62 lore raw
Quoted 64 lines · Jamal Hadi Salim
Quoted 56 lines · Todd Freed

psp associations today are bound to a tcp socket when created. traffic on that socket is encapsulated in transport-mode psp, and encrypted.

this series adds associations which aren't bound to a socket, which allows psp encapsulation and encryption to be applied to forwarded traffic. you can use this to transparently apply psp tunnels to flows, with help from userspace to manage the tc rules and orchestrate key exchange.

the lifecycle of socket-less associations is managed over the psp netlink family. socket-less associations are stored in a small registry, and are addressable by id. the registry does not contain socket associations.

socket-less associations are on the device's association lists, like socket associations. rx ones are therefore marked stale by key rotation in the same way. in this series, nothing acts on socket-less rx associations on key rotation. instead, userspace should replace decap rules for a SPI before its device key has been rotated twice. a follow-up will bring enforcement.

series structure,

1, 2/ prepares psp to work with non-tcp packets

3, 4/ adds the netlink commands for managing socket-less associations

5/ adds a METADATA_PSP dst which carries the socket-less psp association on an skb for tx, and the transmit checks for it

6, 7/ keep mirred and bpf from sending decrypted skbs from egress to ingress, since skb->decrypted depends on direction

8/ limit time-wait psp socket validator to sockets actually in time-wait. the new psp actions check for presence of the validator

9/ adds the act_psp tc actions, psp encap and psp decap. in software, encap is egress only.

10/ adds flower matches on psp header fields, for rx matching

11, 12/ add drv-net tests (netdevsim and hardware)

13/ makes tc-testing run dependsOn probes outside the test namespace, where they currently always fail

14/ adds tc-testing tests

15/ Documentation for socket-less psp associations

a following series adds hardware offload of the psp actions and flower matches, psp tunnel mode (which is offload only and therefore not included here), encap on ingress (also offload only), and the mlx5 implementation for switchdev mode. It's available in the tree below.

Quoted 5 lines

relation to the psp fixes in net:

this series is based on net-next, and overlaps with "psp, tls: don't send offloaded contents in cleartext" in net:

Quoted 14 lines

I looked at the net/sched bits also looks like the two sashikos already caught at least two issues i would have brought up. I have started a test run on our test system to see if anything pops up; i dont suspect anything will show up, but if it does, I will followup to this posting.
My suggestion is you address the issues brought up by the sashikos and spin v2. I will review when you post a v2 and possibly add my reviewed-by.
In v2:
If you have, or can capture, the decapped-GSO packet shape that leaves the L4 header non-linear (gro_cells/vnet_hdr decap bridged to the act_psp
egress), attaching it to the v2 would be useful evidence for the GSO fix.

My bad - only one of the sashikos (gemini) responded. I suggest you wait for the second one. I think it watches this gemini sashiko and tries to come up with more clever findings.

Here's my view after trying to see if we can actually reproduce the claims:
The only legit thing is "act_psp, [Low] missing .get_fill_size", you need to add that.

act_psp, [High] "GSO skb with non-linear L4 header -> OOB read/write"
- this sounds like BS/false positive, but the burden of proof is on you ;-> If that code is broken, then a lot of kernel GSO code is broken from the grep-ing. GSO skb's transport header is linear by tc egress time.

act_psp, secondary claim that the transport_header write "defeats" psp_dev_encap_ok() - that also looks made up.
Double check.

cheers,
jamal

Quoted 128 lines
Quoted 128 lines

https://lore.kernel.org/netdev/[email protected]

when net is merged into net-next:

- net/psp/psp_main.c conflicts around psp_dev_encap_ok(), which both
add: net's only allows tcp, this series' (patch 2) takes any l4 protocol. keep this series' version of the function, and its comments above it and above psp_dev_encapsulate().
- tools/testing/selftests/drivers/net/psp.py and tools/testing/selftests/drivers/net/config conflict: keep both sides (imports, constants, the list of test cases; the NET_ACT_* options).

relation to the netfilter fixes in nf-next:

packets which a psp device decrypted don't have to end in a local psp socket. they can already be forwarded or bridged today, but with socket-less associations that is the intended use, e.g. a router that decaps and forwards. netfilter handles two cases itself, outside the ip stack paths which the net series fixes, and would send such a packet's decrypted contents in clear text:

- the bridge refragments packets which bridge conntrack reassembled (br_ip6_fragment(), nf_br_ip_fragment()), without the check of "net:
don't fragment decrypted skbs".
- the reject code builds its own icmp errors and tcp resets (nf_reject_skb_v4_unreach() and friends), without icmp_send() and icmpv6_send(), which the net series' icmp patches cover.

a separate series to nf-next applies the net series' rules to both:

"netfilter: bridge: don't refragment decrypted skbs" "netfilter: reject: don't reply to decrypted skbs"

https://lore.kernel.org/netfilter-devel/[email protected]

it doesn't depend on this series, and the two don't conflict.

trees:

the full tree, with the net fixes, the nf-next series, this series and the mlx5 offload series, and the conflicts above resolved, is at:

https://github.com/toddfreed/psptc branch psptc

iproute2 tree, with support for the psp action and the psp flower matches, based on iproute2-next. the selftests need it:

https://github.com/toddfreed/iproute2-psptc branch tc-psp

testing:

- netdevsim: drivers/net psp.py passes (57 tests), and tc-testing psp.json (17 tests).
- mlx5 (ConnectX-7, FW 28.48), two hosts: drivers/net psp.py passes:
46 pass, 8 skip (GMAC versions not supported by the device), 3 xfail (netdevsim only).
- each patch builds without warnings with gcc and clang, allmodconfig, W=1.
Todd Freed (15):
psp: get netns from net_device instead of sock
psp: take the psp nexthdr from the packet on encap
psp: declare psp_assoc_set_tx() in psp.h
psp: add support for socket-less psp associations
net: add METADATA_PSP dst to carry a psp association on an skb net/sched: act_mirred: don't send decrypted skbs from egress to
ingress
bpf: don't redirect decrypted skbs from egress to ingress
psp: only give time-wait sockets of psp connections a validator net/sched: add act_psp for psp transport mode
net/sched: flower: add psp_spi, psp_ver, and psp_dev matches
selftests: drv-net: psp: test socket-less associations and the tc psp
action
selftests: drv-net: psp: test that software encap on ingress drops
selftests: tc-testing: run dependsOn probes outside the test namespace
selftests: tc-testing: add tests for the psp action
Documentation: networking: psp: document socket-less associations

 Documentation/netlink/specs/psp.yaml          |  98 ++-
 Documentation/netlink/specs/tc.yaml           |  14 +
 Documentation/networking/psp.rst              | 139 +++-
 MAINTAINERS                                   |   3 +
 .../mellanox/mlx5/core/en_accel/psp_rxtx.c    |   2 +-
 .../net/ethernet/mellanox/mlx5/core/en_main.c |  33 +
 drivers/net/netdevsim/psp.c                   |   2 +-
 include/linux/skbuff.h                        |   4 +
 include/net/dst_metadata.h                    |  19 +
 include/net/flow_dissector.h                  |  18 +
 include/net/psp/functions.h                   |  91 ++-
 include/net/psp/types.h                       |   1 +
 include/net/tc_act/tc_psp.h                   |  23 +
 include/uapi/linux/pkt_cls.h                  |   6 +
 include/uapi/linux/psp.h                      |   6 +
 include/uapi/linux/tc_act/tc_psp.h            |  28 +
 net/core/dev.c                                |  48 +-
 net/core/dst.c                                |   5 +
 net/core/filter.c                             |   9 +
 net/core/flow_dissector.c                     |  27 +
 net/psp/Makefile                              |   2 +-
 net/psp/psp-nl-gen.c                          |  60 ++
 net/psp/psp-nl-gen.h                          |   8 +
 net/psp/psp.h                                 |   7 +
 net/psp/psp_assoc.c                           | 120 +++
 net/psp/psp_main.c                            |  54 +-
 net/psp/psp_nl.c                              | 261 ++++++
 net/psp/psp_sock.c                            |  32 +-
 net/sched/Kconfig                             |  13 +
 net/sched/Makefile                            |   1 +
 net/sched/act_mirred.c                        |   6 +
 net/sched/act_psp.c                           | 439 ++++++++++
 net/sched/cls_flower.c                        |  64 ++
 tools/testing/selftests/drivers/net/config    |   5 +
 tools/testing/selftests/drivers/net/psp.py    | 750 +++++++++++++++++-
 tools/testing/selftests/tc-testing/config     |   2 +
 .../tc-testing/tc-tests/actions/psp.json      | 459 +++++++++++
 tools/testing/selftests/tc-testing/tdc.py     |   2 +-
 tools/testing/selftests/tc-testing/tdc.sh     |   1 +
 39 files changed, 2812 insertions(+), 50 deletions(-)
 create mode 100644 include/net/tc_act/tc_psp.h
 create mode 100644 include/uapi/linux/tc_act/tc_psp.h
 create mode 100644 net/psp/psp_assoc.c
 create mode 100644 net/sched/act_psp.c
 create mode 100644 tools/testing/selftests/tc-testing/tc-tests/actions/psp.json

base-commit: ed04b202027249e2769420893220f54a56e0c59a --
2.53.0-Meta

#63 lore raw
Quoted 3 lines

My bad - only one of the sashikos (gemini) responded. I suggest you wait for the second one. I think it watches this gemini sashiko and tries to come up with more clever findings.

Ok, I will wait for that before posting v2. What is the best way to know if that has happened? This posting is from 3 days ago so I would have expected all the sashiko reviews to be complete by now. Let me know if I should adjust my expectation.

I think this is the right place to look

https://sashiko.dev/#/patchset/20261111005533.6436-1-toddfreed%40meta.com

-Todd

#5 lore raw

Re: [PATCH net-next v1 02/15] psp: take the psp nexthdr from the packet on encap

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] This patch makes psp_dev_encapsulate() accept protocols other than TCP: psp->nexthdr and inner_ipproto now come from the packet, and…

--

psp: take the psp nexthdr from the packet on encap

This patch takes the PSP next header from the IP header of the original packet instead of hardcoding IPPROTO_TCP, so that socket-less associations can carry UDP. psp_dev_encapsulate() now refuses packets with IPv6 extension headers, IPv4 fragments and skbs that are already encapsulated. mlx5e_features_check() also turns off GSO and checksum offload for PSP skbs the device can't handle.

Quoted 4 lines
net/psp/psp_main.c +0 -0
index e09f6fec948d7..1eb1617aaf2b5 100644

[ ... ]

net/psp/psp_main.c static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi, · line 240

Quoted 6 lines
net/psp/psp_main.c +1 -1
@@ -236,7 +237,7 @@ static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi,
 	uh->check = 0;
 	udp_set_len(uh, udp_len);
 
-	psph->nexthdr = IPPROTO_TCP;
+	psph->nexthdr = nexthdr;

[Severity: Medium]

psp_dev_encapsulate() now accepts non-TCP packets. Is the outer UDP source port selection in psp_write_headers() still correct when skb->sk is a UDP socket?

The code just above this hunk still does:

	if (likely(sk)) {
		u32 hash = sk->sk_hash;
		...
		hash ^= hash << 16;
		uh->source = htons(reciprocal_scale(hash, max - min + 1) + min);
	}

The comment there assumes sk_hash is the TCP ehash, which stays constant for the life of the flow. UDP sockets use the same storage for other values:

include/linux/udp.h:
#define udp_port_hash inet.sk.__sk_common.skc_u16hashes[0]
#define udp_portaddr_hash inet.sk.__sk_common.skc_u16hashes[1]

udp_lib_get_port() then sets:

	udp_sk(sk)->udp_port_hash = snum;
	udp_sk(sk)->udp_portaddr_hash ^= snum;

At that point udp_portaddr_hash already holds
ipv4_portaddr_hash(net, rcv_saddr, 0).

After hash ^= hash << 16, the upper 16 bits are udp_portaddr_hash ^ udp_port_hash. That cancels snum and leaves only the hash of the netns and local address. reciprocal_scale() uses essentially only those upper bits.

Wouldn't every UDP socket bound to the same local address then get the same outer PSP source port? That includes all wildcard-bound sockets in a netns, and it would undo the RSS spreading the comment describes.

This path becomes reachable later in the series. tcf_psp_act() in net/sched/act_psp.c attaches the METADATA_PSP dst to egress skbs that still carry their UDP skb->sk. As a result, mlx5 and netdevsim call psp_dev_encapsulate()->psp_write_headers() with a UDP socket. The later patches in the series leave psp_write_headers() unchanged. The sk == NULL branch, which uses udp_flow_src_port(), is not affected.

Should the sk->sk_hash path be limited to TCP sockets, with other sockets falling back to udp_flow_src_port()?

Quoted 3 lines
net/psp/psp_main.c +0 -0
 	psph->hdrlen = PSP_HDRLEN_NOOPT;
 	psph->crypt_offset = 0;
 	psph->verfl = FIELD_PREP(PSPHDR_VERFL_VERSION, ver) |

[ ... ]

Quoted 14 lines
net/psp/psp_main.c +2 -2
@@ -279,11 +313,11 @@ bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,
 		be16_add_cpu(&ipv6_hdr(skb)->payload_len, PSP_ENCAP_HLEN);
 	}
 
-	skb_set_inner_ipproto(skb, IPPROTO_TCP);
+	skb_set_inner_ipproto(skb, nexthdr);
 	skb_set_inner_transport_header(skb, skb_transport_offset(skb) +
 						    PSP_ENCAP_HLEN);
 	skb->encapsulation = 1;
-	psp_write_headers(net, skb, spi, ver,
+	psp_write_headers(net, skb, spi, ver, nexthdr,
 			  skb->len - skb_transport_offset(skb), sport);
 
 	return true;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#16 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit message misdescribes how keys are handled by the new socket-less association API.

--

psp: add support for socket-less psp associations

This commit adds a registry of PSP associations that are not bound to a socket. Each one is either an Rx or a Tx association and is referenced by an ID. It also adds the rx-spi-alloc, assoc-add, assoc-del and assoc-get netlink commands, which are admin-only, to manage these associations.

Quoted 3 lines

key material enters through netlink and is never reported back. no key is stored for rx associations, and users reference associations by id and never handle keys

[Severity: Medium]
Is this paragraph accurate? The code in this patch seems to do the opposite in two places.

psp_nl_rx_spi_alloc_doit() in net/psp/psp_nl.c returns the device-derived Rx key to user space:

net/psp/psp_nl.c:psp_nl_rx_spi_alloc_doit() {
    ...
	if (nla_put_u32(rsp, PSP_A_ASSOC_ID, pas->id) ||
	    nla_put_u32(rsp, PSP_A_ASSOC_DEV_ID, psd->id) ||
	    psp_nl_put_key(rsp, PSP_A_ASSOC_RX_KEY, version, &key)) {
    ...
}

psp_nl_put_key() emits PSP_A_KEYS_KEY with key_sz raw key bytes. The rx-spi-alloc doc in psp.yaml says the same thing: the key "must be passed to the peer out of band".

psp_nl_assoc_add_doit() also requires user space to supply the raw Tx key bytes:

net/psp/psp_nl.c:psp_nl_assoc_add_doit() {
    ...
	err = psp_nl_parse_key(info, PSP_A_ASSOC_TX_KEY, &key, key_sz);
    ...
}

So user space does handle keys, and rx-spi-alloc does report key material back.

The code only seems to guarantee two narrower things. No Rx key is stored in the association, and assoc-get reports only the SPI.

Could the commit message describe that more precisely? For example:
"the Rx key is returned once, by rx-spi-alloc, and is never stored or reported by assoc-get".

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#20 lore raw

Re: [PATCH net-next v1 05/15] net: add METADATA_PSP dst to carry a psp association on an skb

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit message says the second psp_xmit_md() check at dequeue, in sk_validate_xmit_skb() (net/core/dev.c:4164-4172), handles…

--

net: add METADATA_PSP dst to carry a psp association on an skb

This adds a METADATA_PSP metadata_dst type, which holds a reference on a psp association so that socket-less skbs (for example, ones marked by a tc rule) can be PSP-encrypted by existing driver tx paths. __dev_queue_xmit() now validates the metadata dst against the device and MTU and keeps the dst for the driver. sk_validate_xmit_skb() checks it again at dequeue in case the psp device was unregistered while the packet was queued.

Quoted 4 lines
net/core/dev.c +0 -0
index 9665f3b2f5cb2..2cca5f0d302f8 100644

[ ... ]

net/core/dev.c static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb, · line 4172

Quoted 13 lines
net/core/dev.c +9 -0
@@ -4156,6 +4161,15 @@ static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
 
 	if (sk_validate) {
 		skb = sk_validate(sk, dev, skb);
+	} else if (unlikely(skb_psp_md(skb))) {
+		int psp = psp_xmit_md(skb, dev);
+
+		if (psp <= 0) {
+			kfree_skb_reason(skb, psp == -EMSGSIZE ?
+					 SKB_DROP_REASON_PKT_TOO_BIG :
+					 SKB_DROP_REASON_PSP_OUTPUT);
+			skb = NULL;
+		}

[Severity: Medium]

The commit message says this re-check handles the case where "the psp device may have been unregistered while the packet was queued, and its keys deleted". Does that still hold for skbs that get requeued?

This check runs once, from validate_xmit_skb(), before the tx lock is taken. If the txq is stopped by then, sch_direct_xmit() requeues the skb into q->gso_skb. dequeue_skb() then sends it out again without validating it a second time:

net/sched/sch_generic.c:dequeue_skb() {
    ...
		/* skb in gso_skb were already validated */
		*validate = false;
		if (xfrm_offload(skb))
			*validate = true;
    ...
}

On mlx5, one possible sequence is:

CPU0
sch_direct_xmit()
validate_xmit_skb()
sk_validate_xmit_skb()
psp_xmit_md() returns 1

CPU1
mlx5e_nic_disable()
mlx5e_close()

    ...
      netif_tx_disable()

CPU0
HARD_TX_LOCK() finds the txq stopped
dev_requeue_skb() puts the skb on q->gso_skb

CPU1
mlx5e_psp_unregister()

    psp_dev_unregister()
      psp_dev_tx_key_del(psd, pas)
        mlx5e_psp_assoc_del()
          mlx5_destroy_encryption_key(priv->mdev, nkey->id);

Later, mlx5e_nic_enable() registers a new psd, and netif_device_attach() wakes the queues. The qdisc is not reset at any point. The stale skb then comes off gso_skb with validate set to false and reaches mlx5e_xmit(), where mlx5e_psp_set_state() still reads from the old association:

	psp_st->spi = pas->tx.spi;
	psp_st->ver = pas->version;
	psp_st->keyid = *(u32 *)pas->drv_data;

Can this hand the NIC the id of a DEK that has already been destroyed, and that may have been reused for another association? psp_xmit_md() would catch the psd mismatch, but it never runs again for this skb.

On mlx5, the plain check-then-xmit race is blocked because netif_tx_disable() runs before psp_dev_unregister(). That leaves only the requeue window.

The socket path through psp_validate_xmit() was already exposed in the same way before this patch. The new METADATA_PSP path, however, depends on this re-check to handle the unregister case.

Quoted 3 lines
net/core/dev.c +0 -0
 	} else if (unlikely(skb_is_decrypted(skb))) {
 		pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
 		kfree_skb(skb);

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#24 lore raw

Re: [PATCH net-next v1 06/15] net/sched: act_mirred: don't send decrypted skbs from egress to ingress

In reply to Todd Freed
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…

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] This patch adds the egress-to-ingress decrypted check only in tcf_mirred_to_dev() (net/sched/act_mirred.c:291-292).

--

net/sched: act_mirred: don't send decrypted skbs from egress to ingress

This commit stops tcf_mirred_to_dev() from sending skbs that have skb->decrypted set from egress to ingress. On transmit the bit asks the device to encrypt the packet, and on receive it means the device already decrypted it. Redirected skbs are dropped and mirrored skbs are not copied.

net/sched/act_mirred.c static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m, · line 292

Quoted 13 lines
net/sched/act_mirred.c +5 -0
index 1c98e4d81ebe6..52c3eeab381ae 100644
@@ -285,6 +285,12 @@ static int tcf_mirred_to_dev(struct sk_buff *skb, struct tcf_mirred *m,
 		goto err_cant_do;
 	}
 
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */
+	if (unlikely(want_ingress && !at_ingress && skb_is_decrypted(skb)))
+		goto err_cant_do;

[Severity: Low]
At this point in the series, is mirred the only egress to ingress path that needs this check?

A tc egress BPF program can still call bpf_redirect() or bpf_clone_redirect() with BPF_F_INGRESS. That skb goes through:

skb_do_redirect() / bpf_clone_redirect()
__bpf_redirect()

    __bpf_redirect_common() / __bpf_redirect_no_mac()
      __bpf_rx_skb()
        ____dev_forward_skb()
          skb_scrub_packet()

skb_scrub_packet() drops the dst but does not clear skb->decrypted. A kTLS or PSP offload socket skb would therefore reach ingress looking as if the device had decrypted it. The socket-less PSP case can't happen yet, because act_psp only arrives later in the series.

The next patch in the series, "bpf: don't redirect decrypted skbs from egress to ingress", seems to close this gap. It adds a matching check at the top of __bpf_redirect() in net/core/filter.c:

	if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
		     skb_is_decrypted(skb))) {
		kfree_skb(skb);
		return -EINVAL;
	}

BPF_F_PEER without BPF_F_EGRESS already drops anything that is not at tc ingress. So the gap only exists at this intermediate commit.

Would it be worth saying in this commit message that the BPF redirect path is handled in the following patch?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#27 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The new check in __bpf_redirect() (net/core/filter.c:2232-2233) decides that the skb is on egress, and…
- [Low] The new drop in __bpf_redirect() (net/core/filter.c:2234) uses kfree_skb(skb), which records SKB_DROP_REASON_NOT_SPECIFIED.
- [Low] bpf: non-standard multi-line comment style in __bpf_redirect()

--

bpf: don't redirect decrypted skbs from egress to ingress

With this patch, __bpf_redirect() drops skbs that have skb->decrypted set when they are redirected with BPF_F_INGRESS from outside tc ingress. On transmit the bit asks the device to encrypt. In a receive path the same bit would make the packet look like the device decrypted it. This matches the mirred change from the previous patch.

net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2233

Quoted 13 lines
net/core/filter.c +5 -0
index aca8160b26a1a..a178a9dd30070 100644
@@ -2226,6 +2226,15 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
 static int __bpf_redirect(struct sk_buff *skb, struct net_device *dev,
 			  u32 flags)
 {
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */
+	if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
+		     skb_is_decrypted(skb))) {

[Severity: Low]
This isn't a bug, but could the new comment in __bpf_redirect() use the multi-line comment style that BPF code prefers?

net/core/filter.c is covered by the BPF comment style. There the opening /* goes on its own line and the text starts on the next line, even where the surrounding code still uses the older networking style. The added comment puts "On transmit, decrypted asks the device ..." on the same line as the opening delimiter. Moving that text down one line would match the preferred form:

/*
* On transmit, decrypted asks the device to encrypt the packet.
* Sent to ingress, the packet would read as decrypted by the
* device.
*/

[Severity: Medium]
Is skb_at_tc_ingress() a reliable direction signal for every caller of __bpf_redirect()?

tcf_mirred_act() only checks this inside a tc hook, where tc_at_ingress is always current. But __bpf_redirect() is also reached from LWT xmit programs. lwt_xmit_func_proto() gives those programs bpf_redirect() and bpf_clone_redirect(), and BPF_F_INGRESS is an accepted flag:

ip_finish_output2()
lwtunnel_xmit()
run_lwt_bpf()
skb_do_redirect()
__bpf_redirect(skb, dev, flags)

This runs before __dev_queue_xmit(), the only place on transmit that clears the bit:

net/core/dev.c:__dev_queue_xmit() {
    ...
	tcx_set_ingress(skb, false);
    ...
}

The only place that sets the bit is sch_handle_ingress(), and only when the input device has a tcx/clsact ingress entry. skb_scrub_packet() does not touch it. For a forwarded skb, tc_at_ingress at the LWT xmit hook is whatever the input device left behind.

Here is one way to get a forwarded skb whose decrypted bit means "please encrypt". psp_validate_xmit() accepts any device whose psp_dev matches the association, including dev-assoc veth/netkit devices. A PSP socket in a container can then cross the veth with decrypted=1, and the host-side peer forwards it.

Say the host-side veth has a tc ingress hook. Then tc_at_ingress=1 reaches the LWT xmit hook, and bpf_redirect(X, BPF_F_INGRESS) passes this check. The packet enters X's receive path through __bpf_rx_skb() with decrypted=1.

Without a tc ingress hook on the host-side veth, the same packet and the same program get -EINVAL, and the packet is dropped.

Doesn't that make the result depend on unrelated tc configuration on the input device, rather than on the direction of the hook calling the helper? Neither the comment ("On transmit, ...") nor the commit message ("drop decrypted skbs which bpf redirects from egress to ingress") describes this case.

The socket-less PSP case through act_psp encap on tc egress looks fine, since tc_at_ingress is 0 there. Could the caller pass the direction instead (LWT xmit is always egress), or could the LWT path be handled explicitly?

net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2235

Quoted 2 lines
net/core/filter.c +2 -0
+		kfree_skb(skb);
+		return -EINVAL;

[Severity: Low]
This isn't a bug, but could this use kfree_skb_reason() with a specific drop reason?

kfree_skb() records SKB_DROP_REASON_NOT_SPECIFIED. For bpf_redirect(), the program has already returned TC_ACT_REDIRECT, and the callers of skb_do_redirect() ignore its return value:

net/core/dev.c:sch_handle_egress() {
    ...
		skb_do_redirect(skb);
		*ret = NET_XMIT_SUCCESS;
    ...
}

run_lwt_bpf() and netkit ignore it too. Neither the program nor the sender learns about this new policy drop. In drop_monitor or the kfree_skb tracepoint it looks like any other generic drop.

The matching mirred drop in the previous patch returns TC_ACT_SHOT and is recorded as SKB_DROP_REASON_TC_EGRESS. The series also already defines SKB_DROP_REASON_PSP_OUTPUT for related PSP policy drops.

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#36 lore raw

Re: [PATCH net-next v1 08/15] psp: only give time-wait sockets of psp connections a validator

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] psp_twsk_init() (net/psp/psp_sock.c) now sets tw->tw_validate_xmit_skb = psp_validate_xmit whenever the full socket…

--

psp: only give time-wait sockets of psp connections a validator

This commit changes psp_twsk_init() so that tw_validate_xmit_skb is set only when the full socket has a psp association, not on every tcp time-wait socket. It prepares for the upcoming tc psp action, which treats a socket that has a validator as having its own encryption offload.

Quoted 5 lines
net/psp/psp_sock.c +0 -0
index 609b06c7af65b..664955bfb4fdb 100644

net/psp/psp_sock.c void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk) · line 338

Quoted 10 lines
net/psp/psp_sock.c +5 -1
@@ -330,10 +330,14 @@ void psp_twsk_init(struct inet_timewait_sock *tw, const struct sock *sk)
 {
 	struct psp_assoc *pas = psp_sk_assoc(sk);
 
-	if (pas)
+	if (pas) {
 		refcount_inc(&pas->refcnt);
+		/* Only for PSP connections: a validator makes the socket
+		 * look like it has an encryption offload of its own
+		 */
+		tw->tw_validate_xmit_skb = psp_validate_xmit;

[Severity: High]
Should this also check pas->tx.spi? As written, an Rx-only association (pas->tx.spi == 0) also gets the validator here.

On a full socket, the validator is installed only after a Tx key is set, in psp_sock_set_tx_key():

    WRITE_ONCE(sk->sk_validate_xmit_skb, psp_validate_xmit);

psp_sock_assoc_set_rx() publishes sk->psp_assoc but never sets sk->sk_validate_xmit_skb. A connection that did rx-assoc but never tx-assoc therefore has no validator while it is a full socket. It gains one when it enters TIME_WAIT.

Other places that decide whether a connection is PSP-encrypted test pas && pas->tx.spi. These include psp_reply_set_decrypted() in this same file:

    if (pas && pas->tx.spi)
        skb->decrypted = 1;

and also psp_enqueue_set_decrypted() and psp_sk_overhead() in include/net/psp/functions.h.

With the act_psp patch later in the series, tcf_psp_sk_offload() returns true for a TIME_WAIT socket that has a tw_validate_xmit_skb:

    return sk_is_inet(sk) && sk->sk_state == TCP_TIME_WAIT &&
           inet_twsk(sk)->tw_validate_xmit_skb;

tcf_psp_act() then drops the packet with SKB_DROP_REASON_PSP_OUTPUT. In addition, sk_validate_xmit_skb() in net/core/dev.c drops skbs carrying a PSP metadata dst when the time-wait socket has a validator.

TIME_WAIT replies get skb->sk = tw through skb_set_owner_edemux() from ip_send_unicast_reply() and tcp_v6_send_response(). The resulting sequence looks like this:

psp_sock_assoc_set_rx() sk->psp_assoc set, tx.spi == 0, no validator
connection closes
psp_twsk_init() tw_validate_xmit_skb set since pas != NULL
TW ACK/RST reply, skb->sk = tw
tcf_psp_act() ENCAP

    tcf_psp_sk_offload()        true -> TC_ACT_SHOT

So an egress psp encap rule that covers such a connection encapsulates its packets while the socket is full. Once the socket is in TIME_WAIT, the same rule drops its ACK and RST replies. Is this the inconsistency the commit message describes? It seems to remain for Rx-only associations.

An Rx-only socket has no Tx offload of its own. Documentation/networking/psp.rst lists Tx as plain text in the Rx PSP state.

Would gating on pas && pas->tx.spi, as psp_reply_set_decrypted() does, match the full-socket rule? Copying the validator only when sk->sk_validate_xmit_skb == psp_validate_xmit would be another option.

Quoted 4 lines
net/psp/psp_sock.c +1 -1
+	}
 	rcu_assign_pointer(tw->psp_assoc, pas);
-	tw->tw_validate_xmit_skb = psp_validate_xmit;
 }

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#40 lore raw

Re: [PATCH net-next v1 09/15] net/sched: add act_psp for psp transport mode

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 2

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] ENCAP in tcf_psp_act() relies on two marks staying together:
the METADATA_PSP dst, which requests encryption, and skb->decrypted,…
- [Low] The act_psp.c file header ("In software, egress only: like tunnel mode, encap on ingress is hardware offload only"), the comment in the…
- [Low] The block comment above sk_validate_xmit_skb() in net/core/dev.c still says "If the skb belongs to an HW offloaded socket, apply the…

--

net/sched: add act_psp for psp transport mode

This adds a tc action, act_psp. Its encap mode attaches a PSP Tx association to egress packets as a METADATA_PSP dst and sets skb->decrypted, so the PSP device encrypts them on transmit. Its decap mode removes the PSP Rx state from packets the device decrypted, and sk_validate_xmit_skb() now drops METADATA_PSP packets whose socket has its own validator.

Quoted 5 lines
net/core/dev.c +0 -0
index 2cca5f0d302f8..353c0409b3c03 100644
@@ -4154,13 +4154,22 @@ static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,

[ ... ]

net/core/dev.c static struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb, · line 4172

Quoted 12 lines
net/core/dev.c +10 -1
 	if (sk_validate) {
-		skb = sk_validate(sk, dev, skb);
+		/* act_psp doesn't give an association to the packets of a
+		 * socket with its own offload, but the socket can gain one
+		 * while such a packet is queued
+		 */
+		if (unlikely(skb_psp_md(skb))) {
+			kfree_skb_reason(skb, SKB_DROP_REASON_PSP_OUTPUT);
+			skb = NULL;
+		} else {
+			skb = sk_validate(sk, dev, skb);
+		}

[Severity: Low]
This isn't a bug, but the block comment above sk_validate_xmit_skb() still says:

/* Validate an skb for device encryption offload. If the skb belongs to an HW
* offloaded socket, apply the socket's callback. Otherwise, an skb which
* carries a PSP association is checked again against dev: ...

With this new branch, an skb whose socket has a validator and which also carries a METADATA_PSP dst is freed with SKB_DROP_REASON_PSP_OUTPUT. The socket's callback never runs for it.

Should the function comment be updated to cover this case?

[ ... ]

Quoted 5 lines
net/sched/act_psp.c new file +0 -0
new file mode 100644
index 0000000000000..4ff54203c9f51

[ ... ]

Quoted 3 lines
net/sched/act_psp.c new file +3 -0
+static int tcf_psp_act(struct sk_buff *skb, const struct tc_action *a,
+		       struct tcf_result *res)
+{

[ ... ]

net/sched/act_psp.c line 130

Quoted 9 lines
net/sched/act_psp.c new file +9 -0
+	switch (params->psp_action) {
+	case TCA_PSP_ACT_ENCAP:
+		/* Encap on ingress is hardware offload only, like tunnel
+		 * mode: the packet would go through the stack with nothing
+		 * but its dst, which routing, netfilter or a redirect may
+		 * replace, to keep it from leaving in clear text
+		 */
+		if (unlikely(skb_at_tc_ingress(skb)))
+			return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);

[Severity: Low]
Is there a hardware offload path for this action?

This comment, the file header ("In software, egress only: like tunnel mode, encap on ingress is hardware offload only"), the commit message and Documentation/networking/psp.rst all say ingress encap is available through hardware offload.

act_psp_ops doesn't set .offload_act_setup, so tc_setup_offload_act() rejects the action:

net/sched/cls_api.c:tc_setup_offload_act() {
	if (act->ops->offload_act_setup) {
		return act->ops->offload_act_setup(act, entry, index_inc, true,
						   extack);
	} else {
		NL_SET_ERR_MSG(extack, "Action does not support offload");
		return -EOPNOTSUPP;
	}
}

include/net/flow_offload.h has no PSP flow_action_id either. The PSP tunnel mode that "like tunnel mode" refers to isn't in the tree yet; the commit message says a later series adds it.

So skip_sw rules are rejected. Software rules install without error, because tcf_psp_init() has no direction check, and then every matching ingress packet is dropped with SKB_DROP_REASON_PSP_OUTPUT.

Could the comments, commit message and psp.rst say that ingress encap is not supported, rather than hardware offload only?

Quoted 3 lines
net/sched/act_psp.c new file +3 -0
+		/* PSP on a tunnel isn't supported: the encap would overwrite
+		 * the inner headers which the device's tunnel offloads use
+		 */

[ ... ]

net/sched/act_psp.c line 149

Quoted 6 lines
net/sched/act_psp.c new file +6 -0
+		skb_dst_drop(skb);
+		skb_dst_set(skb, dst_clone(&params->md->dst));
+		/* Must be encrypted: sk_validate_xmit_skb() drops it unless
+		 * it still carries the association when it is transmitted
+		 */
+		skb->decrypted = 1;

[Severity: Medium]
Can the METADATA_PSP dst and skb->decrypted get separated after this point?

The commit message relies on skb->decrypted as the backstop: "on egress, encap sets skb->decrypted, so that sk_validate_xmit_skb() drops the packet if it loses the METADATA_PSP dst on the way". The egress to ingress guards in mirred and bpf also check only the decrypted bit:

net/sched/act_mirred.c:tcf_mirred_to_dev() {
	if (unlikely(want_ingress && !at_ingress && skb_is_decrypted(skb)))
		goto err_cant_do;
}

ip_copy_metadata() copies the dst but not the decrypted bit, so fragments built by ip_do_fragment() end up with decrypted == 0:

net/ipv4/ip_output.c:ip_copy_metadata() {
	...
	skb_dst_drop(to);
	skb_dst_copy(to, from);
	...
	skb_ext_copy(to, from);
	...
}

One path where this happens, on a non-PSP netdev's clsact egress:

act_ct (defrag, sets tc_skb_cb(skb)->mru)
-> psp encap (the reassembled packet is not a fragment, so it is accepted) -> mirred egress redirect to the PSP netdev

tcf_dev_queue_xmit()
sch_frag_xmit_hook()

    sch_fragment()
      ip_do_fragment(net, skb->sk, skb, sch_frag_xmit)

sch_frag_xmit() then puts the original dst back on each fragment:

	__skb_dst_copy(skb, data->dst);

As a result, every fragment carries the association but has decrypted == 0.

In the direct case the PSP driver drops the fragments. Suppose a later step on the target's egress replaces the dst, for example tunnel_key set plus a redirect to a tunnel device. sk_validate_xmit_skb() then sees neither the md dst nor the decrypted mark, and the packet goes out in clear text. A redirect to ingress would also pass the skb_is_decrypted() check above.

The TCA_PSP_ACT_DECAP branch below can split the two marks as well. It clears skb->decrypted whenever SKB_EXT_PSP is present, without checking for an attached METADATA_PSP dst.

Would it make sense to do one or more of the following?

- also test skb_psp_md() in the mirred/bpf guards and in the cleartext backstop
- propagate decrypted in ip_copy_metadata() and ip6_copy_metadata()
- have decap refuse packets that carry a METADATA_PSP dst

Quoted 12 lines
net/sched/act_psp.c new file +12 -0
+		break;
+	case TCA_PSP_ACT_DECAP:
+		/* Only a packet the device decrypted: on transmit,
+		 * skb->decrypted means "device, please encrypt", which decap
+		 * must not undo.
+		 */
+		if (!skb_ext_find(skb, SKB_EXT_PSP))
+			break;
+		skb_ext_del(skb, SKB_EXT_PSP);
+		skb->decrypted = 0;
+		break;
+	}

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#44 lore raw

Re: [PATCH net-next v1 10/15] net/sched: flower: add psp_spi, psp_ver, and psp_dev matches

In reply to Todd Freed
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 0

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] The commit message misstates what a PSP flower rule matches once two key rotations have passed, and it overstates its claim that…

--

net/sched: flower: add psp_spi, psp_ver, and psp_dev matches

This adds a flow dissector key that is filled from the SKB_EXT_PSP Rx state of decrypted packets. It also adds flower matches on the SPI (with a mask), the PSP version and the PSP device ID. The goal is to let a tc rule select the packets of a single Rx association, for example to apply psp decap.

Quoted 4 lines
net/core/flow_dissector.c +0 -0
index 1be6c739e3c71..95d3fa3b1568e 100644

[ ... ]

Quoted 16 lines
net/core/flow_dissector.c +12 -0
@@ -511,6 +512,32 @@ void skb_flow_dissect_hash(const struct sk_buff *skb,
 }
 EXPORT_SYMBOL(skb_flow_dissect_hash);
 
+void skb_flow_dissect_psp(const struct sk_buff *skb,
+			  struct flow_dissector *flow_dissector,
+			  void *target_container)
+{
+#if IS_ENABLED(CONFIG_INET_PSP)
+	struct flow_dissector_key_psp *key;
+	struct psp_skb_ext *pse;
+
+	if (!dissector_uses_key(flow_dissector, FLOW_DISSECTOR_KEY_PSP))
+		return;
+
+	pse = skb_ext_find(skb, SKB_EXT_PSP);

net/core/flow_dissector.c void skb_flow_dissect_hash(const struct sk_buff *skb, · line 536

Quoted 10 lines
net/core/flow_dissector.c +10 -0
+	if (!pse)
+		return;
+
+	key = skb_flow_dissector_target(flow_dissector,
+					FLOW_DISSECTOR_KEY_PSP,
+					target_container);
+	key->spi = pse->spi;
+	key->dev_id = pse->dev_id;
+	key->version = pse->version;
+	key->present = 1;

[Severity: Medium]
Does the commit message describe the right failure mode for rules that are still installed after two key rotations?

The commit message says:

Together these matches tie a rule to one association, ...

and:

this means that a rule matching packets that correspond to an rx association which is stale (two rotations have passed), can still match.

After two rotations the device key for the original association is gone. Its packets then fail to decrypt and never get SKB_EXT_PSP, so the stale association itself can no longer match.

The SPI value can be handed out again, though. In netdevsim, for example:

drivers/net/netdevsim/psp.c:nsim_key_rotate() {
    ...
	if (ns->psp.spi & PSP_SPI_KEY_PHASE)
		ns->psp.spi = 0;
	else
		ns->psp.spi = PSP_SPI_KEY_PHASE;
    ...
}

and nsim_rx_spi_alloc() then does:

	assoc->spi = cpu_to_be32(++ns->psp.spi);

So a new rx-spi-alloc, possibly for a different peer, can get 0x80000001 again. skb_flow_dissect_psp() only copies spi, dev_id and version. Given that, wouldn't the example rule from the commit message:

psp_spi 0x80000001 psp_ver 0 psp_dev 1 action psp decap

strip PSP state from the traffic of a different, live association? With a mirred action instead of decap, it would forward that traffic.

The socket path avoids this because psp_pse_matches_pas() also compares the generation:

	return pse && pas->rx.spi == pse->spi &&
	       pas->generation == pse->generation &&
	       pas->version == pse->version &&
	       pas->dev_id == pse->dev_id;

Adding generation to the key would not fully fix this either. The mlx5 Rx path always passes generation = 0 to psp_dev_rcv(). So it looks like (spi, version, dev) cannot identify a single association beyond two rotations on any driver.

The "Socket-less associations" text that a later patch in this series adds to Documentation/networking/psp.rst has the same gap. It only says userspace should replace such rules before two rotations, and it repeats that the matches tie a decap rule to one Rx association. No later patch in the series adds a generation match or any enforcement.

Could the commit message and the documentation say that a stale rule can end up matching a different association that reused the SPI, rather than the stale association itself?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#52 lore raw

Re: [PATCH net-next v1 13/15] selftests: tc-testing: run dependsOn probes outside the test namespace

In reply to Todd Freed
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…

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 patch fixes a real regression but has no Fixes: tag.
- [Low] run_one_test() now passes a new stage string, 'probe', to every plugin's adjust_command(stage, command) hook.

--

selftests: tc-testing: run dependsOn probes outside the test namespace

This changes run_one_test() in tdc.py so the dependsOn probe is passed to exec_cmd() with a new 'probe' stage instead of 'execute'. With that stage, nsPlugin does not put "ip netns exec" in front of the probe, so the probe runs in the base namespace and the probe-gated tests are no longer always skipped.

tools/testing/selftests/tc-testing/tdc.py def run_one_test(pm, args, index, tidx): · line 402

Quoted 10 lines
tools/testing/selftests/tc-testing/tdc.py +1 -1
index 511d66c36a2a0..541caf984519f 100755
@@ -399,7 +399,7 @@ def run_one_test(pm, args, index, tidx):
     if 'dependsOn' in tidx:
         if (args.verbose > 0):
             print('probe command for test skip')
-        (p, procout) = exec_cmd(tidx, args, pm, 'execute', tidx['dependsOn'])
+        (p, procout) = exec_cmd(tidx, args, pm, 'probe', tidx['dependsOn'])

[Severity: Low]

Should this patch have a Fixes: tag?

The probe block came from commit 7f3f86402609 ("selftests: tc-testing: add "depends_on" property to skip tests"). At that time nsPlugin used one shared netns that was created ahead of time, so the probe worked.

Commit 98cfbe4234a4 ("selftests/tc-testing: localize test resources") moved tests to per-test tcut-<random> namespaces. It also wrote the 'execute' stage call shown above. In run_one_test(), the probe still runs before the per-test suffix is added:

    NAMES['NS'] = '{}-{}'.format(NAMES['NS'], tidx['random'])

It also runs before pm.call_pre_case() creates the namespace. As a result, nsPlugin's adjust_command() wraps the probe in a netns exec for the bare "tcut" name, and no namespace with that name is ever created.

Because of this, the mirred dependsOn probes added later in dcfaf1f758ee ("selftests/tc-testing: require an up to date iproute2 for blockcast tests") could never pass.

Would this tag fit?

Fixes 98cfbe4234a4 ("selftests/tc-testing: localize test resources")

[Severity: Low]

This passes a new stage string, 'probe', to the adjust_command() hook of every plugin. Should the in-tree docs list it?

The stage list in tools/testing/selftests/tc-testing/README reads:

The stages are identified by the following strings:

- pre (pre-suite)
- setup
- command
- verify
- teardown
- post (post-suite)

creating-plugins/AddingPlugins.txt also leaves 'probe' out of both its phase list and its "The stages are represented by the following strings" list. The commented stage-dispatch template in TdcPlugin.adjust_command() has no 'probe' branch either.

The dependsOn description in creating-testcases/AddingTestCases.txt only says:

dependsOn: Same as 'skip', but the value is executed as a command. The test
is skipped when the command returns non-zero.

Probes now run in the base namespace, outside the test netns. A future dependsOn command that uses per-test devices such as $DEV0, $DEV1 or $DUMMY would fail, and its test would just be skipped. Could this be noted in the dependsOn description?

The fix also depends on plugins passing unknown stages through unchanged. nsPlugin and valgrindPlugin both do that today.

The existing lists were already out of date ('command' rather than 'execute'). The missing 'probe' entry and the base-namespace behaviour of dependsOn are new with this patch.

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#55 lore raw

Re: [PATCH net-next v1 14/15] selftests: tc-testing: add tests for the psp action

In reply to Todd Freed
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…

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] Tests 2d50 ("Add psp action without encap or decap"), cab5 ("Add psp encap action without assoc, with index") and 0c17 ("Reject psp…
- [Low] Tests a744 ("Add flower psp_spi filter with psp decap") and 4e1f ("Add flower psp_spi, psp_ver and psp_dev filter with psp decap") in…

--

selftests: tc-testing: add tests for the psp action

This adds tdc tests for the psp tc action. They add, replace, delete and flush decap actions, and check that invalid encap/decap configurations are rejected. It also adds flower filter tests for psp_spi, psp_ver and psp_dev, and enables CONFIG_INET_PSP and CONFIG_NET_ACT_PSP in the tc-testing config.

Quoted 6 lines
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +0 -0
new file mode 100644
index 0000000000000..990e8bd1ce9a0
@@ -0,0 +1,459 @@

[ ... ]

Quoted 3 lines
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +3 -0
+    {
+        "id": "2d50",
+        "name": "Add psp action without encap or decap",

[ ... ]

tools/testing/selftests/tc-testing/tc-tests/actions/psp.json line 226

Quoted 5 lines
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +5 -0
+        "cmdUnderTest": "$TC actions add action psp index 12",
+        "expExitCode": "255",
+        "verifyCmd": "$TC actions list action psp",
+        "matchPattern": "action order [0-9]+: psp",
+        "matchCount": "0",

[Severity: Low]
Does this test reach the kernel check it is named after?

The test passes if the command exits with 255 and no psp action is listed afterwards. tc actions add also exits with 255 when tc's own parser refuses the arguments, before any netlink request is sent. In iproute2, tc_action_modify() returns -1 for a parse_action() failure and for an rtnl_talk() failure alike.

If the psp parser in tc requires encap or decap, this test would pass without ever reaching this check:

net/sched/act_psp.c:tcf_psp_init() {
    ...
	if (NL_REQ_ATTR_CHECK(extack, nla, tb, TCA_PSP_ACTION)) {
		NL_SET_ERR_MSG(extack, "Missing PSP action, encap or decap");
    ...
}

The same question applies to two other tests:

- cab5 ("Add psp encap action without assoc, with index") and the "Missing PSP association ID" check in the encap case.
- 0c17 ("Reject psp decap action with an assoc") and the "decap takes no PSP association" check in the decap case.

In each case the test would still pass if the kernel branch were removed.

The flower tests b58d and 2f96 avoid this by expecting exit code 2. tc filter add returns 2 only on an rtnl_talk() error and returns 1 on a parse failure. The action tests have no such check.

Would it make sense to match the extack text instead? For example, a verifyCmd could rerun the command with stderr captured and grep for the kernel message.

[ ... ]

Quoted 3 lines
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +3 -0
+    {
+        "id": "a744",
+        "name": "Add flower psp_spi filter with psp decap",

[ ... ]

Quoted 1 line

+ "dependsOn": "$TC filter add flower help 2>&1 | grep -q psp_spi",

[ ... ]

tools/testing/selftests/tc-testing/tc-tests/actions/psp.json

Quoted 2 lines
tools/testing/selftests/tc-testing/tc-tests/actions/psp.json new file +2 -0
+        "cmdUnderTest": "$TC filter add dev $DEV1 ingress protocol ip pref 1 flower psp_spi 0x1234 action psp decap",
+        "expExitCode": "0",

[Severity: Low]
Should this dependsOn also check for the psp action?

The command uses "action psp decap", but the probe only checks that flower knows psp_spi. The action tests earlier in this file probe for the action like this:

$TC actions add action psp help 2>&1 | grep -q decap

run_one_test() in tdc.py uses only the probe's return code to decide whether to skip a test. Suppose tc has the flower psp_* keys but not the psp action. This test would then run instead of being skipped. tc would fall back to its noact parser, reject the action, and the test would be reported as a failure.

The commit message says:

The tests need a tc with the psp action and the flower psp_* keys; they skip without it (dependsOn).

Test 4e1f ("Add flower psp_spi, psp_ver and psp_dev filter with psp decap") has the same issue.

Could both probes be chained with && for these two tests?

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#58 lore raw

Re: [PATCH net-next v1 15/15] Documentation: networking: psp: document socket-less associations

In reply to Todd Freed
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…

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 new psp.rst text says, in the psp encap assoc ID bullet, "Encap on ingress is hardware offload only." The header comment of…
- [Low] In psp.rst, the psp encap assoc ID bullet says: "If the association is removed before transmit, or if the packet is…
- [Low] In the flower paragraph, psp.rst says the psp_spi, psp_ver and psp_dev matches together "tie a decap rule to one Rx…

--

Documentation: networking: psp: document socket-less associations

This commit reorganizes the PSP documentation around associations. It documents the new netlink commands for socket-less associations, the psp tc action and the flower psp_spi, psp_ver and psp_dev matches. It also adds sections on fragments and on PSP device statistics.

Quoted 4 lines
Documentation/networking/psp.rst +0 -0
index 0f9b6b73f2447..79b101db5dfc4 100644

[ ... ]

Quoted 7 lines
Documentation/networking/psp.rst +3 -0
@@ -140,6 +162,55 @@ The PSP assoc state of a socket is not reset when the connection is
 torn down. ``connect()`` on a socket that has PSP assoc state will
 return ``-EINVAL``.
 
+Socket-less associations
+~~~~~~~~~~~~~~~~~~~~~~~~
+

[ ... ]

Quoted 4 lines

+- ``assoc-del`` deletes an association. tc actions and packets which still

Documentation/networking/psp.rst +3 -0
+  reference it keep it alive. The device keeps decrypting the SPI of a
+  deleted Rx association until its device key is rotated out: remove the
+  decap rule to stop taking its packets.

[ ... ]

Documentation/networking/psp.rst The PSP assoc state of a socket is not reset when the connection is · line 192

Quoted 6 lines

+- ``psp encap assoc ID`` attaches a Tx association. The packet must then

Documentation/networking/psp.rst +5 -0
+  be transmitted on the main netdev of the association's PSP device, which
+  encrypts it (``mirred egress redirect``). If the association is removed
+  before transmit, or if the packet is transmitted on any other device,
+  it will be dropped, rather than sent in the clear. Encap on ingress is
+  hardware offload only.

[Severity: Low]
Is the part that says "If the association is removed before transmit ... it will be dropped" accurate? It conflicts with the assoc-del bullet above and with the assoc-del doc in Documentation/netlink/specs/psp.yaml:

Packets and tc actions which still reference it keep it alive.

In the code, psp_nl_assoc_del_doit() only calls psp_assoc_unpublish(). That removes the ID from the registry and drops the registry's reference:

net/psp/psp_assoc.c:psp_assoc_unpublish() {
    ...
	if (xa_cmpxchg(&psp_assocs, pas->id, pas, NULL, 0) == pas)
		psp_assoc_put(pas);
    ...
}

The METADATA_PSP dst created by tcf_psp_md_create() keeps its own reference. tcf_psp_act() also keeps attaching dst_clone(&params->md->dst) to every packet.

On transmit, psp_xmit_md() checks only the device and the MTU. It never checks whether the association was deleted:

include/net/psp/functions.h:psp_xmit_md() {
    ...
	if (rcu_access_pointer(dev->psp_dev) != pas->psd ||
	    dev != pas->psd->main_netdev)
		return -EINVAL;
    ...
}

So after assoc-del, packets are still encrypted and sent with the deleted association's key until the tc action is removed. A drop seems to happen only when the packet loses its METADATA_PSP dst, or when the PSP device does not match or has been unregistered.

Would "if the packet loses its association on the way (e.g. its dst is replaced)" describe this more accurately?

[Severity: Low]
Is "Encap on ingress is hardware offload only" accurate for this series? act_psp_ops in net/sched/act_psp.c does not set .offload_act_setup:

static struct tc_action_ops act_psp_ops = {
	.kind		=	"psp",
	.id		=	TCA_ID_PSP,
	.owner		=	THIS_MODULE,
	.act		=	tcf_psp_act,
	.dump		=	tcf_psp_dump,
	.init		=	tcf_psp_init,
	.cleanup	=	tcf_psp_cleanup,
	.size		=	sizeof(struct tcf_psp),
};

Because of that, tc_setup_offload_act() in net/sched/cls_api.c rejects the action:

	} else {
		NL_SET_ERR_MSG(extack, "Action does not support offload");
		return -EOPNOTSUPP;
	}

In software, tcf_psp_act() always drops encap at ingress:

		if (unlikely(skb_at_tc_ingress(skb)))
			return tcf_psp_drop(p, skb, SKB_DROP_REASON_PSP_OUTPUT);

So ingress encap cannot work in any configuration today. The flower commit in this series says offload will come in a follow-up series.

Should this say that ingress encap is not supported (the packet is always dropped) and that hardware offload is future work? The header comment in net/sched/act_psp.c makes the same claim.

[ ... ]

Documentation/networking/psp.rst The PSP assoc state of a socket is not reset when the connection is · line 207

Quoted 9 lines
Documentation/networking/psp.rst +9 -0
+The flower classifier matches what a packet was decrypted with:
+``psp_spi SPI[/MASK]``, ``psp_ver VERSION`` and ``psp_dev DEV_ID``, the
+ID of the PSP device which decrypted it. These never match a clear text
+packet, so ``psp_spi 0/0`` matches any packet decrypted with PSP.
+Together they tie a decap rule to one Rx association.
+
+Once the device key an SPI was created from has been rotated twice, that
+association is considered stale. Unlike sockets, tc does not handle key
+rotation. userspace should replace such rules before two rotations.

[Severity: Low]
Does "Together they tie a decap rule to one Rx association" overstate what the match guarantees? The flow key built by skb_flow_dissect_psp() carries only these fields:

	key->spi = pse->spi;
	key->dev_id = pse->dev_id;
	key->version = pse->version;
	key->present = 1;

It has no key generation and no association identity. SPI values get reused after key rotation. For example, nsim_key_rotate() in netdevsim resets the SPI counter:

	if (ns->psp.spi & PSP_SPI_KEY_PHASE)
		ns->psp.spi = 0;
	else
		ns->psp.spi = PSP_SPI_KEY_PHASE;

After two rotations, the same SPI can be given to a different peer or to a socket association under a new key. If the old decap rule is still in place, it would strip SKB_EXT_PSP and skb->decrypted from that other association's packets and forward them.

PSP device IDs are also allocated cyclically in a 16-bit space in psp_dev_create():

	err = xa_alloc_cyclic(&psp_devs, &psd->id, psd, xa_limit_16b,
			      &last_id, GFP_KERNEL);

After enough unregister/register cycles, a stale psp_dev match could end up matching a different device.

The next paragraph says userspace should replace rules before two rotations. It does not say that a stale rule will match other associations' traffic, and it does not mention device ID reuse.

The flower commit in this series says "the generation of the device key is not checked". Could the doc include the same qualification here?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261111005533.6436-1-toddfreed%40meta.com
#37 lore raw

Re: [PATCH net-next v1 08/15] psp: only give time-wait sockets of psp connections a validator

In reply to [email protected]
Quoted 3 lines

[Severity: High]
Should this also check pas->tx.spi? As written, an Rx-only association (pas->tx.spi == 0) also gets the validator here.

This patch has been re-posted to net, as patch 3 in the series "net: don't redirect decrypted skbs to ingress, psp time-wait validator".

It is now checking pas->tx.spi, as suggested here.

-Todd

#6 lore raw

Re: [PATCH net-next v1 02/15] psp: take the psp nexthdr from the packet on encap

In reply to [email protected]
Quoted 10 lines

[Severity: Medium]

psp_dev_encapsulate() now accepts non-TCP packets. Is the outer UDP source port selection in psp_write_headers() still correct when skb->sk is a UDP socket?

...

Should the sk->sk_hash path be limited to TCP sockets, with other sockets falling back to udp_flow_src_port()?

Yep. v2 will only use sk_hash for TCP.

pw-bot: cr

-Todd

#17 lore raw

Re: [PATCH net-next v1 04/15] psp: add support for socket-less psp associations

In reply to [email protected]
Quoted 8 lines
Quoted 3 lines

key material enters through netlink and is never reported back. no key is stored for rx associations, and users reference associations by id and never handle keys

[Severity: Medium]
Is this paragraph accurate? The code in this patch seems to do the opposite in two places.

Quoted 8 lines

...

So user space does handle keys, and rx-spi-alloc does report key material back.

Could the commit message describe that more precisely? For example:
"the Rx key is returned once, by rx-spi-alloc, and is never stored or reported by assoc-get".

Yes. In v2 it will say the Rx key is returned from rx-spi-alloc, but not stored. In v2 rx-spi-alloc won't create an association at all.

-Todd

#21 lore raw

Re: [PATCH net-next v1 05/15] net: add METADATA_PSP dst to carry a psp association on an skb

In reply to [email protected]
Quoted 12 lines

[Severity: Medium]

The commit message says this re-check handles the case where "the psp device may have been unregistered while the packet was queued, and its keys deleted". Does that still hold for skbs that get requeued?

...

Can this hand the NIC the id of a DEK that has already been destroyed, and that may have been reused for another association? psp_xmit_md() would catch the psd mismatch, but it never runs again for this skb.

Quoted 5 lines

...

The socket path through psp_validate_xmit() was already exposed in the same way before this patch. The new METADATA_PSP path, however, depends on this re-check to handle the unregister case.

This is true, the checks do not handle skbs that get requeued.

As noted, packets of a psp socket have the same gap today with psp_validate_xmit().
I'll send a separate Fix to net that covers both. v2 will narrow the commit message
and mention this gap explicitly.

-Todd

#28 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

In reply to [email protected]
Quoted 9 lines

[Severity: Medium]
Is skb_at_tc_ingress() a reliable direction signal for every caller of __bpf_redirect()?

tcf_mirred_act() only checks this inside a tc hook, where tc_at_ingress is always current. But __bpf_redirect() is also reached from LWT xmit programs. lwt_xmit_func_proto() gives those programs bpf_redirect() and bpf_clone_redirect(), and BPF_F_INGRESS is an accepted flag:

Quoted 4 lines

...

Without a tc ingress hook on the host-side veth, the same packet and the same program get -EINVAL, and the packet is dropped.

Real finding.

This patch was re-posted as a Fix to net as patch2 in the series "net: don't redirect decrypted skbs to ingress, psp time-wait validator". This path is addressed there by calling tcx_set_ingress(false) in bpf_xmit().

-Todd

#41 lore raw

Re: [PATCH net-next v1 09/15] net/sched: add act_psp for psp transport mode

In reply to [email protected]
Quoted 20 lines

[Severity: Medium]
Can the METADATA_PSP dst and skb->decrypted get separated after this point?

The commit message relies on skb->decrypted as the backstop: "on egress, encap sets skb->decrypted, so that sk_validate_xmit_skb() drops the packet if it loses the METADATA_PSP dst on the way". The egress to ingress guards in mirred and bpf also check only the decrypted bit:

One path where this happens, on a non-PSP netdev's clsact egress:

act_ct (defrag, sets tc_skb_cb(skb)->mru)
-> psp encap (the reassembled packet is not a fragment, so it is accepted) -> mirred egress redirect to the PSP netdev

tcf_dev_queue_xmit()
sch_frag_xmit_hook()

    sch_fragment()
      ip_do_fragment(net, skb->sk, skb, sch_frag_xmit)
Quoted 6 lines

sch_frag_xmit() then puts the original dst back on each fragment:

        __skb_dst_copy(skb, data->dst);

As a result, every fragment carries the association but has decrypted == 0.

The fragment path is handled by "net: don't fragment decrypted skbs" in the net series,

https://lore.kernel.org/netdev/[email protected]

This causes the skbs to simply be dropped instead of being fragmented.

Quoted 3 lines

Would it make sense to do one or more of the following?

- propagate decrypted in ip_copy_metadata() and ip6_copy_metadata()

Conceptually it makes sense. But because of the fix above, that would be dead code. Furthermore, they still couldn't be sent. skbs which are to be encrypted on tx (ktls, psp) need the L4 header, and non-initial fragments do not have it.

Quoted 4 lines

- also test skb_psp_md() in the mirred/bpf guards and in the cleartext backstop

- have decap refuse packets that carry a METADATA_PSP dst

In both cases, these guards would be dead code.There's no way for these to happen once the fragment path is closed.

-Todd

#45 lore raw

Re: [PATCH net-next v1 10/15] net/sched: flower: add psp_spi, psp_ver, and psp_dev matches

In reply to [email protected]
Quoted 19 lines

[Severity: Medium]
Does the commit message describe the right failure mode for rules that are still installed after two key rotations?

The commit message says:

Together these matches tie a rule to one association, ...

and:

this means that a rule matching packets that correspond to an rx association which is stale (two rotations have passed), can still match.

The "Socket-less associations" text that a later patch in this series adds to Documentation/networking/psp.rst has the same gap. It only says userspace should replace such rules before two rotations, and it repeats that the matches tie a decap rule to one Rx association. No later patch in the series adds a generation match or any enforcement.

Quoted 3 lines

Could the commit message and the documentation say that a stale rule can end up matching a different association that reused the SPI, rather than the stale association itself?

In v2, there are no Rx associations. It will be more clear that matches tie a rule to a SPI not to an association. And the reliance on userspace to replace rules before that SPI could be re-used, will be further highlighted.

-Todd

maintainer
#29 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

In reply to Todd Freed
Quoted 31 lines · Todd Freed

on transmit, skb->decrypted means the device must encrypt the packet. For example, a packet of a ktls or psp offload socket, or, with the tc psp action added later in this series, one which psp encap attached a tx association to.

on receive, skb->decrypted means the device decrypted the packet.

bpf_redirect() and bpf_clone_redirect() with BPF_F_INGRESS send the packet to a device's receive path with the bit still set, where it indicates the packet was decrypted by the device.

this is less of a problem with socket offloads, whose packets are by definition generated locally; more of a problem with socket-less psp, which can also apply to forwarded traffic.

in addition, the redirect drops the dst (skb_scrub_packet()), which for socket-less psp carries the tx association.

drop decrypted skbs which bpf redirects from egress to ingress. this matches the behavior of mirred, since the previous patch.

---
  net/core/filter.c | 9 +++++++++
  1 file changed, 9 insertions(+)
net/core/filter.c +0 -0
index aca8160b26a1..a178a9dd3007 100644

net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2235

Quoted 10 lines
net/core/filter.c +7 -0
@@ -2226,6 +2226,15 @@ static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev,
  static int __bpf_redirect(struct sk_buff *skb, struct net_device *dev,
  			  u32 flags)
  {
+	/* On transmit, decrypted asks the device to encrypt the packet. Sent
+	 * to ingress, the packet would read as decrypted by the device.
+	 */
+	if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
+		     skb_is_decrypted(skb))) {
+		kfree_skb(skb);
+		return -EINVAL;

This check should rather live in the bpf_redirect (and friends) helper e.g. after we check for invalid params, etc, rather than here which feels off. Also, it would probably make sense to refactor this condition into a small inline helper so you don't have to open code it multiple times.

Quoted 5 lines
net/core/filter.c +2 -0
+	}
+
  	if (dev_is_mac_header_xmit(dev))
  		return __bpf_redirect_common(skb, dev, flags);
  	else
#30 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

Quoted 8 lines

net/core/filter.c static int __bpf_redirect_common(struct sk_buff *skb, struct net_device *dev, · line 2235

Quoted 7 lines
net/core/filter.c +7 -0
+     /* On transmit, decrypted asks the device to encrypt the packet. Sent
+      * to ingress, the packet would read as decrypted by the device.
+      */
+     if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
+                  skb_is_decrypted(skb))) {
+             kfree_skb(skb);
+             return -EINVAL;
Quoted 4 lines

This check should rather live in the bpf_redirect (and friends) helper e.g. after we check for invalid params, etc, rather than here which feels off. Also, it would probably make sense to refactor this condition into a small inline helper so you don't have to open code it multiple times.

Sounds good I will move this check into the two callers (bpf_clone_redirect() and
skb_do_redirect()) under a helper.

FYI this patch was moved to the net series "net: don't redirect decrypted skbs to
ingress, psp time-wait validator", so you will see this applied to v3 there.

-Todd

maintainer
#31 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

Quoted 8 lines · Todd Bert Freed
Quoted 8 lines
Quoted 7 lines
(quoted diff) +7 -0
+     /* On transmit, decrypted asks the device to encrypt the packet. Sent
+      * to ingress, the packet would read as decrypted by the device.
+      */
+     if (unlikely((flags & BPF_F_INGRESS) && !skb_at_tc_ingress(skb) &&
+                  skb_is_decrypted(skb))) {
+             kfree_skb(skb);
+             return -EINVAL;
Quoted 8 lines
Quoted 4 lines

This check should rather live in the bpf_redirect (and friends) helper e.g. after we check for invalid params, etc, rather than here which feels off. Also, it would probably make sense to refactor this condition into a small inline helper so you don't have to open code it multiple times.

Sounds good I will move this check into the two callers (bpf_clone_redirect() and
skb_do_redirect()) under a helper.

But why under skb_do_redirect? I meant just here:

net/core/filter.c +4 -0
index 532405988fd9..ba112111de22 100644
@@ -2471,6 +2471,8 @@ BPF_CALL_3(bpf_clone_redirect, struct sk_buff *, skb, u32, ifindex, u64, flags)
 
        if (unlikely(flags & (~(BPF_F_INGRESS) | BPF_F_REDIRECT_INTERNAL)))
                return -EINVAL;
+       if (...cond...)
+               return -EOPNOTSUPP;
 
        /* BPF test infra's convert___skb_to_skb() can create type-less
         * GSO packets. gso_features_check() will detect this as a bad
@@ -2563,6 +2565,8 @@ BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags)
        if (unlikely(!bpf_net_ctx_get() ||
                     (flags & (~(BPF_F_INGRESS) | BPF_F_REDIRECT_INTERNAL))))
                return TC_ACT_SHOT;
+       if (...cond...)
+               return TC_ACT_SHOT;
 
        ri = bpf_net_ctx_get_ri();
        ri->flags = flags;
Quoted 5 lines

FYI this patch was moved to the net series "net: don't redirect decrypted skbs to
ingress, psp time-wait validator", so you will see this applied to v3 there.

-Todd

#32 lore raw

Re: [PATCH net-next v1 07/15] bpf: don't redirect decrypted skbs from egress to ingress

net/core/filter.c BPF_CALL_3(bpf_clone_redirect, struct sk_buff *, skb, u32, ifindex, u64, flags) · line 2475

Quoted 12 lines

But why under skb_do_redirect? I meant just here:

net/core/filter.c +2 -0
index 532405988fd9..ba112111de22 100644
@@ -2471,6 +2471,8 @@ BPF_CALL_3(bpf_clone_redirect, struct sk_buff *, skb, u32, ifindex, u64, flags)
 
         if (unlikely(flags & (~(BPF_F_INGRESS) | BPF_F_REDIRECT_INTERNAL)))
                 return -EINVAL;
+       if (...cond...)
+               return -EOPNOTSUPP;

Yep we are on the same page for this one.

net/core/filter.c BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags) · line 2569

Quoted 8 lines
net/core/filter.c +2 -0
         /* BPF test infra's convert___skb_to_skb() can create type-less
          * GSO packets. gso_features_check() will detect this as a bad
@@ -2563,6 +2565,8 @@ BPF_CALL_2(bpf_redirect, u32, ifindex, u64, flags)
         if (unlikely(!bpf_net_ctx_get() ||
                      (flags & (~(BPF_F_INGRESS) | BPF_F_REDIRECT_INTERNAL))))
                 return TC_ACT_SHOT;
+       if (...cond...)
+               return TC_ACT_SHOT;

bpf_redirect() does not see the skb, so it can't check skb->decrypted. After the program has returned TC_ACT_REDIRECT and skb_do_redirect() is called, is the earliest point at which the policy can be enforced.

-Todd