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=1794061597; b=abiRn7N47sfnMdWNY1GVoiLWvEY2iW0y2bns2PUw6JLmncphy0PslUuhTGIZd4/35kwz AEDas5Whnu/eqV8cgktIVQxvOrVuAMj+yTEMSQvRWLGwtgi8z4FXR09HEzxdQis1gmMbZ m16NRtnXJvo8R/jLMET8umj2PbfCZ9zH+LfM7CQeNgYl7AMVPgTnYGiYwEmSY8EyZvlQn GBkBmrOExoaR0du9vJ8QLqDaPfK3F762+VgOUNLyMHw+yA0yWTvKnL0u6LfxW5rjpwyfF kO3Babypo4Pm/CbUvsTneX+AWytvqomfeLYvZ8vQSZvylP+ZfIEsDt+GFox0+v+7J+A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794061597; 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=nhUB9GKd/KDiKFZteUQuufyt1ys7MLtDTMcAyQaCFM4=; b=qXvjmYRJNYVNX9FVikoxWV+x7s54TUpqB4bT5zYN9QDwlWj+70a7m1o22GI/RXimtLCl PpLkwWe5l9Xyz0S5YLUZ6hLcUqJL59PEomvX2AYh5CIyMYEt/zawwKHWEtBbvBfsIHIrl I58HXI6ktheoiTctbjCc7rPaW4EEVAVWiQ7RnNeQxZ/FecTAn0bOzTqiRzamCPmRvxdic sawXJ1NyLXQd3NTgfMNBLizMBq/HTPKjjJrdmoXkNF7uqnAH1DCmZvw+NOwu3B0Hmqp+j c/eOEdINc8XlRba1CvPWC0cGzJyMO+gECv0S2CWfYtZ+AY0xUKosGfW1MmjvdWdnCfg== 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=AnSfTsUB; 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 A0819606A32D; Sat, 7 Nov 2026 14:26:37 +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=AnSfTsUB Received: by smtp.kernel.org (Postfix) with ESMTPSA id 228AF1F0089F; Sat, 7 Nov 2026 14:26:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794061597; bh=nhUB9GKd/KDiKFZteUQuufyt1ys7MLtDTMcAyQaCFM4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=AnSfTsUBRST0yd/Z5aPTeBX+vAp0vIMIzpHhZixnkiRIB3tcBEOTUli4RkOf9Ovlb TNJkanhE6I+YJ4DIhoM+IBdU9YfHnxBDMfFcGNsIgCst2ah1/Q7XrM22ECpvwAsD4H fwhYlqI/0hCfmd0kyZW02PISShqOQOv9mHhfn2To= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joseph Qi , Andrew Morton , Heming Zhao , Mark Fasheh , Joel Becker Subject: [PATCH 6.12 0671/1536] ocfs2/dlm: hold the lookup reference across convert AST enqueue Date: Sat, 7 Nov 2026 08:44:47 -0500 Message-ID: <20261107135016.330644606@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134957.653319350@linuxfoundation.org> References: <20261107134957.653319350@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joseph Qi commit 125fe08ff6cfa064e1212f586f01993ee45c0330 upstream. dlm_convert_lock_handler() drops the reference it took when it found the lock on res->granted at its leave label, one statement before it calls dlm_queue_ast(). dlm_free_dead_locks() takes res->spinlock and drops the list and base references, so a peer death landing in that gap leaves the handler's own put as the one that frees the lock, and __dlm_queue_ast() then reads lock->lockres from freed memory. The handler is registered next to dlm_create_lock_handler(), so a convert message buffered on a dying peer's socket arrives on the same o2net receive work that o2net_disconnect_node() does not wait for. The two can interleave as follows, with the reference counts as they are before this fix: Socket data-ready Node-down thread Receive worker ----------------- ---------------- -------------- o2net_data_ready() select sc under callback read lock o2net_disconnect_node() queue shutdown begin flush; new color queue sc_rx_work in the new color release callback lock shutdown socket flush returns read buffered convert_lock dlm_convert_lock_handler() find lock on res->granted dlm_lock_get() refs = 3 lock res->spinlock __dlmconvert_master() call_ast = 1 unlock res->spinlock DLM node-down cleanup lock res->spinlock dlm_free_dead_locks() unlink lock put list ref refs = 2 put base ref refs = 1 unlock res->spinlock dlm_lock_put() refs = 0 free lock dlm_queue_ast() __dlm_queue_ast() read lock->lockres (use-after-free) __dlmconvert_master() only moves the lock between lists, so the count entering the gap is base, list and lookup. Drop the lookup reference after the AST is queued instead of before it and the race ends with the one __dlm_queue_ast() took, which dlm_flush_asts() releases later with ast_pending cleared and ast_list unlinked. No extra get is needed, and the normal case ends with the same count as before. dlmconvert_master() has the same shape but is only reached from dlmlock() for a lock this node owns, which dlm_free_dead_locks() never matches. Link: https://lore.kernel.org/20261014112321.2955584-1-joseph.qi@linux.alibaba.com Fixes: 2c5c54aca9d0 ("ocfs2/dlm: Add missing dlm_lock_put()s") Signed-off-by: Joseph Qi Signed-off-by: Andrew Morton Reviewed-by: Heming Zhao Cc: Mark Fasheh Cc: Joel Becker Cc: Signed-off-by: Greg Kroah-Hartman --- fs/ocfs2/dlm/dlmconvert.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) --- a/fs/ocfs2/dlm/dlmconvert.c +++ b/fs/ocfs2/dlm/dlmconvert.c @@ -534,15 +534,19 @@ int dlm_convert_lock_handler(struct o2ne } leave: - if (lock) - dlm_lock_put(lock); - /* either queue the ast or release it, if reserved */ if (call_ast) dlm_queue_ast(dlm, lock); else if (ast_reserved) dlm_lockres_release_ast(dlm, res); + /* + * Keep the lock alive through AST enqueue: a concurrent + * dlm_free_dead_locks() drops the list and base references. + */ + if (lock) + dlm_lock_put(lock); + if (kick_thread) dlm_kick_thread(dlm, res);