Skip to contentSkip to conversation

netfilter: reject: don't quote decrypted payload in icmp errors

PATCH New Todd Freed 1 participant 1 message Nov 23

Subsystems (4)
lore
Share & tools
lore

Todd Freed

author
#0 lore raw

PATCH 1/1 netfilter: reject: don't quote decrypted payload in icmp errors

On receive, skb->decrypted means that the device decrypted the skb (kTLS device offload, PSP). For a decrypted skb, any part of the packet which had been encrypted should not be sent back onto the network in cleartext.

These patches in the net series,

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

ipv4: icmp: don't quote decrypted payload in icmp errors
ipv6: icmpv6: don't quote decrypted payload in icmpv6 errors

make the IP stack not send any ICMP error about a received decrypted skb.

The reject expression in netdev and bridge chains builds its own ICMP errors, without icmp_send() and icmpv6_send(). nf_reject_skb_v4_unreach() and nf_reject_skb_v6_unreach() quote up to 536 and 1220 bytes of the packet. Apply the rule to these paths too. These only get received skbs, as the netdev and bridge reject expressions are limited to the ingress, prerouting and input hooks, so unlike icmp_send() no locally originated case needs to be kept.

The reject rule still drops the packet, but without a reply, as it already does in other cases (non-first fragments, ICMP errors, bad checksums).

nf_send_unreach() and nf_send_unreach6() use icmp_send() and icmpv6_send(), which are covered by the net series.

Testing:

Reproduced with mlx5 (ConnectX-7) on net/main, with a reject rule in a netdev ingress chain on the receiving host matching an established connection. With kTLS RX device offload, the ICMP and ICMPv6 unreachables quoted the decrypted TLS payload in cleartext. With PSP sockets, the ICMPv6 unreachables quoted the decrypted TCP header and payload. With this patch, no ICMP error is sent for the decrypted packets.

Fixes 784abe24c903 ("net: Add decrypted field to skb")

---

Notes:
This supersedes the 2-patch nf-next series "netfilter: don't send decrypted skbs in clear text":
https://lore.kernel.org/netfilter-devel/[email protected]

- Patch 2/2, "netfilter: reject: don't reply to decrypted skbs", reproduces on net/main, so it is resent here to nf as a fix, reduced to the ICMP errors.
- Patch 1/2, "netfilter: bridge: don't refragment decrypted skbs", is dropped. I could not reproduce it on mlx5, neither on net/main nor with the socket-less PSP series: the device doesn't decrypt PSP in IP fragments.

 net/ipv4/netfilter/nf_reject_ipv4.c | 7 +++++++
 net/ipv6/netfilter/nf_reject_ipv6.c | 7 +++++++
 2 files changed, 14 insertions(+)
net/ipv4/netfilter/nf_reject_ipv4.c +7 -0
index 7cb33af671e2..4d89ec6a4a91 100644
@@ -118,6 +118,13 @@ struct sk_buff *nf_reject_skb_v4_unreach(struct net *net,
 	if (!nf_reject_iphdr_validate(oldskb))
 		return NULL;
 
+	/* Don't send the decrypted part of an skb onto the network: the
+	 * device decrypted a received skb, and this reply quotes it. Only
+	 * received skbs get here (bridge, netdev ingress).
+	 */
+	if (unlikely(skb_is_decrypted(oldskb)))
+		return NULL;
+
 	/* IP header checks: fragment. */
 	if (ip_hdr(oldskb)->frag_off & htons(IP_OFFSET))
 		return NULL;
net/ipv6/netfilter/nf_reject_ipv6.c +7 -0
index 5e08d8529cc8..fc30569b1f4d 100644
@@ -144,6 +144,13 @@ struct sk_buff *nf_reject_skb_v6_unreach(struct net *net,
 	if (!nf_reject_ip6hdr_validate(oldskb))
 		return NULL;
 
+	/* Don't send the decrypted part of an skb onto the network: the
+	 * device decrypted a received skb, and this reply quotes it. Only
+	 * received skbs get here (bridge, netdev ingress).
+	 */
+	if (unlikely(skb_is_decrypted(oldskb)))
+		return NULL;
+
 	/* Don't reply to ICMPV6_DEST_UNREACH with ICMPV6_DEST_UNREACH */
 	if (nf_skb_is_icmp6_unreach(oldskb))
 		return NULL;

base-commit: 734bef548a96e8774d6eef5dfa2026c6edc4e80b

Signature · 1 line
2.53.1-Meta