From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 61ED41F7586; Mon, 27 Oct 2025 18:59:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591572; cv=none; b=LWpz7gahPVN39/OiLH6xbmNzbV6MAfFtViQ1jG71OY4e+K85CWdccBdJJunaVO31kH9erirObZhVsZS2VvMUsL/FcLJPJlKai4nnPmqJx58R/M3mrJ82RUDAFa2t2u2hiPW60eNq9fubV55ZbP9POySM6DHRk2C20KhLHOooumA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761591572; c=relaxed/simple; bh=AX49Jqm92y1+4igOBsjnNdjOYvOzhL6yWYZfsTiA+4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AbpHFSRbimYyZz/j45qv7EJH/sqscirRZP1RpNtkRadvlbEidpHeEtu405vj8wH0F7YIBJSIaoIdlCxME6B1qZA0xgc1dwI/HlhKHwoFUEBaOvouMUIM5AYQHiiJsfnLFrNy4CR2+Rv0bdNctOYlvBjvvAKmOoTpMV8UPrArr7E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UJGdsQLZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UJGdsQLZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF4E7C4CEF1; Mon, 27 Oct 2025 18:59:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761591572; bh=AX49Jqm92y1+4igOBsjnNdjOYvOzhL6yWYZfsTiA+4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UJGdsQLZ8eehrJ+0JSGh3ir6o4RcKDtOJnuQyTxhX47hEqpRAsLujutpat1bDRMia Y1N1X4eH95nEL6Zb9yLAqHvxdCkVOyEOTM+XPJyt2O8a/Gt/KNNmr9yE9WdWbaLC2y fcEr5ms+itJg/EAsW4/0qEVgBjSutAtqVd/6mGBU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jann Horn , Sabrina Dubroca , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 248/332] tls: dont rely on tx_work during send() Date: Mon, 27 Oct 2025 19:35:01 +0100 Message-ID: <20251027183531.386868891@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183524.611456697@linuxfoundation.org> References: <20251027183524.611456697@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Sabrina Dubroca [ Upstream commit 7f846c65ca11e63d2409868ff039081f80e42ae4 ] With async crypto, we rely on tx_work to actually transmit records once encryption completes. But while send() is running, both the tx_lock and socket lock are held, so tx_work_handler cannot process the queue of encrypted records, and simply reschedules itself. During a large send(), this could last a long time, and use a lot of memory. Transmit any pending encrypted records before restarting the main loop of tls_sw_sendmsg_locked. Fixes: a42055e8d2c3 ("net/tls: Add support for async encryption of records for performance") Reported-by: Jann Horn Signed-off-by: Sabrina Dubroca Link: https://patch.msgid.link/8396631478f70454b44afb98352237d33f48d34d.1760432043.git.sd@queasysnail.net Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/tls/tls_sw.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/net/tls/tls_sw.c b/net/tls/tls_sw.c index e519a0160668e..a300d1ac13a88 100644 --- a/net/tls/tls_sw.c +++ b/net/tls/tls_sw.c @@ -1056,6 +1056,13 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) else if (ret != -EAGAIN) goto send_end; } + + /* Transmit if any encryptions have completed */ + if (test_and_clear_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) { + cancel_delayed_work(&ctx->tx_work.work); + tls_tx_records(sk, msg->msg_flags); + } + continue; rollback_iter: copied -= try_to_copy; @@ -1110,6 +1117,12 @@ int tls_sw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) goto send_end; } } + + /* Transmit if any encryptions have completed */ + if (test_and_clear_bit(BIT_TX_SCHEDULED, &ctx->tx_bitmask)) { + cancel_delayed_work(&ctx->tx_work.work); + tls_tx_records(sk, msg->msg_flags); + } } continue; -- 2.51.0