psp, tls: don't send offloaded contents in cleartext
Subsystems (10)
v7 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)
5/ IPv6 redirects (patch 6)
Cases 2 to 5 are relevant for kTLS as well as PSP.
Patch 9 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's reject expression in netdev and bridge chains builds its own ICMP errors, outside these paths. A separate patch to nf applies the same rule there,
https://lore.kernel.org/netfilter-devel/[email protected]
Testing:
Hardware testing was done on ConnectX-7 (FW 28.48), between two x86 hosts, plus netdevsim.
- 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.
- IPv6 redirects, on mlx5, with the server forwarding on its interface (force_forwarding), as described in patch 6:
- kTLS and PSP: Without the fix, the redirects from the server quote the decrypted TCP header and payload. With it, no redirect is sent for the decrypted segments.
- In both cases, redirects for packets that weren't decrypted are still sent.
v7:
- new patch 6: ip6_forward() quoted decrypted packets in the NDISC redirect, which doesn't go through icmp6_send(). Don't send redirects for decrypted skbs (Sashiko)
- patch 3: the commit message now says the check comes after the ignore_df and frag_max_size too-big checks (Sashiko)
- patch 5: log the dropped errors with net_dbg_ratelimited(), like the other cases where icmp6_send() doesn't reply (Sashiko)
- sentence case in the commit messages, and patch 9 wording (Dragos)
- Cc: stable on the fixes (patches 1-6 and 9)
- rebase on net/main
v6: https://lore.kernel.org/netdev/[email protected]
- 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 in the commit message 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 (9):
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
ipv6: don't send redirects for decrypted skbs
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 | 23 ++ net/ipv6/ip6_output.c | 14 +- net/psp/psp_main.c | 21 +- tools/testing/selftests/drivers/net/config | 1 + tools/testing/selftests/drivers/net/psp.py | 245 +++++++++++++++++- 9 files changed, 333 insertions(+), 20 deletions(-)
base-commit: 639a75a3539f621e4437ffeec7ab51bf8a1fb170
Signature · 1 line
2.53.1-Meta
PATCH v7 1/9 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
Re: [PATCH net v7 1/9] net/mlx5e: ring the tx doorbell when an accel offload drops a packet
Quoted 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 7 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")Reviewed-by Dragos Tatulea <[email protected]>Signed-off-by Todd Freed <[email protected]>
Thanks.
PATCH v7 2/9 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 a 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
PATCH v7 3/9 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 software 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 ignore_df and frag_max_size 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
PATCH v7 4/9 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 PREROUTING, INPUT or FORWARD chain, or in an inet ingress 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 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
PATCH v7 5/9 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 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.
Like the other cases where icmp6_send() doesn't reply, log the drop with net_dbg_ratelimited().
--- net/ipv6/icmp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
net/ipv6/icmp.c +23 -0
@@ -778,6 +778,18 @@ 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)) { +net_dbg_ratelimited ("%s: no reply to received decrypted packet [%pI6c > %pI6c]\n" , + __func__, &hdr->saddr, &hdr->daddr); + goto out_unlock; + } +if (!icmpv6_xrlim_allow (sk, type, &fl6, apply_ratelimit)) goto out_unlock;
@@ -799,6 +811,17 @@ 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 )) { +net_dbg_ratelimited ("%s: no reply to locally originated decrypted packet [%pI6c > %pI6c]\n" , + __func__, &hdr->saddr, &hdr->daddr); +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
PATCH v7 6/9 ipv6: don't send redirects for decrypted skbs
In reply to Todd FreedWhen ip6_forward() forwards a packet back out of the interface it came in on, it sends an NDISC Redirect to the packet's source. The Redirected Header option 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), the redirect sends part of it back out onto the network in cleartext.
The redirect is built by ndisc_send_redirect(), not icmp6_send(), so the previous patch for ICMPv6 errors doesn't cover it. On IPv4 the redirect goes through __icmp_send(), which the patch for ICMP errors covers.
Both PSP and kTLS RX device offload can get a decrypted skb forwarded:
- mlx5 decrypts PSP packets whatever their destination address. A PSP packet encrypted with the server's key but addressed to another host on the link, and routed via the server, is decrypted and forwarded.
- kTLS RX device offload keeps decrypting a connection's packets after its local address is removed. With TCP early demux disabled (net.ipv4.ip_early_demux=0), they are then forwarded. With early demux, ip6_forward() drops them, as early demux attached the socket.
Note that the forwarded packet itself is dropped by sk_validate_xmit_skb() because of skb->decrypted.
Reproduced with mlx5 (ConnectX-7), with a client C, a server S and a peer P on the same link. On S, forwarding is enabled on the interface only:
sysctl -w net.ipv6.conf.eth0.force_forwarding=1
PSP:
- C routes P's address via S:
ip -6 route add P/128 via S dev eth0
- C connects to a TCP server on P, with PSP on its socket using S's key.
- S's device decrypts the segments C sends, and ip6_forward() routes them back out of eth0 towards P. S sends the redirect.
kTLS:
kTLS RX device offload only decrypts the flows of local kTLS sockets, so the packets have to belong to a connection to S that is no longer delivered locally:
- S has a second address S2 on the prefix. C opens a kTLS connection to S2, with kTLS RX device offload on S.
- S disables TCP early demux (net.ipv4.ip_early_demux=0), then removes S2 while C keeps sending.
- S's device keeps decrypting the connection's records, S forwards them back out of eth0, and sends C redirects quoting them in cleartext.
With this patch, no redirect is sent for the decrypted packets (in both cases), and packets which weren't decrypted still get one.
Don't send redirects for decrypted skbs, as for skbs decapsulated from IPsec.
--- net/ipv6/ip6_output.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/ipv6/ip6_output.c +4 -1
@@ -619,9 +619,12 @@ int ip6_forward(struct sk_buff *skb)/* IPv6 specs say nothing about it, but it is clear that we cannot send redirects to source routed frames. We don't send redirects to frames decapsulated from IPsec. +Nor to frames decrypted by the device: the redirect would quote +them in cleartext. */ if (IP6CB (skb)->iif == dev->ifindex && - opt->srcrt ==0 && !skb_sec_path (skb)) { + opt->srcrt ==0 && !skb_sec_path (skb) && + !skb_is_decrypted (skb)) {struct in6_addr *target =NULL ;struct inet_peer *peer;struct rt6_info *rt;
Signature · 1 line
2.53.1-Meta
PATCH v7 7/9 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
PATCH v7 8/9 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
PATCH v7 9/9 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 goes 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 reviewSashiko has reviewed this 9-patch series and found no issues.
Sashiko has reviewed this 9-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]