psp, tls: don't send offloaded contents in cleartext
Subsystems (10)
v6 cover psp, tls: don't send offloaded contents in cleartext
While working on adding support for socket-less psp associations, I noticed the case of ipv6 extension headers was not being handled properly for psp packets. It will be relevant with that series, because it adds udp support, for which the inner packet needs to be inspected to set the psp nexthdr.
That led me to various other ways the encryption offload path could transmit packets unencrypted.
Since the psp/tls association encodes intent to send encrypted packets, but these various cases circumvent that, sending these as fixes.
The cases are,
1/ ipv6 extension headers (patch 2; patch 1 makes mlx5e flush its tx
queue when the resulting drop happens),
2/ fragments (patch 3),
3/ icmp errors (patch 4),
4/ icmpv6 errors (patch 5),
Cases 2, 3 and 4 are relevant for ktls as well as psp.
patch 8 fixes an mlx5e bug in tso checksum calculation for psp packets when the l3 dest is an intermediate hop (ipv4 source routing). It's not about preventing unencrypted tx, so could be considered separate.
netfilter refragments bridged packets and builds reject replies itself, outside these paths. A separate nf-next series applies the same rules there.
Testing:
hardware testing was done on connectx-7 (fw 28.48), between two x86 hosts, plus netdevsim.
- drivers/net psp.py: on netdevsim, all 36 tests pass. on mlx5, 40 pass, 4 skip (gmac versions the device doesn't support), and 2 xfail (netdevsim only). the gmac variants of data_basic_send_netkit_psp_assoc fail: that test doesn't skip versions the device doesn't support, which is fixed separately.
- drivers/net/hw tls_hw_offload.py on mlx5: all 8 tests pass.
- tso checksum seed: a psp tcp socket with an ipv4 loose source route, the peer checking tcp checksums in software. hundreds of checksum errors before the fix, none after.
- fragments, with tls offload and psp:
- ipv4 (route mtu above the device mtu, IP_PMTUDISC_OMIT): without the fix, some fragments after the first go out in cleartext. with it they're dropped.
- ipv6, through an ipvs dr service with a local client: without the fix, fragments after the first go out in cleartext, and the peer reassembles them. with it they're dropped.
- icmp and icmpv6 errors, on netdevsim psp, with an nft reject rule (icmpx port-unreachable) in the inet family:
- in an input chain, of received decrypted packets: without the fix, the errors go out on the wire, quoting the decrypted packets. with it, no error reaches the wire.
- in an output chain, of a psp socket's packets: the error is delivered to the local socket, with and without the fix.
- a PKT_TOOBIG from ip6_fragment() about a psp socket's packets is delivered to the socket, with and without the fix.
v6:
- patches 4 and 5 - since "net: Make PSP skb extension survive packet scrubbing", some of the comments on patches 4 and 5 no longer make sense (psp skb and ktls skb can now be reliably distinguished). the behavior from v5 is retained, the rationale has been updated.
- patches 4 and 5 - clarified which reject rules go through icmp_send() and icmp6_send(), so that it's more obvious how the nf-next series applies (Sashiko)
- patch 5 - icmpv6: explain why the check of a locally originated skb comes after the rate limit (Sashiko)
- patch 6 - remove the socket option and close the connection in separate try blocks, and don't overstate the variants (Sashiko)
- patch 7 - use ctl_file_write() to turn off tcp_mtu_probing, including 1 (Sashiko)
- Cc: stable on the fixes (patches 1-5 and 8)
- rebase on net/main
v5: https://lore.kernel.org/netdev/[email protected]
- new patch 1: mlx5e rings the tx doorbell when an accel offload drops a packet, and checks the stop room after the nop it posts (Sashiko)
- ipv6 extension headers: drop them in psp_dev_encapsulate() again, instead of in mlx5e. it's the helper which can't encapsulate them, for every driver (netdevsim sent them malformed). unlike the routing header rejection in v2, this isn't a device limitation
- don't fragment decrypted skbs in ip6_fragment() either
- icmp and icmpv6: send no error at all about a received decrypted skb, instead of quoting up to the tcp header for tls offload
- icmpv6: decide whether an error about a locally originated skb goes to a local address from the error's route (RTF_LOCAL), like icmp (RTCF_LOCAL), instead of the address list (Sashiko)
- selftests: the extension header test runs on netdevsim too, and removes the socket option before closing. the fragment test uses the source address of the route, and turns off tcp_mtu_probing
v4: https://lore.kernel.org/netdev/[email protected]
- back to dropping ipv6 packets with extension headers, but moved into mlx5e instead of psp_dev_encapsulate()
- drop the psp core changes to rx and tx ipv6 extension headers
- new patch 2 to drop decrypted skbs instead of fragmenting
- new patches 3 and 4 to prevent quoting just-decrypted packet contents in icmp errors, v4 and v6 respectively (Jakub, Bjorn, Sashiko)
- new selftest: ipv4 fragments of a psp tcp socket
v3: https://lore.kernel.org/netdev/[email protected]
- new patch 1 to fix tso checksum seed calculation in mlx5e (Daniel)
- accept routing headers and reject ah (Daniel)
- split the psp_dev_rcv() change into its own patch (Daniel)
- return -EINVAL instead of -1 (Daniel)
- selftest: one variant per extension header type (Daniel)
v2: https://lore.kernel.org/netdev/[email protected]
- walk the extension headers instead of dropping (Daniel)
- reject fragment headers (Bjorn, Daniel)
- reject routing headers
- psp_dev_rcv() handle the rx case as well
v1: https://lore.kernel.org/netdev/[email protected]
Todd Freed (8):
net/mlx5e: ring the tx doorbell when an accel offload drops a packet
psp: don't encapsulate ipv6 packets with extension headers
net: don't fragment decrypted skbs
ipv4: icmp: don't quote decrypted payload in icmp errors
ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
selftests: drv-net: psp: test ipv6 tcp socket with extension headers
selftests: drv-net: psp: test that ipv4 psp packets aren't fragmented net/mlx5e: psp: tso: replace only the length in checksum seed
.../mellanox/mlx5/core/en_accel/psp_rxtx.c | 21 +- .../net/ethernet/mellanox/mlx5/core/en_tx.c | 8 +- net/ipv4/icmp.c | 12 + net/ipv4/ip_output.c | 8 + net/ipv6/icmp.c | 18 ++ net/ipv6/ip6_output.c | 9 + net/psp/psp_main.c | 21 +- tools/testing/selftests/drivers/net/config | 1 + tools/testing/selftests/drivers/net/psp.py | 245 +++++++++++++++++- 9 files changed, 324 insertions(+), 19 deletions(-)
base-commit: 5e9b2ad9b8384cd3c417cd5e2c3bc7eee4a72791
Signature · 1 line
2.53.1-Meta
PATCH v6 1/8 net/mlx5e: ring the tx doorbell when an accel offload drops a packet
when mlx5e_accel_tx_begin() drops the skb, e.g. because psp can't encapsulate it, mlx5e_xmit() returns without posting anything. the skbs before it in a bulk dequeue may have been posted with xmit_more, which defers the doorbell to the next one, and an mpwqe session may be open. the device then doesn't see them until the next transmit on that sq, and since the queue isn't stopped, the tx watchdog doesn't fire.
flush the sq on this drop like the dma error paths do: close the mpwqe session, post a nop and ring the doorbell.
mlx5e_tx_flush() doesn't check whether the nop leaves less than stop_room in the sq. for the dma error paths that is rare, but a run of offload drops would post nops without stopping the queue, and could overrun wqes in flight. so check it in mlx5e_tx_flush(), like the other producers do. the completion of the nop wakes the queue again.
the next patch makes the psp drop reachable from user space, with an ipv6 extension header set on a psp socket.
--- drivers/net/ethernet/mellanox/mlx5/core/en_tx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +7 -1
@@ -365,6 +365,7 @@ static void mlx5e_tx_flush(struct mlx5e_txqsq *sq) }; wqe =mlx5e_post_nop (&sq->wq, sq->sqn, &sq->pc); +mlx5e_tx_check_stop (sq);mlx5e_notify_hw (&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); }
@@ -672,8 +673,13 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev) }/* May send SKBs and WQEs. */ -if (unlikely (!mlx5e_accel_tx_begin (dev, sq, skb, &accel))) +if (unlikely (!mlx5e_accel_tx_begin (dev, sq, skb, &accel))) { +/* The skb was dropped: ring the doorbell which the previous +* ones may have deferred to it +*/ +mlx5e_tx_flush (sq);return NETDEV_TX_OK ; + }mlx5e_sq_xmit_prepare (sq, skb, &accel, &attr);
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 1/8] net/mlx5e: ring the tx doorbell when an accel offload drops a packet
Sashiko has reviewed this patch and found no issues.
Quoted 16 lines
when
mlx5e_accel_tx_begin()drops the skb, e.g. because psp can't encapsulate it,mlx5e_xmit()returns without posting anything. the skbs before it in a bulk dequeue may have been posted withxmit_more, which defers the doorbell to the next one, and an mpwqe session may be open. the device then doesn't see them until the next transmit on that sq, and since the queue isn't stopped, the tx watchdog doesn't fire.flush the sq on this drop like the dma error paths do: close the mpwqe session, post a nop and ring the doorbell.
mlx5e_tx_flush()doesn't check whether the nop leaves less thanstop_roomin the sq. for the dma error paths that is rare, but a run of offload drops would post nops without stopping the queue, and could overrun wqes in flight. so check it inmlx5e_tx_flush(), like the other producers do. the completion of the nop wakes the queue again.
Quoted 6 lines
the next patch makes the psp drop reachable from user space, with an ipv6 extension header set on a psp socket.
Fixes 2ac9cfe78223 ("net/mlx5e: IPSec, Add Innova IPSec offload TX data path")Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH net v6 1/8] net/mlx5e: ring the tx doorbell when an accel offload drops a packet
In reply to Todd FreedQuoted 16 lines · Todd Freed
when
mlx5e_accel_tx_begin()drops the skb, e.g. because psp can't encapsulate it,mlx5e_xmit()returns without posting anything. the skbs before it in a bulk dequeue may have been posted withxmit_more, which defers the doorbell to the next one, and an mpwqe session may be open. the device then doesn't see them until the next transmit on that sq, and since the queue isn't stopped, the tx watchdog doesn't fire.flush the sq on this drop like the dma error paths do: close the mpwqe session, post a nop and ring the doorbell.
mlx5e_tx_flush()doesn't check whether the nop leaves less thanstop_roomin the sq. for the dma error paths that is rare, but a run of offload drops would post nops without stopping the queue, and could overrun wqes in flight. so check it inmlx5e_tx_flush(), like the other producers do. the completion of the nop wakes the queue again.
Quoted 6 lines
the next patch makes the psp drop reachable from user space, with an ipv6 extension header set on a psp socket.
Fixes 2ac9cfe78223 ("net/mlx5e: IPSec, Add Innova IPSec offload TX data path")Signed-off-by Todd Freed <[email protected]>
LGTM. Couldn't find any side effects besides the additonal NOP + db dance which is ok.
Thanks,
Dragos
[email protected]
AI reviewRe: [PATCH net v6 1/8] net/mlx5e: ring the tx doorbell when an accel offload drops a packet
In reply to Todd FreedThank 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 mlx5e_tx_check_stop() call in mlx5e_tx_flush() (drivers/net/ethernet/mellanox/mlx5/core/en_tx.c:368) can count one…
--
net/mlx5e: ring the tx doorbell when an accel offload drops a packet
When mlx5e_accel_tx_begin() drops an skb, this patch makes mlx5e_xmit() call mlx5e_tx_flush(). That closes any open mpwqe session, posts a nop and rings the doorbell that earlier xmit_more skbs had deferred. It also adds a stop_room check to mlx5e_tx_flush() after the nop is posted.
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c static void mlx5e_tx_flush(struct mlx5e_txqsq *sq) · line 368
Quoted 9 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +1
-0@@ -365,6 +365,7 @@ static void mlx5e_tx_flush(struct mlx5e_txqsq *sq) }; wqe =mlx5e_post_nop (&sq->wq, sq->sqn, &sq->pc); +mlx5e_tx_check_stop (sq);
[Severity: Low]
Can this count a single queue stop twice in sq->stats->stopped?
mlx5e_tx_flush() starts with mlx5e_tx_mpwqe_ensure_complete(). If an MPWQE session is open, that goes into mlx5e_tx_mpwqe_session_complete(), which already runs a stop check:
mlx5e_tx_mpwqe_session_complete() {
...
sq->pc += wi->num_wqebbs;
session->wqe = NULL;
mlx5e_tx_check_stop(sq);
...
}If closing the session leaves less than sq->stop_room free, the queue is stopped and stopped is incremented. The nop then advances sq->pc by one more, so free room has only gone down, and the new check also fails. mlx5e_tx_check_stop() does not test whether the queue is already stopped:
mlx5e_tx_check_stop() {
if (unlikely(!mlx5e_wqc_has_room_for(&sq->wq, sq->cc, sq->pc, sq->stop_room))) {
netif_tx_stop_queue(sq->txq);
sq->stats->stopped++;
}
}When the nop completes, mlx5e_txqsq_wake() wakes the queue once and increments wake once. That leaves stopped one higher than wake. These counters are reported as the qstats tx stop/wake values and as tx_queue_stopped/tx_queue_wake in ethtool.
This can be reached from the new accel drop path below. It can also now be reached from the existing DMA error paths in mlx5e_sq_xmit_mpwqe() and mlx5e_sq_xmit_wqe(), since they call the same helper.
The PTP path in mlx5e_txwqe_complete() already avoids this:
if (!netif_tx_queue_stopped(sq->txq) &&
mlx5e_ptpsq_metadata_freelist_empty(sq->ptpsq)) {
netif_tx_stop_queue(sq->txq);
sq->stats->stopped++;
}Would a similar netif_tx_queue_stopped() guard work here?
Only the statistics are affected. The queue still wakes when the nop completes, and no packets are lost. The normal mlx5e_xmit() path can already skew these counters the same way, through mlx5e_tx_mpwqe_ensure_complete() followed by mlx5e_txwqe_complete(). Later patches in the series do not touch en_tx.c, so this is still present at the end of the series.
Quoted 5 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +0
-0mlx5e_notify_hw (&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); }@@ -672,8 +673,13 @@ netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev) }
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev) · line 682
Quoted 10 lines
drivers/net/ethernet/mellanox/mlx5/core/en_tx.c +6
-1/* May send SKBs and WQEs. */ -if (unlikely (!mlx5e_accel_tx_begin (dev, sq, skb, &accel))) +if (unlikely (!mlx5e_accel_tx_begin (dev, sq, skb, &accel))) { +/* The skb was dropped: ring the doorbell which the previous +* ones may have deferred to it +*/ +mlx5e_tx_flush (sq);return NETDEV_TX_OK ; + }
This is the new caller that reaches the double count above. It needs a PSP, IPsec, MACsec or kTLS drop while an MPWQE session is open and the SQ is close to full. The commit message says the next patch makes the PSP drop reachable from user space.
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117203137.804424-1-toddfreed%40meta.com
PATCH v6 2/8 psp: don't encapsulate ipv6 packets with extension headers
In reply to Todd Freedpsp_dev_encapsulate() inserts the udp+psp headers at the transport header, rewrites the protocol of the fixed ip header to udp, and writes tcp as the psp next header. so tcp must directly follow the fixed header.
if the packet is an ipv6 packet with extension headers, udp+psp is placed after them, but the next header indicating the l4 protocol is on the last extension header in the chain, not in the fixed header. therefore this produces a malformed packet.
in addition to being malformed, with mlx5 this kind of packet goes out unencrypted. since the tx association encodes intent to send encrypted packets, drop such packets instead.
a psp tcp socket emits such packets if certain socket options are set on it (e.g. IPV6_DSTOPTS). refusing the combination of such socket options with psp association would be helpful but is not implemented here. since extension headers can also come from a route the datapath check is needed anyway.
the check also covers ipv4: the l4 protocol must be tcp, and the transport header must follow the ip header and its options. packets of a psp tcp socket always pass it.
--- net/psp/psp_main.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
net/psp/psp_main.c +19 -2
@@ -245,6 +245,24 @@ static void psp_write_headers(struct net *net, struct sk_buff *skb, __be32 spi,memset (&psph->iv,0 ,sizeof (psph->iv)); } +/* UDP+PSP goes in at the transport header, the protocol of the fixed IP +* header becomes UDP, and TCP the PSP next header: TCP must directly follow +* the fixed header. It doesn't with IPv6 extension headers, whose last one +* holds the L4 protocol. +*/ +static bool psp_dev_encap_ok (const struct sk_buff *skb) +{ +u32 network_len =skb_network_header_len (skb); + +if (skb->protocol ==htons (ETH_P_IP )) +return ip_hdr (skb)->protocol ==IPPROTO_TCP && + network_len ==ip_hdrlen (skb); +if (skb->protocol ==htons (ETH_P_IPV6 )) +return ipv6_hdr (skb)->nexthdr ==IPPROTO_TCP && + network_len ==sizeof (struct ipv6hdr ); +return false; +} +/* Encapsulate a TCP packet with PSP by adding the UDP+PSP headers and filling * them in. */
@@ -255,8 +273,7 @@ bool psp_dev_encapsulate(struct net *net, struct sk_buff *skb, __be32 spi,u32 ethr_len =skb_mac_header_len (skb);u32 bufflen = ethr_len + network_len; -if (skb->protocol !=htons (ETH_P_IP ) && - skb->protocol !=htons (ETH_P_IPV6 )) +if (!psp_dev_encap_ok (skb))return false;if (skb_cow_head (skb,PSP_ENCAP_HLEN ))
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 2/8] psp: don't encapsulate ipv6 packets with extension headers
Sashiko has reviewed this patch and found no issues.
Quoted 20 lines
psp_dev_encapsulate()inserts the udp+psp headers at the transport header, rewrites the protocol of the fixed ip header to udp, and writes tcp as the psp next header. so tcp must directly follow the fixed header.if the packet is an ipv6 packet with extension headers, udp+psp is placed after them, but the next header indicating the l4 protocol is on the last extension header in the chain, not in the fixed header. therefore this produces a malformed packet.
in addition to being malformed, with mlx5 this kind of packet goes out unencrypted. since the tx association encodes intent to send encrypted packets, drop such packets instead.
a psp tcp socket emits such packets if certain socket options are set on it (e.g.
IPV6_DSTOPTS). refusing the combination of such socket options with psp association would be helpful but is not implemented here. since extension headers can also come from a route the datapath check is needed anyway.
Quoted 7 lines
the check also covers ipv4: the l4 protocol must be tcp, and the transport header must follow the ip header and its options. packets of a psp tcp socket always pass it.
Fixes fc724515741a ("psp: provide encapsulation helper for drivers")Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v6 3/8 net: don't fragment decrypted skbs
In reply to Todd Freedon transmit, skb->decrypted means the device must encrypt the skb. if it can't do that, then the packet should be dropped, not transmitted in the clear.
ip_do_fragment() and ip6_fragment() on a decrypted skb produce fragments which have skb->decrypted unset, and can be sent out unencrypted.
tx of individually encrypted fragments would not work anyway, because encrypting needs the L4 header, which non-initial fragments do not have.
ktls could encrypt in sw before fragmenting. that would not work for psp offload which does not have a software fallback path.
tcp sizes segments to the mtu, so psp and ktls socket packets normally won't reach this path. an ipv4 tcp socket can be made to send fragments by setting a route mtu above the device mtu and disabling pmtud on the socket (IP_PMTUDISC_OMIT). the selftest later in the series does this.
emitting fragments from an ipv6 tcp socket requires more steps, but is also possible. the test setup here uses ipvs, which sets ignore_df on forwarded packets. in ip6_fragment(), check skb->decrypted after the too-big checks, so that a local socket still gets PKT_TOOBIG for path mtu discovery.
tested with tls tx offload on mlx5 (connectx-7), over ipv4. without this patch some fragments after the first go out in cleartext, with it they're dropped (IpFragFails) and the connection stalls.
tested over ipv6, with tls tx offload and psp on mlx5 (connectx-7), through an ipvs dr service with a local client. without this patch, fragments after the first go out in cleartext, and the peer reassembles them; with it they're dropped (Ip6FragFails).
--- net/ipv4/ip_output.c | 8 ++++++++ net/ipv6/ip6_output.c | 9 +++++++++ 2 files changed, 17 insertions(+)
net/ipv4/ip_output.c +8 -0
@@ -770,6 +770,14 @@ int ip_do_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,struct ip_frag_state state;int err =0 ; +/* PSP and TLS offload need the packet's L4 header, which non-initial +* fragments do not have. +*/ +if (unlikely (skb_is_decrypted (skb))) { + err = -EMSGSIZE ; + goto fail; + } +/* for offloaded checksums cleanup checksum before fragmentation */ if (skb->ip_summed ==CHECKSUM_PARTIAL ) { err =ip_check_csum_start (skb);
net/ipv6/ip6_output.c +9 -0
@@ -929,6 +929,15 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, mtu =IPV6_MIN_MTU ; } +/* PSP and TLS offload need the packet's L4 header, which non-initial +* fragments do not have. Checked after the too-big checks above, +* so that PMTUD for a local socket works. +*/ +if (unlikely (skb_is_decrypted (skb))) { + err = -EMSGSIZE ; + goto fail; + } +if (np) {u32 frag_size =READ_ONCE (np->frag_size);
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 3/8] net: don't fragment decrypted skbs
Sashiko has reviewed this patch and found no issues.
Quoted 14 lines
on transmit,
skb->decryptedmeans the device must encrypt the skb. if it can't do that, then the packet should be dropped, not transmitted in the clear.
ip_do_fragment()andip6_fragment()on a decrypted skb produce fragments which haveskb->decryptedunset, and can be sent out unencrypted.tx of individually encrypted fragments would not work anyway, because encrypting needs the L4 header, which non-initial fragments do not have.
ktls could encrypt in sw before fragmenting. that would not work for psp offload which does not have a software fallback path.
Quoted 7 lines
tcp sizes segments to the mtu, so psp and ktls socket packets normally [ ... ]
Fixes e8f69799810c ("net/tls: Add generic NIC offload infrastructure")Fixes 659a2899a57d ("tcp: add datapath logic for PSP with inline key exchange")Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
[email protected]
AI reviewRe: [PATCH net v6 3/8] net: don't fragment decrypted skbs
In reply to Todd FreedThank 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] In ip6_fragment() (net/ipv6/ip6_output.c), the new skb_is_decrypted() refusal at lines 932-939 runs before the…
--
net: don't fragment decrypted skbs
This patch makes ip_do_fragment() and ip6_fragment() refuse to fragment skbs that have skb->decrypted set. Without it, the resulting fragments can be sent out in cleartext. In ip6_fragment() the new check sits after the existing too-big checks so that PMTUD for a local socket keeps working.
[ ... ]
Quoted 9 lines
net/ipv6/ip6_output.c +1
-0@@ -929,6 +929,15 @@ int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, mtu =IPV6_MIN_MTU ; } +/* PSP and TLS offload need the packet's L4 header, which non-initial
net/ipv6/ip6_output.c int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb, · line 942
Quoted 10 lines
net/ipv6/ip6_output.c +8
-0+* fragments do not have. Checked after the too-big checks above, +* so that PMTUD for a local socket works. +*/ +if (unlikely (skb_is_decrypted (skb))) { + err = -EMSGSIZE ; + goto fail; + } +if (np) {u32 frag_size =READ_ONCE (np->frag_size);
[Severity: Low]
This isn't a bug, but the commit message says:
in ip6_fragment(), check skb->decrypted after the too-big checks, so that a local socket still gets PKT_TOOBIG for path mtu discovery.
ip6_fragment() has one more too-big check after the np->frag_size clamp, and the new check now runs before it:
if (mtu < hlen + sizeof(struct frag_hdr) + 8) goto fail_toobig;
A decrypted skb that would have reached this check is now dropped with -EMSGSIZE, and no ICMPV6_PKT_TOOBIG is sent.
At this point mtu is at least IPV6_MIN_MTU. So the bypassed check only fires with about 1265 bytes or more of unfragmentable extension headers, and the packet is dropped in either case. The code comment says "the too-big checks above", which is accurate.
Could the commit message say that the check comes after the ignore_df and frag_max_size too-big checks, so that it matches the code?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117203137.804424-1-toddfreed%40meta.com
PATCH v6 4/8 ipv4: icmp: don't quote decrypted payload in icmp errors
In reply to Todd Freedan icmp error quotes as much of the invoking packet as fits in 576 bytes. if the device had decrypted the packet (as indicated by skb->decrypted) then the icmp error is sending part of it back out onto the network in cleartext.
the two offloads encrypt different parts of the packet:
- ktls encrypts the tcp payload. the tcp header is in the clear on the wire, so a quote of the ip header and the tcp header, without the payload, would be fine.
- psp encryption also covers the tcp header. the quote could include just the ip header, but then that's not really useful. linux receivers want to look at the l4 layer on the quoted packet to look up the related flow, so such a truncated icmp error packet is just dropped (icmp_socket_deliver()).
a decrypted psp skb carries SKB_EXT_PSP, so the two could be told apart, and an error about a ktls skb could still quote up to the tcp header. but then whether the tcp header of a psp packet goes out in cleartext would depend on the extension not being lost anywhere between the device and here, while skb->decrypted is what the device itself set. so don't send an error about a received decrypted skb at all.
on tx, skb->decrypted is also set. an error about a locally originated skb (skb_iif is 0) is sent in full as before, if it is routed to a local address (RTCF_LOCAL on the route to the packet's source address).
iptables REJECT, and nft reject in the ip and inet families, send their icmp error with icmp_send(), through nf_send_unreach(). so now, a received packet which the device decrypted, and which hits such a reject rule in the INPUT or FORWARD chain, is dropped without a reply, like a drop rule. nft reject in the netdev and bridge families builds its own error (nf_reject_skb_v4_unreach()); a separate nf-next patch applies the same rule there.
packets which weren't decrypted are rejected as before, and so are locally originated ones in the OUTPUT chain, if the error goes to a local address as above.
the next patch does the same for icmpv6.
--- net/ipv4/icmp.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
net/ipv4/icmp.c +12 -0
@@ -979,6 +979,18 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,if (rt->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) goto ende; +/* Don't send parts of a decrypted skb onto the network. A received skb +* was decrypted by the device, and the transport header may have been +* encrypted. The different offloads can't be distinguished in all cases +* so simply don't send the error. +* +* A locally originated skb to be encrypted may be quoted if its source +* address (target of the error) is local. +*/ +if (unlikely (skb_is_decrypted (skb_in)) && + (skb_in->skb_iif || !(rt->rt_flags &RTCF_LOCAL ))) + goto ende; +/* peer icmp_ratelimit */ if (!icmpv4_xrlim_allow (net, rt, &fl4, type, code, apply_ratelimit)) goto ende;
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 4/8] ipv4: icmp: don't quote decrypted payload in icmp errors
Sashiko has reviewed this patch and found no issues.
Quoted 15 lines
an icmp error quotes as much of the invoking packet as fits in 576 bytes. if the device had decrypted the packet (as indicated by
skb->decrypted) then the icmp error is sending part of it back out onto the network in cleartext.the two offloads encrypt different parts of the packet:
- ktls encrypts the tcp payload. the tcp header is in the clear on the wire, so a quote of the ip header and the tcp header, without the payload, would be fine.
- psp encryption also covers the tcp header. the quote could include just the ip header, but then that's not really useful. linux receivers want to look at the l4 layer on the quoted packet to look up the related flow, so such a truncated icmp error packet is just dropped
Quoted 6 lines
[ ... ]Suggested-by Jakub Kicinski <[email protected]>Suggested-by Björn Töpel <[email protected]>Fixes 784abe24c903 ("net: Add decrypted field to skb")Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
[email protected]
AI reviewRe: [PATCH net v6 4/8] ipv4: icmp: don't quote decrypted payload in icmp errors
In reply to Todd FreedThank 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 patch blocks decrypted-payload quoting only in __icmp_send() (net/ipv4/icmp.c).
--
ipv4: icmp: don't quote decrypted payload in icmp errors
This patch makes __icmp_send() skip the error when the invoking skb was decrypted by the device. Locally originated skbs are the exception: if the error is routed to a local address, it is still sent. The netdev and bridge nft reject paths are left to a separate nf-next patch.
Quoted 9 lines
net/ipv4/icmp.c +1
-0@@ -979,6 +979,18 @@ void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info,if (rt->rt_flags & (RTCF_BROADCAST |RTCF_MULTICAST )) goto ende; +/* Don't send parts of a decrypted skb onto the network. A received skb
net/ipv4/icmp.c void __icmp_send(struct sk_buff *skb_in, int type, int code, __be32 info, · line 992
Quoted 10 lines
net/ipv4/icmp.c +10
-0+* was decrypted by the device, and the transport header may have been +* encrypted. The different offloads can't be distinguished in all cases +* so simply don't send the error. +* +* A locally originated skb to be encrypted may be quoted if its source +* address (target of the error) is local. +*/ +if (unlikely (skb_is_decrypted (skb_in)) && + (skb_in->skb_iif || !(rt->rt_flags &RTCF_LOCAL ))) + goto ende;
[Severity: Medium]
This check only covers ICMP errors sent through icmp_send(). Can a decrypted payload still be quoted in cleartext by the other IPv4 unreachable builder?
nf_reject_skb_v4_unreach() in net/ipv4/netfilter/nf_reject_ipv4.c is unchanged by this series and has no skb_is_decrypted() check:
net/ipv4/netfilter/nf_reject_ipv4.c:nf_reject_skb_v4_unreach() {
...
len = min_t(unsigned int, 536, oldskb->len);
...
nskb = alloc_skb(sizeof(struct iphdr) + sizeof(struct icmphdr) +
LL_MAX_HEADER + len, GFP_ATOMIC);
...
skb_put_data(nskb, skb_network_header(oldskb), len);
...
}It is called from nft_reject_netdev_send_v4_unreach() and nft_reject_br_send_v4_unreach(). The nskb comes from a fresh alloc_skb(), so its decrypted bit is 0, and it goes out through dev_queue_xmit() or br_forward().
With a netdev or bridge family reject rule matching device-decrypted traffic, this would still send up to about 508 bytes of kTLS payload, or the PSP-covered TCP header and payload, unencrypted.
nf_reject_skb_v6_unreach() in net/ipv6/netfilter/nf_reject_ipv6.c has the same gap, with a quote of up to 1220 bytes. The icmp6_send() side is handled by the later "ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors" patch in this series.
The commit message says:
nft reject in the netdev and bridge families builds its own error (nf_reject_skb_v4_unreach()); a separate nf-next patch applies the same rule there.
This patch carries Fixes: 784abe24c903 and Cc: stable. A stable backport would then make an inet family reject of a decrypted packet send nothing. A netdev or bridge family reject of the same packet would still send plaintext.
Should the netfilter builders be fixed in this same series, or through nf/net with the same Fixes: and Cc: stable tags, rather than nf-next?
Quoted 4 lines
net/ipv4/icmp.c +1
-0+/* peer icmp_ratelimit */ if (!icmpv4_xrlim_allow (net, rt, &fl4, type, code, apply_ratelimit)) goto ende;
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117203137.804424-1-toddfreed%40meta.com
Re: [PATCH net v6 4/8] ipv4: icmp: don't quote decrypted payload in icmp errors
Quoted 11 lines
[Severity: Medium]
This check only covers ICMP errors sent throughicmp_send(). Can a decrypted payload still be quoted in cleartext by the other IPv4 unreachable builder?The commit message says:
nft reject in the netdev and bridge families builds its own error (
nf_reject_skb_v4_unreach()); a separate nf-next patch applies the same rule there.
Quoted 7 lines
This patch carries Fixes:
784abe24c903and Cc: stable. A stable backport would then make an inet family reject of a decrypted packet send nothing. A netdev or bridge family reject of the same packet would still send plaintext.Should the netfilter builders be fixed in this same series, or through nf/net with the same Fixes: and Cc: stable tags, rather than nf-next?
The nf-next series in question,
https://lore.kernel.org/netfilter-devel/[email protected]
1/2 netfilter: bridge: don't refragment decrypted skbs" (dd5e0f8aebca) 2/2 netfilter: reject: don't reply to decrypted skbs" (01538dbd6b9b)
patch 2/2 reproduces on net/main. I believe the precedent then would be to send it to nf (not nf-next).
patch 1/2 does not reproduce on net/main. And it no longer reproduces with the net-next series, "psp: introduce socket-less psp associations". I will drop that one.
-Todd
PATCH v6 5/8 ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
In reply to Todd Freedan icmpv6 error quotes as much of the invoking packet as fits in the minimum ipv6 mtu. if the device had decrypted the packet (as indicated by skb->decrypted) then the icmpv6 error is sending part of it back out onto the network in cleartext.
as in the previous patch for icmp, don't send an error about a received decrypted skb at all: psp also encrypts the l4 header, and telling it apart from ktls rx device offload would rely on SKB_EXT_PSP not being lost on the way. linux receivers would drop an error whose quote stops before the l4 header anyway (icmpv6_notify()). this covers ip6tables REJECT and nft reject in the ip6 and inet families; the netdev and bridge families are left to the nf-next patch, as for icmp.
on tx, skb->decrypted is also set. an error about a locally originated skb (skb_iif is 0) is sent in full as before, if its route goes to a local address (RTF_LOCAL), like RTCF_LOCAL in the previous patch.
an error about a received decrypted skb is dropped before the rate limit, so that it doesn't use up the peer's and the global icmpv6 credit. the check of a locally originated skb needs the route of the error, which is looked up after the rate limit.
--- net/ipv6/icmp.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
net/ipv6/icmp.c +18 -0
@@ -778,6 +778,15 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, np =inet6_sk (sk); +/* Don't send parts of a decrypted skb onto the network, see +* __icmp_send(): no error about a received skb. Before the rate +* limit, so that such an error costs no credit. The check of a +* locally originated skb below needs the route of the error, which +* is looked up after the rate limit. +*/ +if (unlikely (skb_is_decrypted (skb) && skb->skb_iif)) + goto out_unlock; +if (!icmpv6_xrlim_allow (sk, type, &fl6, apply_ratelimit)) goto out_unlock;
@@ -799,6 +808,15 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info,if (IS_ERR (dst)) goto out_unlock; +/* An error about a locally originated decrypted skb is sent only if +* it is routed to a local address. +*/ +if (unlikely (skb_is_decrypted (skb)) && + !(dst_rt6_info (dst)->rt6i_flags &RTF_LOCAL )) { +dst_release (dst); + goto out_unlock; + } + ipc6.hlimit =ip6_sk_dst_hoplimit (np, &fl6, dst); msg.skb = skb;
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 5/8] ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
Sashiko has reviewed this patch and found no issues.
Quoted 22 lines
an icmpv6 error quotes as much of the invoking packet as fits in the minimum ipv6 mtu. if the device had decrypted the packet (as indicated by
skb->decrypted) then the icmpv6 error is sending part of it back out onto the network in cleartext.as in the previous patch for icmp, don't send an error about a received decrypted skb at all: psp also encrypts the l4 header, and telling it apart from ktls rx device offload would rely on
SKB_EXT_PSPnot being lost on the way. linux receivers would drop an error whose quote stops before the l4 header anyway (icmpv6_notify()). this covers ip6tables REJECT and nft reject in the ip6 and inet families; the netdev and bridge families are left to the nf-next patch, as for icmp.on tx,
skb->decryptedis also set. an error about a locally originated skb (skb_iifis 0) is sent in full as before, if its route goes to a local address (RTF_LOCAL), likeRTCF_LOCALin the previous patch.an error about a received decrypted skb is dropped before the rate limit, so that it doesn't use up the peer's and the global icmpv6 credit. the check of a locally originated skb needs the route of the error, which is looked up after the rate limit.
Quoted 7 lines
Reported-by Sashiko <[email protected]>Closes https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261023234640.1459291-1-toddfreed%40meta.comSuggested-by Jakub Kicinski <[email protected]>Suggested-by Björn Töpel <[email protected]>Fixes 784abe24c903 ("net: Add decrypted field to skb")Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
[email protected]
AI reviewRe: [PATCH net v6 5/8] ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
In reply to Todd FreedThank 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] The fix is incomplete on IPv6.
--
ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
This commit stops icmp6_send() from sending an error about a received skb that the device has decrypted (skb->decrypted). An error about a locally originated decrypted skb is still sent, but only if its route goes to a local address (RTF_LOCAL). This follows the earlier IPv4 patch for __icmp_send().
Quoted 7 lines
net/ipv6/icmp.c +0
-0@@ -778,6 +778,15 @@ void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, np =inet6_sk (sk);
net/ipv6/icmp.c void icmp6_send(struct sk_buff *skb, u8 type, u8 code, __u32 info, · line 789
Quoted 10 lines
net/ipv6/icmp.c +9
-0+/* Don't send parts of a decrypted skb onto the network, see +* __icmp_send(): no error about a received skb. Before the rate +* limit, so that such an error costs no credit. The check of a +* locally originated skb below needs the route of the error, which +* is looked up after the rate limit. +*/ +if (unlikely (skb_is_decrypted (skb) && skb->skb_iif)) + goto out_unlock; +
[Severity: High]
Does this cover the NDISC Redirect sent from ip6_forward()? That path also quotes the invoking packet, but it never goes through icmp6_send():
net/ipv6/ip6_output.c:ip6_forward() {
...
if (IP6CB(skb)->iif == dev->ifindex &&
opt->srcrt == 0 && !skb_sec_path(skb)) {
...
if (peer && inet_peer_xrlim_allow(peer, 1*HZ))
ndisc_send_redirect(skb, target);
...
}None of these conditions look at skb->decrypted. ndisc_send_redirect() then copies up to about 1200 bytes of the original packet into a new skb from ndisc_alloc_skb(), and that skb is not marked decrypted:
net/ipv6/ndisc.c:ndisc_send_redirect() {
...
rd_len = min_t(unsigned int,
IPV6_MIN_MTU - sizeof(struct ipv6hdr) - sizeof(*msg) - optlen,
skb->len + 8);
...
if (rd_len)
ndisc_fill_redirect_hdr_option(buff, skb, rd_len);
skb_dst_set(buff, dst);
ndisc_send_skb(buff, &ipv6_hdr(skb)->saddr, &saddr_buf);
...
}ndisc_fill_redirect_hdr_option() calls skb_copy_bits() starting at the network header of the original skb. The decrypted L3/L4/payload bytes would then go out in cleartext inside the Redirected Header option.
sk_validate_xmit_skb() drops the forwarded packet itself ("unencrypted skb with no associated socket"). That leaves the redirect as the only way this plaintext gets out of the host.
On IPv4, the call chain ip_forward()->ip_rt_send_redirect()->icmp_send()-> __icmp_send() reaches the check from the previous patch, because skb_iif is set. The commit message says:
as in the previous patch for icmp, don't send an error about a received decrypted skb at all
For redirects, though, IPv6 does not match IPv4. Nothing later in the series seems to change this.
As for how a decrypted skb gets to ip6_forward(): the mlx5 PSP RX decrypt rule in setup_fte_udp_psp() matches only on ip_protocol == IPPROTO_UDP and the UDP dport. It does not match on the destination address. mlx5e_psp_offload_handle_rx_skb() then sets skb->decrypted. With forwarding enabled, a PSP packet sent to a non-local IPv6 address would be decrypted and then forwarded.
kTLS RX offload can also produce a decrypted skb whose destination is no longer local. One example is when the local address is removed while the offload is still active.
The !skb_sec_path() condition already keeps redirects from quoting frames decapsulated by IPsec. Would a similar skb_is_decrypted() check make sense, either in the redirect condition in ip6_forward() or in ndisc_send_redirect()?
Quoted 3 lines
net/ipv6/icmp.c +0
-0if (!icmpv6_xrlim_allow (sk, type, &fl6, apply_ratelimit)) goto out_unlock;
[ ... ]
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261117203137.804424-1-toddfreed%40meta.com
Re: [PATCH net v6 5/8] ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors
Quoted 10 lines
[Severity: High]
Does this cover the NDISC Redirect sent fromip6_forward()? That path also quotes the invoking packet, but it never goes throughicmp6_send():None of these conditions look at
skb->decrypted.With
forwarding enabled, a PSP packet sent to a non-local IPv6 address would be decrypted and then forwarded.
Quoted 6 lines
kTLS RX offload can also produce a decrypted skb whose destination is no longer local. One example is when the local address is removed while the offload is still active.
The !skb_sec_path() condition already keeps redirects from quoting frames decapsulated by IPsec.
I reproduced this on CX7, with both psp and ktls offload sockets. It only affects
ipv6 (or rather, this path is already addressed by patch 4, the icmp fix).
* server enables forwarding (force_forwarding=1)
* client connects to an on-link address using the server as gateway, so the server forwards the packet back out and sends a redirect
* the forwarded packet itself is dropped because of skb->decrypted
* the redirect quotes the invoking packet which had been decrypted and goes out
I will post a v7 with one additional patch that addresses this.
-Todd
pw-bot: cr
PATCH v6 6/8 selftests: drv-net: psp: test ipv6 tcp socket with extension headers
In reply to Todd Freedsend on a psp tcp socket in three phases, checking the device's tx-packets and what the peer received after each:
1/ no socket options. the data is sent, counted, and received.
2/ an extension header set on the socket. the packets are dropped,
tx-packets is unchanged, and nothing reaches the peer. the data stays queued.
3/ option removed. the queued data, then new data, is sent, counted,
and received.
the test has three variants: a destination options header (IPV6_DSTOPTS) and a hop-by-hop options header (IPV6_HOPOPTS), each holding one padn option, and a segment routing header (IPV6_RTHDR).
a software filter on the peer also counts, and drops, udp packets from the socket's address to the peer's. psp packets reach the peer as decrypted tcp packets, as expected. packets which were encapsulated but are malformed or unencrypted (this is what mlx5 does) show up as udp, and the test asserts there are none. if the filter cannot be set up the test is skipped.
tx-packets is read after it has quiesced, because some devices refresh counters periodically (mlx5 takes about a second).
without the fix in "psp: don't encapsulate ipv6 packets with extension headers", netdevsim encapsulates the packets in a malformed way and counts them in tx-packets, and the test fails on that. with mlx5 (connectx-7), the packets go out unencrypted and aren't counted in tx-packets. the test fails on the udp packets which reach the peer. capturing on the peer,
tcpdump -i <dev> -nn -A 'ip6 and src host <sender> and not tcp'
shows them as udp, with the test's payload readable.
--- tools/testing/selftests/drivers/net/config | 1 + tools/testing/selftests/drivers/net/psp.py | 150 ++++++++++++++++++++- 2 files changed, 148 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/config +1 -0
@@ -4,6 +4,7 @@ CONFIG_DEBUG_INFO_BTF_MODULES=n CONFIG_INET_PSP=y CONFIG_IPV6=y CONFIG_MACSEC=m +CONFIG_NET_ACT_GACT=m CONFIG_NET_ACT_SKBEDIT=m CONFIG_NET_CLS_ACT=y CONFIG_NET_CLS_BPF=y
tools/testing/selftests/drivers/net/psp.py +147 -3
178 lines not on this page · raw message
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 6/8] selftests: drv-net: psp: test ipv6 tcp socket with extension headers
Sashiko has reviewed this patch and found no issues.
Quoted 18 lines
send on a psp tcp socket in three phases, checking the device's tx-packets and what the peer received after each:
1/ no socket options. the data is sent, counted, and received.
2/ an extension header set on the socket. the packets are dropped,
tx-packets is unchanged, and nothing reaches the peer. the data stays queued.3/ option removed. the queued data, then new data, is sent, counted,
and received.the test has three variants: a destination options header (
IPV6_DSTOPTS) and a hop-by-hop options header (IPV6_HOPOPTS), each holding one padn option, and a segment routing header (IPV6_RTHDR). [ ... ]
tcpdump -i <dev> -nn -A 'ip6 and src host <sender> and not tcp'
Quoted 3 lines
shows them as udp, with the test's payload readable.
Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH v6 7/8 selftests: drv-net: psp: test that ipv4 psp packets aren't fragmented
In reply to Todd Freedmake the ipv4 packets of a psp tcp socket need fragmenting, and check that they're dropped (IpFragFails) and not transmitted unencrypted.
tcp sizes its segments from the route mtu. with IP_PMTUDISC_OMIT, ip fragments them to the device mtu, and doesn't set df. so the test sets a route mtu of twice the larger of the two device mtus (at most 65535) on both ends (the peer's mss limits ours too), keeping the device and source address of the current route, and IP_PMTUDISC_OMIT on the socket. tcp mtu probing (tcp_mtu_probing 2, or 1 once a black hole is detected) can cap the mss at the probing base, so the test turns it off. if the peer isn't on-link, or the socket's mss doesn't need fragmenting, the test is skipped.
a software filter on the peer counts, and drops, the ipv4 fragments which reach it from the socket's address, and the test asserts there are none. IpFragFails is per netns, so it only confirms that the packets were dropped.
while both route mtus are in place, a new ssh connection to the remote over these addresses can stall: its segments are sized from the route mtu, and sent with df set. so the local route is added last, and removed before the next remote command.
no ipv6 test: the stack only fragments ipv6 tcp packets when something like ipvs sets ignore_df on them (see "net: don't fragment decrypted skbs"), which this test doesn't set up.
without the fix in "net: don't fragment decrypted skbs", the packets are fragmented, and the fragments go out unencrypted. they reach the peer, IpFragFails doesn't move, and the test fails.
--- tools/testing/selftests/drivers/net/psp.py | 95 +++++++++++++++++++++- 1 file changed, 94 insertions(+), 1 deletion(-)
tools/testing/selftests/drivers/net/psp.py +94 -1
@@ -22,10 +22,12 @@ from lib.py import KsftSkipEx, KsftFailEx, CmdExitFailure from lib.py import NetDrvEpEnv, NetDrvContEnv from lib.py import Netlink, NlError, PSPFamily, RtnlFamily from lib.py import NetNSEnter -from lib.py import bkg, rand_port, wait_port_listen +from lib.py import bkg, ctl_file_write, rand_port, wait_port_listen from lib.py import ip, tc TCP_ULP = 31 +IP_MTU_DISCOVER = 10 +IP_PMTUDISC_OMIT = 5 def _get_outq(s):
@@ -822,6 +824,97 @@ def data_send_ipv6_exthdr(cfg, opt, val): _close_psp_conn(cfg, s) +def _ipv4_snmp(key): + """ An Ip: counter of this netns, from /proc/net/snmp """ + with open("/proc/net/snmp", encoding="utf-8") as f: + ip_lines = [line.split() for line in f if line.startswith("Ip:")] + return int(ip_lines[1][ip_lines[0].index(key)]) + + +def _ipv4_route_mtu(dst, mtu, host=None): + """ Add a route to @dst with @mtu, keeping the device and source of + the current one, which must be on-link. Returns the defer removing it. + """ + route = ip(f"-4 route get {dst}", json=True, host=host)[0] + if route.get("gateway"): + raise KsftSkipEx(f"{dst} isn't on-link") + try: + ip(f"route add {dst}/32 dev {route['dev']} src {route['prefsrc']} " + f"mtu {mtu}", host=host) + except CmdExitFailure as e: + raise KsftSkipEx(f"can't set the route mtu to {dst}: {e}") from e + return defer(ip, f"route del {dst}/32 dev {route['dev']}", host=host) + + +def data_send_ipv4_frags(cfg): + """ Test that IPv4 packets of a PSP TCP socket aren't fragmented """ + cfg.require_ipver("4") + _init_psp_dev(cfg) + + # Fragments which get out reach the remote. Set up the count before + # connecting, so a skip doesn't leave the responder mid key exchange. + # The socket's source is the one the kernel picks, which may not be + # LOCAL_V4, and the fragments would leave through the route's device + rem = cfg.remote_addr_v["4"] + route = ip(f"-4 route get {rem}", json=True)[0] + if route["dev"] != cfg.ifname: + raise KsftSkipEx(f"{rem} isn't routed through {cfg.ifname}") + loc = route["prefsrc"] + remote_frags = _remote_count(cfg, "ip", + f"src_ip {loc} dst_ip {rem} ip_flags frag") + if not remote_frags: + raise KsftSkipEx("can't count fragments on the remote") + + # TCP sizes its segments from the route MTU. With IP_PMTUDISC_OMIT, IP + # fragments them to the device MTU. Set a route MTU above the device + # MTU on both ends, since the peer's MSS limits ours too. While both + # are in place, a new ssh connection to the remote over these addresses + # can stall, so add the local one last, and remove it first. + mtu = min(2 * max(cfg.dev['mtu'], cfg.remote_dev['mtu']), 65535) + _ipv4_route_mtu(loc, mtu, host=cfg.remote) + local_route = _ipv4_route_mtu(rem, mtu) + + # With MTU probing on, TCP can cap the MSS at the probing base, whatever + # the route MTU + ctl_file_write("/proc/sys/net/ipv4/tcp_mtu_probing", 0) + + s = _make_psp_conn(cfg, 0, "4") + try: + rx_assoc = cfg.pspnl.rx_assoc({"version": 0, + "dev-id": cfg.psp_dev_id, + "sock-fd": s.fileno()}) + tx = _spi_xchg(s, rx_assoc['rx-key']) + cfg.pspnl.tx_assoc({"dev-id": cfg.psp_dev_id, + "version": 0, + "tx-key": tx, + "sock-fd": s.fileno()}) + s.setsockopt(socket.IPPROTO_IP, IP_MTU_DISCOVER, IP_PMTUDISC_OMIT) + mss = s.getsockopt(socket.IPPROTO_TCP, socket.TCP_MAXSEG) + if mss + 40 <= cfg.dev['mtu']: + raise KsftSkipEx(f"mss {mss} needs no fragmenting") + + fails = _ipv4_snmp("FragFails") + # The packets are dropped, so the send may not complete (with a + # jumbo device MTU, the socket buffer can take all of it) + s.settimeout(3) + try: + s.sendall(b'f' * 200000) + except socket.timeout: + pass + fails = _ipv4_snmp("FragFails") - fails + + # Before the next ssh to the remote, see above + local_route.exec() + + # Fragments would go out unencrypted: the packets must be dropped + # instead of fragmented. FragFails is per netns, so it only + # confirms the drop: the remote count is what decides. + ksft_eq(remote_frags(), 0, comment="fragments reached the remote") + ksft_gt(fails, 0, comment="packets dropped instead of fragmented") + finally: + _close_psp_conn(cfg, s) + + def _get_psp_ver_ip_variants(): for ver in range(4): for ipv in ("4", "6"):
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 7/8] selftests: drv-net: psp: test that ipv4 psp packets aren't fragmented
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
make the ipv4 packets of a psp tcp socket need fragmenting, and check that they're dropped (IpFragFails) and not transmitted unencrypted.
tcp sizes its segments from the route mtu. with
IP_PMTUDISC_OMIT, ip fragments them to the device mtu, and doesn't set df. so the test sets a route mtu of twice the larger of the two device mtus (at most 65535) on both ends (the peer's mss limits ours too), keeping the device and source address of the current route, andIP_PMTUDISC_OMITon the socket. tcp mtu probing (tcp_mtu_probing2, or 1 once a black hole is detected) can cap the mss at the probing base, so the test turns it off. if the peer isn't on-link, or the socket's mss doesn't need fragmenting, the test is skipped.
Quoted 8 lines
a software filter on the peer counts, and drops, the ipv4 fragments which reach it from the socket's address, and the test asserts there are [ ... ]
without the fix in "net: don't fragment decrypted skbs", the packets are fragmented, and the fragments go out unencrypted. they reach the peer, IpFragFails doesn't move, and the test fails.Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
PATCH v6 8/8 net/mlx5e: psp: tso: replace only the length in checksum seed
In reply to Todd Freedfor psp tcp with tso,
- __tcp_transmit_skb() -> tcp_v6_send_check() or tcp_v4_send_check() computes the checksum seed using the addresses on the socket and the total length, then
- mlx5e_psp_handle_tx_skb() recomputes the checksum seed using addresses from the packet's l3 header, and the length of one segment
the length difference is expected by the device. however, the difference in addresses is incorrect in cases where the l3 header daddr is an intermediate hop, for example,
- ipv4 source route option (IP_OPTIONS with lsrr or ssrr)
- ipv6 IPV6_RTHDR header (conceptually ; ipv6 extension headers are not properly supported on this path yet)
in these cases every segment of the tso packet to go out with a bad tcp checksum
the fix is to replace only the length in the seed which tcp had already computed. this is also what tcp_gso_segment() does.
tested on connectx-7, with a psp tcp socket whose ipv4 loose source route's first hop isn't the final destination, and the peer checking tcp checksums in software.
--- .../mellanox/mlx5/core/en_accel/psp_rxtx.c | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +9 -12
@@ -177,18 +177,15 @@ bool mlx5e_psp_handle_tx_skb(struct net_device *netdev,return false; }if (skb_is_gso (skb)) { -int len =skb_shinfo (skb)->gso_size +inner_tcp_hdrlen (skb); -struct tcphdr *th =inner_tcp_hdr (skb); - -if (skb->protocol ==htons (ETH_P_IP )) { -const struct iphdr *ip =ip_hdr (skb); - - th->check = ~tcp_v4_check (len, ip->saddr, ip->daddr,0 ); - }else { -const struct ipv6hdr *ip6 =ipv6_hdr (skb); - - th->check = ~tcp_v6_check (len, &ip6->saddr, &ip6->daddr,0 ); - } +u32 seg_len =skb_shinfo (skb)->gso_size +inner_tcp_hdrlen (skb); +u32 len = skb->len -skb_inner_transport_offset (skb); + +/* update just the length component of the checksum seed +* tcp computed the seed with the total length, but mlx5 +* devices are expecting the segment length +*/ +inet_proto_csum_replace4 (&inner_tcp_hdr (skb)->check, skb, +htonl (len),htonl (seg_len), true); }return true;
Signature · 1 line
2.53.1-Meta
[email protected]
AI reviewRe: [PATCH net v6 8/8] net/mlx5e: psp: tso: replace only the length in checksum seed
Sashiko has reviewed this patch and found no issues.
Quoted 13 lines
for psp tcp with tso,
-
__tcp_transmit_skb()->tcp_v6_send_check()ortcp_v4_send_check()computes the checksum seed using the addresses on the socket and the total length, then-
mlx5e_psp_handle_tx_skb()recomputes the checksum seed using addresses from the packet's l3 header, and the length of one segmentthe length difference is expected by the device. however, the difference in addresses is incorrect in cases where the l3 header daddr is an intermediate hop, for example,
Quoted 8 lines
- ipv4 source route option (
IP_OPTIONSwith lsrr or ssrr)
- ipv6IPV6_RTHDRheader (conceptually ; ipv6 extension headers are not
[ ... ]Fixes e5a1861a298e ("net/mlx5e: Implement PSP Tx data path")Acked-by Daniel Zahka <[email protected]>Signed-off-by Todd Freed <[email protected]>
Sashiko has reviewed this patch and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
Re: [PATCH net v6 8/8] net/mlx5e: psp: tso: replace only the length in checksum seed
In reply to Todd FreedQuoted 10 lines · Todd Freed
for psp tcp with tso,
-
__tcp_transmit_skb()->tcp_v6_send_check()ortcp_v4_send_check()computes the checksum seed using the addresses on the socket and the total length, then-
mlx5e_psp_handle_tx_skb()recomputes the checksum seed using addresses from the packet's l3 header, and the length of one segmentthe length difference is expected by the device. however, the difference
No cap in first char of sentence makes reading the commit message harder. For example is this sentence standalone or a continuation? Sorry for cramping your style.
Quoted 9 lines
in addresses is incorrect in cases where the l3 header daddr is an intermediate hop, for example,
- ipv4 source route option (
IP_OPTIONSwith lsrr or ssrr)
- ipv6IPV6_RTHDRheader (conceptually ; ipv6 extension headers are not properly supported on this path yet)in these cases every segment of the tso packet to go out with a bad tcp checksum
What did you mean with "to go out" here? Goes out? Or is a verb missing?
Quoted 5 lines
the fix is to replace only the length in the seed which tcp had already
computed. this is also what
tcp_gso_segment()does.
Quoted 8 lines
tested on connectx-7, with a psp tcp socket whose ipv4 loose source route's first hop isn't the final destination, and the peer checking tcp checksums in software.
Fixes e5a1861a298e ("net/mlx5e: Implement PSP Tx data path")Acked-by Daniel Zahka <[email protected]>Signed-off-by Todd Freed <[email protected]>
Other than that:
Thanks,
Dragos
Re: [PATCH net v6 8/8] net/mlx5e: psp: tso: replace only the length in checksum seed
Quoted 3 lines
Quoted 2 lines
in these cases every segment of the tso packet to go out with a bad tcp checksum
What did you mean with "to go out" here? Goes out? Or is a verb missing?
Sorry about that. Here is the updated phrasing.
In these cases every segment of the TSO packet goes out with a bad TCP checksum.
I'm not sure whether I should re-post if the only changes are grammar improvements in the commit message. But, if it does get reposted, that is how it will be worded.
-Todd