From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qt1-f180.google.com (mail-qt1-f180.google.com [209.85.160.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0CD0440D597 for ; Mon, 29 Jun 2026 02:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782698464; cv=none; b=oq8NGNueXOefC7Iws+DJMgsctdesSt8ib4zizrQW3rFvR+x/oHVx5Z8XL6OOgJEHsh6AkRJG9YmVyGmfSI4Jv2nDcJlxasj0TmXJyxBb0tf1p/XiA6F9ncwhdj0ljNEGkltrdhofsDfL3dr5UqwEsYFdavXSLKetPnCM4aulDw8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782698464; c=relaxed/simple; bh=fwrrwpH/BaEHJXAYBdgKN08KqhTO8F9+wHs087B12qo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=sKzi+LpUUulselKs1cmiazfThv1tbUJFU8PggkSW/+pv34Rse+opvms1sHAJp9KGJ30DFefXBSn+EYX+aC0MTCFoOh+7Rykv4TM1HoRvFuZ5p5K8Ze8iKGMtqiwVTKgwxB1C4uWG6iBZt5ZYwb6/RCQCKVyleG5uK01qH/Ywbmo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Y10Lm0kJ; arc=none smtp.client-ip=209.85.160.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Y10Lm0kJ" Received: by mail-qt1-f180.google.com with SMTP id d75a77b69052e-51a868b6962so35193501cf.2 for ; Sun, 28 Jun 2026 19:01:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782698461; x=1783303261; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Wh4ZvE2Ba8epM6KIDao30fstJWHE57U07EByhetTANg=; b=Y10Lm0kJen4ntLA2Td0avdjPtfoKKDIWoNw1tsqcCqWVvVGFunSrUI50H9NdpQFKCu xPwhTMXP5kyqv5nDPmYHK0hWNXcNu8otFhV8nwtHesGzyue13Ja1IV5d1BHoDCPsU9Sh BdPhzOfXbVED9qDtgcEDVwA7ivoGRAPc+lWdtvqNUjBHFlB+Aze20c3uQ/RodF7npx+K geWZRugFPQOG6OA2jHcCwugCklIOovFywbh/mWkF/ISZZFJcxg/mCKBO9qrhwHJqBlx+ j8CJ08kSWLwXrnLG+cd7691hNqAiGWQSchFwWWBUllF4bZJVrfhilyDa1YL4E/aYur/X TqCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782698461; x=1783303261; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Wh4ZvE2Ba8epM6KIDao30fstJWHE57U07EByhetTANg=; b=Vvpdvz0mOxOIm8tXYKXhSmsqnZLpPswQfQEHKrVXYnmPWnTaQGJoBlSNXqP/6CJ4uK FklE2lonaQMoXuuv4Qec56cEvVSHDaSJkZeIEoLB8lcYziiLqpZQK/dgw0ZqC2pxlLLH Eit1VjFOxl70347n4nf9VAQN/XshuYCFVhWixXoz8Pk/GNxhnh+J0T9Kz6sHo5DmExqT Z69+F9tno4jZzOMOpZ8gdBIGOZJhbGQM1R4fY9xQG1arvUUwULTAQkO3FyL1BgT85JJw fVoiRc8X4O6mOGdgD7nsDMVA5IJpzS4IZmSr3e1atQrrxucJLoixtnL80efBc3r44iXP f4sA== X-Forwarded-Encrypted: i=1; AFNElJ8Li87JhEjJUnF7L3SlXef4ZF7iABufx9rg5sSWbWQAKOT1A1d9FfKyB1aPmEf4VQ/du8sxI7Oz66crxqc=@vger.kernel.org X-Gm-Message-State: AOJu0Yz0c3nImk4gsXWxmIFpesA1X5xAn31tllWkrldROBI1bUtbMkc4 hVHjFmawRC92HAXhsEm1jW1v3twM0rfRA/YLWfv4IrBSCM2a+OHXAoDm X-Gm-Gg: AfdE7ckHK0RcbX7dBZc8yvJge4P5th1Htu/4HkS5ZaV4MpmAMcsKqNNVNCqsDNTeFjI DlR53rt5b4NV7PNCRJgc9K0h2uktXrc5YCNakKduUIRbNYsbACrpjYt1X3XAr6IeTkYW8pHEd8a 4bBh0JOdiMmIToMklH2fLIsh8jAtSsyHuULJ3yViPEc0pVPgKTxbB3rlJ8P3DpAAv6XCCYu6MWm 2OtwKnBP7paW8NXShdh8kQPHR56tjC3fhIBT7z52S/cVbmd173gQU+8LP1AbmrFF1U0xBaoMf+t /ehxvzZr32iJWduaWMbogktsiwn56O5LxM9cvTj0WooeA0VvCdjqL0YxzJTkG7ZHASO/LrS4Cej lhlzXkZwxTMf3LKcvtyLmRECA7qqkoSYwhF6TjwHNLjK3YlKFQSOpBJA8zuhxfUL+vCVlwIjp1W TutAUSommmgZDuML5BYeapIG5bd/WY8Ud9xNWM1AtejYOtPmpOEoZ+LYLen7lYPoGnufo6Sek3N JDWnUW1a18ilvGXHo6+6uHYSGQnSi4+ X-Received: by 2002:a05:622a:2d3:b0:519:55c0:a1e5 with SMTP id d75a77b69052e-51a726e2a09mr192133211cf.8.1782698460639; Sun, 28 Jun 2026 19:01:00 -0700 (PDT) Received: from server0.tail6e7dd.ts.net (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8f03e035a77sm14362436d6.8.2026.06.28.19.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Jun 2026 19:01:00 -0700 (PDT) From: Michael Bommarito To: Thomas Gleixner , Ingo Molnar , Peter Zijlstra Cc: Darren Hart , Davidlohr Bueso , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Ji'an Zhou , linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev Subject: [PATCH] futex/requeue: Clean up requeue state on the self-deadlock path Date: Sun, 28 Jun 2026 22:00:49 -0400 Message-ID: <20260629020049.2082397-1-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit futex_requeue() can reach the self-deadlock check after get_pi_state() has taken a reference for the waiter and futex_requeue_pi_prepare() has set this->pi_state and moved the waiter's requeue_state to Q_REQUEUE_PI_IN_PROGRESS. The check returns -EDEADLK and breaks out of the requeue loop without undoing any of that, unlike the sibling rt_mutex_start_proxy_lock() failure path which clears this->pi_state, drops the reference with put_pi_state() and calls futex_requeue_pi_complete(). The extra pi_state reference is therefore leaked (the post-loop put_pi_state() only balances the initial reference taken in futex_proxy_trylock_atomic()), and the waiter is left in Q_REQUEUE_PI_IN_PROGRESS. When that waiter is next woken on the source futex it enters futex_requeue_pi_wakeup_sync() and waits for a requeue completion that never comes, since futex_requeue_pi_complete() was skipped; on a !PREEMPT_RT kernel this is an unkillable busy-spin that pins a CPU. The path is reachable by an unprivileged FUTEX_CMP_REQUEUE_PI that requeues a non-top waiter which already owns the target PI futex. Make the -EDEADLK path perform the same cleanup as the rt_mutex_start_proxy_lock() deadlock path. Fixes: 74e144274af3 ("futex/requeue: Prevent NULL pointer dereference in remove_waiter() on self-deadlock") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- Built x86_64 with W=1, no new warnings; checkpatch --strict clean. Reproduced with an unprivileged user program under QEMU/KVM: the triggering FUTEX_CMP_REQUEUE_PI leaves the requeued owner spinning permanently in futex_requeue_pi_wakeup_sync() (requeue_state stuck at Q_REQUEUE_PI_WAIT) and kmemleak reports the leaked futex_pi_state. With this patch the requeue still returns -EDEADLK, but the waiter no longer wedges and kmemleak is clean. The futex selftests pass and are unchanged from the unpatched kernel. kernel/futex/requeue.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kernel/futex/requeue.c b/kernel/futex/requeue.c index 7384672916fb6..73ca06ec32454 100644 --- a/kernel/futex/requeue.c +++ b/kernel/futex/requeue.c @@ -648,6 +648,9 @@ int futex_requeue(u32 __user *uaddr1, unsigned int flags1, /* Self-deadlock: non-top waiter already owns the PI futex. */ if (rt_mutex_owner(&pi_state->pi_mutex) == this->task) { ret = -EDEADLK; + this->pi_state = NULL; + put_pi_state(pi_state); + futex_requeue_pi_complete(this, ret); break; } base-commit: f24ca6729076623c9a0547ecc71e4fc1c4b65c3c -- 2.53.0