Patch "net: tls: avoid discarding data on record close" has been added to the 6.4-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    net: tls: avoid discarding data on record close

to the 6.4-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     net-tls-avoid-discarding-data-on-record-close.patch
and it can be found in the queue-6.4 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.


>From 6b47808f223c70ff564f9b363446d2a5fa1e05b2 Mon Sep 17 00:00:00 2001
From: Jakub Kicinski <kuba@xxxxxxxxxx>
Date: Fri, 4 Aug 2023 15:59:51 -0700
Subject: net: tls: avoid discarding data on record close

From: Jakub Kicinski <kuba@xxxxxxxxxx>

commit 6b47808f223c70ff564f9b363446d2a5fa1e05b2 upstream.

TLS records end with a 16B tag. For TLS device offload we only
need to make space for this tag in the stream, the device will
generate and replace it with the actual calculated tag.

Long time ago the code would just re-reference the head frag
which mostly worked but was suboptimal because it prevented TCP
from combining the record into a single skb frag. I'm not sure
if it was correct as the first frag may be shorter than the tag.

The commit under fixes tried to replace that with using the page
frag and if the allocation failed rolling back the data, if record
was long enough. It achieves better fragment coalescing but is
also buggy.

We don't roll back the iterator, so unless we're at the end of
send we'll skip the data we designated as tag and start the
next record as if the rollback never happened.
There's also the possibility that the record was constructed
with MSG_MORE and the data came from a different syscall and
we already told the user space that we "got it".

Allocate a single dummy page and use it as fallback.

Found by code inspection, and proven by forcing allocation
failures.

Fixes: e7b159a48ba6 ("net/tls: remove the record tail optimization")
Signed-off-by: Jakub Kicinski <kuba@xxxxxxxxxx>
Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 net/tls/tls_device.c |   64 ++++++++++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 31 deletions(-)

--- a/net/tls/tls_device.c
+++ b/net/tls/tls_device.c
@@ -52,6 +52,8 @@ static LIST_HEAD(tls_device_list);
 static LIST_HEAD(tls_device_down_list);
 static DEFINE_SPINLOCK(tls_device_lock);
 
