Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795042263; b=F0FrfGc5Z0OwK+DrqTTf3iFs/jDFJ+6lnrVG9RQdBOTz9YbQAt0OhEpcJugVl6clXFVk wBERUUu6Oi/ktGVaj1ZvVxZlr1i8sn9dGuwPQv1YnJiq0AdVz/8YMfaYB4nejfzUVBE4k j4UGDYK/9qHqdbWeKN1qghV0t2qOXzvWfnzV1UbFcN8xLW9X85fYG+nx+z38A6+SaLgkP rxtcrMFgqiX7NGdmcQesn8FG4iGvUgseDP7GABg5PaatmJ0J8i6olQbCP9mvfUCTAm44t I0tU8yuR5w8SqU/KTz7MJJ9mcWDEFw4dqp536zTHefAPu+wrfbKU1KbU23NTZw9BLrg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795042263; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=I03Zlx+Oreh0XIKZtnZmEhTiSOzaS6q1WcsCt0JPmug=; b=gQ9KwVZ1rYZ/TzHIMZ2u+VfTbQZC52MtuMTWTKrE3d4u+eGimPM6WAEwlE1S9SI2lq2j HpNm4zHEG+iZD/0KBMvp+GFGr11iLgfiutFIvJim5nNfrcZCeWz8sGUaXhpvCWeIWu4Xl 3i6EWqE+zSGYkqJ83CzxKSEnNqDfJGuHB5g9/QkV6tFyanSDk3okzVP0OgW1Y3dVsgZzc jrTOwd+tLG1EFKXpe4wHxjLImUCXM0cyCwh9T3P9EMgvFWRHSOvGv7X7i17oan1Ayakpm qaQRoXKm9S0rzy88OaRSnuCcYJETRFkxNCKuh1ci4HwWaodD0L6L+dRWDHg1uqiJ+gQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=l43fafOL; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5DF53606A32A; Wed, 18 Nov 2026 22:51:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=l43fafOL Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC59C1F000C5; Wed, 18 Nov 2026 22:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1795042263; bh=I03Zlx+Oreh0XIKZtnZmEhTiSOzaS6q1WcsCt0JPmug=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=l43fafOLcRVr5ix2CswN2QEefyBB8K6jF7rCt3+/ofFCNc2G4/9+0kXbH0J8VHzwX UkFwASVlcrq83UFLB01mgiN9SgJSzTlH2Rg9LHbU/uwKkejShIU7HQD1fmOvshtLkb oUYvJObhVJBZUeEbTu2cjr65L1vBZBP0P92NzZ/Y= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rishikesh Jethwani , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.6 3071/3318] tls: device: protect async RX resync state during device-down Date: Wed, 18 Nov 2026 16:01:33 +0100 Message-ID: <20261118150452.234243718@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261118150313.527275416@linuxfoundation.org> References: <20261118150313.527275416@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rishikesh Jethwani [ Upstream commit f89a228125238f8d4c7e2b8161e2a85fe35307b6 ] tls_device_rx_resync_new_rec() can run in process context with the socket lock held, but without an RCU read lock: from the strparser work item (tls_strp_work()) and from the receive paths (tls_rx_rec_wait(), tls_rx_rec_done()). The resync_async pointer belongs to the driver RX context, which tls_device_down() tears down from the netdev notifier without taking the socket lock; only the softirq entry to the parser is implicitly inside an RCU section. If the parser passes the TLS_RX_DEV_DEGRADED check before device-down sets it, tls_device_down() can complete synchronize_net() and delete the driver context before the parser accesses resync_async->req or its record log. In the asynchronous stage the parser also writes the record log, so this is a write to freed memory, not only a stale read. The RCU section in tls_device_resync_rx() starts after those accesses and therefore does not prevent the use-after-free. Found by code inspection; not reproduced. Hitting the window requires the parser to be preempted between the DEGRADED check and the resync_async access across the device-down grace period and the driver's teardown. Fixes: ed9b7646b06a ("net/tls: Add asynchronous resync") Signed-off-by: Rishikesh Jethwani Link: https://patch.msgid.link/20261013213517.2219663-1-rjethwani@purestorage.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/tls/tls_device.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index bb7057aa828e1..ea4f19d09b832 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -788,8 +788,15 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (tls_ctx->rx_conf != TLS_HW) return; + + /* The parser also runs in process context, without an RCU read lock. + * Protect the driver's resync_async state before checking the flags: + * device-down sets DEGRADED and waits for synchronize_net() before + * freeing it, without taking the socket lock. + */ + rcu_read_lock(); if (unlikely(test_bit(TLS_RX_DEV_DEGRADED, &tls_ctx->flags))) - return; + goto out; prot = &tls_ctx->prot_info; rx_ctx = tls_offload_ctx_rx(tls_ctx); @@ -804,11 +811,11 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (likely(!is_req_pending) || req_seq != seq || !atomic64_try_cmpxchg(&rx_ctx->resync_req, &resync_req, 0)) - return; + goto out; break; case TLS_OFFLOAD_SYNC_TYPE_CORE_NEXT_HINT: if (likely(!rx_ctx->resync_nh_do_now)) - return; + goto out; /* head of next rec is already in, note that the sock_inq will * include the currently parsed message when called from parser @@ -817,7 +824,7 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) if (sock_data > rcd_len) { trace_tls_device_rx_resync_nh_delay(sk, sock_data, rcd_len); - return; + goto out; } rx_ctx->resync_nh_do_now = 0; @@ -828,16 +835,18 @@ void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) resync_req = atomic64_read(&rx_ctx->resync_async->req); is_req_pending = resync_req; if (likely(!is_req_pending)) - return; + goto out; if (!tls_device_rx_resync_async(rx_ctx->resync_async, resync_req, &seq, &rcd_delta)) - return; + goto out; tls_bigint_subtract(rcd_sn, rcd_delta); break; } tls_device_resync_rx(tls_ctx, sk, seq, rcd_sn); +out: + rcu_read_unlock(); } static void tls_device_core_ctrl_rx_resync(struct tls_context *tls_ctx, -- 2.53.0