From mboxrd@z Thu Jan 1 00:00:00 1970 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=1796389344; b=YNXxerg1nNGUlr/9/8UTe7jP6qIurhMGTxq0urqMDWnG6BlgKMhY95w2/UKvF2b7s7j+ PaXbXqUR3UtE3jWto75mmd8vcdH8YD3Qxm6u5h1WgmFPygiK+1NS/35TS4XMZc9EcjgOm CMTKiOt8pw/iE2RXynx+R/cD72esRyoB2N6+ScH0FHAbQfdH3oeisXCuM2cZ9kvQgvf5Q d+D8k8VN/Ek5+fgZi9Z0hqDl+kgID52Oc17H+ZHyqELBm/uJhlnyPUK7AQcGuY29MkwJF DX3L1uml2vGELlnNtbcpji4nXiajvB+IbOq4YdORseWsML2FMPQO/xxuL/bMyEKMKKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796389344; 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=0vXDPxAlaBWcXylp0cp2/4fHTj/S1ThPQDG/oGvJ9IM=; b=squjOJm60DsnBMeFBcS96RV8Kh5QILDuyj5ba8Cu3YNk4JcncCFQDYfycZEt0qBgohjg FB0dAykY+U0V/fGbQbYKtKmONCThicN337tK6G9bK3IuGW/VZDeyusScv+kxJ5ATK6O0x AhDWHkj9YiwEzGCXyszYbiZzi0jotYX6fY8b+IxD0DxCWuuKQ+y0OGcP+cZR50HC8InNu +B6vK1uDndOcjle0Z9yqduRJxoYmVyhvJvsir32rJguKdYWLj5g4KvZ0PtOXHRj1Z5/eP Fr0PAt4Agt1i58Vkn2jgitiKnz/9K+oNF75m9JRGkkuzb2DT5lWfb2N8j6Cbo1Zee4A== 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="2m/FyZQP"; 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 93ED2606A32D; Fri, 4 Dec 2026 13:02:24 +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=2m/FyZQP Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0ED51F00A05; Fri, 4 Dec 2026 13:02:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796389344; bh=0vXDPxAlaBWcXylp0cp2/4fHTj/S1ThPQDG/oGvJ9IM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=2m/FyZQPIjgcGzHYJwjGDuFUPwMKCF9EpKP/6PTOu2XKW6tTS3yuaGHXtRoKoDfEm k6VIIHBWJhcIOhChdLvSYFTNxZbmUf+V+aS5aC4Gwe2mNPVrXH9G0nh/8Y2BEkZ+fb pfd8uFK6UXX5ELJnK4tfqklldsx6Yguq+P7qplNE= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jaeyeong Lee , Paolo Abeni Subject: [PATCH 6.1 0957/1059] net/tls: serialize context removal in tls_device_down() Date: Fri, 4 Dec 2026 19:08:08 +0900 Message-ID: <20261204100708.808944104@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jaeyeong Lee commit 81c8333141b9aa465d98bb4c035284556e699701 upstream. tls_device_down() moves each context to tls_device_down_list while holding tls_device_lock. It then drops its reference and removes the context after releasing the lock. tls_device_queue_ctx_destruction() removes contexts from the same list under tls_device_lock. If it removes an adjacent context while tls_device_down() is deleting its node, the two list updates can interleave. One update can then target a context freed by the other path, causing a use-after-free write. Drop the reference and remove the context in the existing tls_device_lock critical section. Keep tls_device_free_ctx() after releasing the lock. This issue was found with a static analysis tool. Fixes: f6336724a4d4 ("net/tls: Remove the context from the list in tls_device_down") Cc: stable@vger.kernel.org Signed-off-by: Jaeyeong Lee Link: https://patch.msgid.link/20261112043209.102404-1-lee@jaeyeong.cc Signed-off-by: Paolo Abeni Signed-off-by: Greg Kroah-Hartman --- net/tls/tls_device.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -1396,6 +1396,8 @@ static int tls_device_down(struct net_de spin_unlock_irqrestore(&tls_device_lock, flags); list_for_each_entry_safe(ctx, tmp, &list, list) { + bool free_ctx; + /* Stop offloaded TX and switch to the fallback. * tls_is_sk_tx_device_offloaded will return false. */ @@ -1433,17 +1435,19 @@ static int tls_device_down(struct net_de */ spin_lock_irqsave(&tls_device_lock, flags); list_move_tail(&ctx->list, &tls_device_down_list); + /* Serialize the final removal with sk_destruct. */ + free_ctx = refcount_dec_and_test(&ctx->refcount); + if (free_ctx) + list_del(&ctx->list); spin_unlock_irqrestore(&tls_device_lock, flags); /* Device contexts for RX and TX will be freed in on sk_destruct * by tls_device_free_ctx. rx_conf and tx_conf stay in TLS_HW. - * Now release the ref taken above. */ - if (refcount_dec_and_test(&ctx->refcount)) { + if (free_ctx) { /* sk_destruct ran after tls_device_down took a ref, and * it returned early. Complete the destruction here. */ - list_del(&ctx->list); tls_device_free_ctx(ctx); } }