+static struct page *dummy_page;
+
 static void tls_device_free_ctx(struct tls_context *ctx)
 {
 	if (ctx->tx_conf == TLS_HW) {
@@ -313,36 +315,33 @@ static int tls_push_record(struct sock *
 	return tls_push_sg(sk, ctx, offload_ctx->sg_tx_data, 0, flags);
 }
 
-static int tls_device_record_close(struct sock *sk,
-				   struct tls_context *ctx,
-				   struct tls_record_info *record,
-				   struct page_frag *pfrag,
-				   unsigned char record_type)
+static void tls_device_record_close(struct sock *sk,
+				    struct tls_context *ctx,
+				    struct tls_record_info *record,
+				    struct page_frag *pfrag,
+				    unsigned char record_type)
 {
 	struct tls_prot_info *prot = &ctx->prot_info;
-	int ret;
+	struct page_frag dummy_tag_frag;
 
 	/* append tag
 	 * device will fill in the tag, we just need to append a placeholder
 	 * use socket memory to improve coalescing (re-using a single buffer
 	 * increases frag count)
-	 * if we can't allocate memory now, steal some back from data
+	 * if we can't allocate memory now use the dummy page
 	 */
-	if (likely(skb_page_frag_refill(prot->tag_size, pfrag,
-					sk->sk_allocation))) {
-		ret = 0;
-		tls_append_frag(record, pfrag, prot->tag_size);
-	} else {
-		ret = prot->tag_size;
-		if (record->len <= prot->overhead_size)
-			return -ENOMEM;
+	if (unlikely(pfrag->size - pfrag->offset < prot->tag_size) &&
+	    !skb_page_frag_refill(prot->tag_size, pfrag, sk->sk_allocation)) {
+		dummy_tag_frag.page = dummy_page;
+		dummy_tag_frag.offset = 0;
+		pfrag = &dummy_tag_frag;
 	}
+	tls_append_frag(record, pfrag, prot->tag_size);
 
 	/* fill prepend */
 	tls_fill_prepend(ctx, skb_frag_address(&record->frags[0]),
 			 record->len - prot->overhead_size,
 			 record_type);
-	return ret;
 }
 
 static int tls_create_new_record(struct tls_offload_context_tx *offload_ctx,
@@ -535,18 +534,8 @@ last_record:
 
 		if (done || record->len >= max_open_record_len ||
 		    (record->num_frags >= MAX_SKB_FRAGS - 1)) {
-			rc = tls_device_record_close(sk, tls_ctx, record,
-						     pfrag, record_type);
-			if (rc) {
-				if (rc > 0) {
-					size += rc;
-				} else {
-					size = orig_size;
-					destroy_record(record);
-					ctx->open_record = NULL;
-					break;
-				}
-			}
+			tls_device_record_close(sk, tls_ctx, record,
+						pfrag, record_type);
 
 			rc = tls_push_record(sk,
 					     tls_ctx,
@@ -1466,14 +1455,26 @@ int __init tls_device_init(void)
 {
 	int err;
 
-	destruct_wq = alloc_workqueue("ktls_device_destruct", 0, 0);
-	if (!destruct_wq)
+	dummy_page = alloc_page(GFP_KERNEL);
+	if (!dummy_page)
 		return -ENOMEM;
 
+	destruct_wq = alloc_workqueue("ktls_device_destruct", 0, 0);
+	if (!destruct_wq) {
+		err = -ENOMEM;
+		goto err_free_dummy;
+	}
+
 	err = register_netdevice_notifier(&tls_dev_notifier);
 	if (err)
-		destroy_workqueue(destruct_wq);
+		goto err_destroy_wq;
 
+	return 0;
+
+err_destroy_wq:
+	destroy_workqueue(destruct_wq);
+err_free_dummy:
+	put_page(dummy_page);
 	return err;
 }
 
@@ -1482,4 +1483,5 @@ void __exit tls_device_cleanup(void)
 	unregister_netdevice_notifier(&tls_dev_notifier);
 	destroy_workqueue(destruct_wq);
 	clean_acked_data_flush();
+	put_page(dummy_page);
 }


Patches currently in stable-queue which might be from kuba@xxxxxxxxxx are

queue-6.4/selftests-forwarding-ethtool-skip-when-using-veth-pairs.patch
queue-6.4/selftests-mptcp-join-fix-implicit-ep-test.patch
queue-6.4/selftests-forwarding-bridge_mdb_max-fix-failing-test-with-old-libnet.patch
queue-6.4/selftests-forwarding-skip-test-when-no-interfaces-are-specified.patch
queue-6.4/iavf-fix-potential-races-for-fdir-filters.patch
queue-6.4/selftests-mptcp-join-fix-delete-and-re-add-test.patch
queue-6.4/tcp-add-missing-family-to-tcp_set_ca_state-tracepoint.patch
queue-6.4/selftests-forwarding-bridge_mdb-fix-failing-test-with-old-libnet.patch
queue-6.4/selftests-forwarding-tc_tunnel_key-make-filters-more-specific.patch
queue-6.4/net-marvell-prestera-fix-handling-ipv4-routes-with-nhid.patch
queue-6.4/misdn-update-parameter-type-of-dsp_cmx_send.patch
queue-6.4/selftests-forwarding-tc_flower-relax-success-criterion.patch
queue-6.4/net-tls-avoid-discarding-data-on-record-close.patch
queue-6.4/igc-add-lock-to-safeguard-global-qbv-variables.patch
queue-6.4/vlan-fix-vlan-0-memory-leak.patch
queue-6.4/net-core-remove-unnecessary-frame_sz-check-in-bpf_xdp_adjust_tail.patch
queue-6.4/ipv6-adjust-ndisc_is_useropt-to-also-return-true-for-pio.patch
queue-6.4/wireguard-allowedips-expand-maximum-node-depth.patch
queue-6.4/mptcp-avoid-bogus-reset-on-fallback-close.patch
queue-6.4/bonding-fix-incorrect-deletion-of-eth_p_8021ad-protocol-vid-from-slaves.patch
queue-6.4/selftests-forwarding-bridge_mdb-check-iproute2-version.patch
queue-6.4/selftests-forwarding-bridge_mdb-make-test-more-robust.patch
queue-6.4/selftests-forwarding-ethtool_extended_state-skip-when-using-veth-pairs.patch
queue-6.4/dccp-fix-data-race-around-dp-dccps_mss_cache.patch
queue-6.4/selftests-forwarding-ethtool_mm-skip-when-mac-merge-is-not-supported.patch
queue-6.4/mptcp-fix-disconnect-vs-accept-race.patch
queue-6.4/selftests-forwarding-add-a-helper-to-skip-test-when-using-veth-pairs.patch
queue-6.4/net-packet-annotate-data-races-around-tp-status.patch
queue-6.4/mptcp-fix-the-incorrect-judgment-for-msk-cb_flags.patch
queue-6.4/selftests-forwarding-switch-off-timeout.patch
queue-6.4/drivers-net-prevent-tun_build_skb-to-exceed-the-packet-size-limit.patch
queue-6.4/net-mana-fix-mana-vf-unload-when-hardware-is-unresponsive.patch
queue-6.4/selftests-forwarding-hw_stats_l3_gre-skip-when-using-veth-pairs.patch
queue-6.4/selftests-forwarding-bridge_mdb_max-check-iproute2-version.patch
queue-6.4/tunnels-fix-kasan-splat-when-generating-ipv4-pmtu-error.patch
queue-6.4/selftests-forwarding-tc_actions-use-ncat-instead-of-nc.patch
queue-6.4/selftests-forwarding-set-default-ipv6-traceroute-utility.patch



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux