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=1796381015; b=OcJu52sYfQ9IKIcsaITPeQ7FQFhOxoRqmIJGRwiptVoS0i18r3EZ3T9vMwdcCwqoAaVG FM7j/l0/M40BPMXcvDW4XNMR6IV1L9kE4EqXnB+XI2NlD+f2IRC+LjcD1bwngdYVEBFQp i4abc0sR7HGs8QHN1hoeKP+GoQlurHRofIC+tEfyXEG7xuObWAHpNpGxSoUDNmr+K/kiV j2cHY9xsn+kF1tVIQmei+L/xND7MaArKncLXWTVKAhMitxErspCn51Rdqwbq+MHtPf5eO OAkV/88u/rsLNq8hS3KsTOOhQY8OCpbAo2LMf0dMMgdbyFBlyoRAnscTrteUf+NGnCA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381015; 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=H5PKT+R9R6MkJrgN3CdefHuKBIDaTSXmYRe9GKTlXjI=; b=HJ1RkLMzWW2ZuO9PLxb0o7RHvs1i/5e000IEHLLJz97IhhLnxVXL7ZHMLUBUuHJO8vJ3 2MRChafiU6WmsUBxXQ+OIQQEzmjGvnXvL0FlT+ciABXDt5Eh5AtXENohVwgCd4Gw7gUln iH6lBN88t0UOXjdZE1VJpjBhQ326blabNu0VnuivVVrj4xoGSDAmswBVhcoDdwi0W7xMR fg+4j0P09nEnmrltuBOkCaO/GbMnjzJq258spOov/MKu3AQnGUqIi97d/GK8PQoMddbbY wpPDD+/VpORthQgOPARv42XPp/BdlbaFV98ZP0ZWsYa72TKYUB2dkIR7p9e/5uhmevA== 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=jOXJsYM0; 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 77913606A322; Fri, 4 Dec 2026 10:43:35 +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=jOXJsYM0 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB2E51F000CE; Fri, 4 Dec 2026 10:43:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381015; bh=H5PKT+R9R6MkJrgN3CdefHuKBIDaTSXmYRe9GKTlXjI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=jOXJsYM0GLhqaLqRmkf7bXP7Y8Uo6KUbSnT+t6kqjxyW/R62NI37SZiCfmrL26hd5 D9Cc5bF4owUiNASSxH2aLxxruCOor5KWLd9EDDF4RevlkJgpkbt6X8lxb8P0iVaI/f 45BD8cU5dd/HLy9nrTLoU/4pFZ2VmZ1nEanQuxi0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jaeyeong Lee , Paolo Abeni Subject: [PATCH 7.3 520/742] net/tls: serialize context removal in tls_device_down() Date: Fri, 4 Dec 2026 19:06:24 +0900 Message-ID: <20261204100648.981349582@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@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 7.3-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 @@ -1350,6 +1350,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. */ @@ -1387,17 +1389,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); } }