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=1796383884; b=kM/+uEk/ayxc1yhEcNU1AsKOd1j1yXcKUiteEE56Cr7deGZlqFSwmWq47A+mAnCSSWLI urO4Eu/O49uFyRyVIy02yxcast9W9iQNDOyFRz0JCk41FR4yalXvqFo6HOULxfQHae+m6 UJkQg/TPqMOSpT4qk9amU28pDgZgVTr+yKj+oWAyPlbZmFsG/N6gY+VzUjxYcVAb01kWh FNDnGIh+VvsGShywGSH1jCD92QS+5197FxkVa7Pi7dcuH/I+IadeWE3RImviXHEDwy6dA q0mtCASym+hsTDs7RvY2zWSe51i170s4hwKKuDwHNDfeqZHmzMhdFj2SZsrWblI8eGw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383884; 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=lca78t64j9vm8WaaSjYO3DePwq0zvnj73oH2wiUMLfw=; b=CbXAEmE80233yOeI7O7lF3Mofp5iXgZ+1PeigQAD3x7NWkkkyN/xz+0nOZj6VoDOa3aw vzBefVFySYynrO+zZU3GKln1R6tvzFhnFzEwIca2MDQPHxp+x4l86ES988lPR2baUhm6V 2KaGsEC/6t2rd3x4cHORa0nP1iKY9S7ANw16ohyUUGV4i7qSSGxCzpLJwnWs0jPpT9ROL YZ8i6MhpzYfTKWITya2KUWTZ9/gTfxG0LYKRPjGZ2ijvYy3E5HGBUOgxncBcS6TIJUZ7d 662z09dHmBEGILoUd0zbcE1YLK2cZqo+rDnpuz/gdQwX9LSHMsKlQMk4O2P8JjT1rMw== 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=sDV8gF+q; 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 CA2D3606A322; Fri, 4 Dec 2026 11:31: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=sDV8gF+q Received: by smtp.kernel.org (Postfix) with ESMTPSA id 413211F000C2; Fri, 4 Dec 2026 11:31:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383884; bh=lca78t64j9vm8WaaSjYO3DePwq0zvnj73oH2wiUMLfw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=sDV8gF+qetxZ2AkzbJXwsXbt118oQ1dratfc2oRfNSP4YvX/Hk4Rx/4oYjertYbdr QHk0gSyMizL5y/IPSOr9UczRdXzm3XN4WWd8mCdRbfyoGNy+376J6i+qzxiE/8Oq5i m6kF4WF0h6FNBjW4dS+UnXbBU+KZe75etHz0YkrU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jaeyeong Lee , Paolo Abeni Subject: [PATCH 6.12 408/555] net/tls: serialize context removal in tls_device_down() Date: Fri, 4 Dec 2026 19:07:31 +0900 Message-ID: <20261204100625.274589048@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@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.12-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 @@ -1349,6 +1349,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_skb_tx_device_offloaded will return false. */ @@ -1386,17 +1388,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); } }