Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC5EA16A956 for ; Wed, 18 Sep 2024 07:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726644022; cv=none; b=NQmcnhDwlnACr+Bz7fGl/xqq8oQPZfaaTwKxXQ8Fu0Tjq/g6ioquQ8IacFuXhq9hw9gtdy669CdhOjhVWx5jVBIuN6x0XZP9PstDa3lSAmEBq5KnKV/Nq4HD/K0BkiSrtLDn7o0QuVZCzfXe2jDcwRjoqWcH64pL6bDDDj0Vxbo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726644022; c=relaxed/simple; bh=Zn01ijBDWMI+2dmryCoYs+Yy1lunQ7Sq2McQW1xv9wg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=J+XiMKT93zGrItlRhOcLrLW/kH2crtBrTFycZ0/w3Z4SVx7NUfCgZ9kII/9MMT3qV0lnFCVp4uxEGI+UqJNVRcJK+VK76KU7NDT7IWAZk4gBzFikeKnXlKXwDRzoVfl36unT+MZpOA5I4eolYI7CV0clgk2ed9X/x552uwSigt0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VStmioaj; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VStmioaj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DA7DC4CEC3; Wed, 18 Sep 2024 07:20:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1726644022; bh=Zn01ijBDWMI+2dmryCoYs+Yy1lunQ7Sq2McQW1xv9wg=; h=From:To:Cc:Subject:Date:Reply-to:From; b=VStmioaj8a8iNAkiaRCYtgz1GNJQNooBViUgqcX48Im6BfB+KxaAZLi7UKMDMzQia xkcs/S7KJf+gEWUkoOhfu1Q4CKHkgj/vk8u9TvRM8vy69/bWbNsjEd8xM1gXghH/Lb 19QDynW6DryV54VH1hlBLKRfpBvfrDi6H4PMSCLA= From: Greg Kroah-Hartman To: linux-cve-announce@vger.kernel.org Cc: Greg Kroah-Hartman Subject: CVE-2024-46797: powerpc/qspinlock: Fix deadlock in MCS queue Date: Wed, 18 Sep 2024 09:17:32 +0200 Message-ID: <2024091856-CVE-2024-46797-9174@gregkh> X-Mailer: git-send-email 2.46.0 Precedence: bulk X-Mailing-List: linux-cve-announce@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Reply-to: , X-Developer-Signature: v=1; a=openpgp-sha256; l=6264; i=gregkh@linuxfoundation.org; h=from:subject:message-id; bh=Zn01ijBDWMI+2dmryCoYs+Yy1lunQ7Sq2McQW1xv9wg=; b=owGbwMvMwCRo6H6F97bub03G02pJDGmv6jKu6DdcdKmcwGKbzMn7ZK/op7qA9pOV94qf7t3K9 Jzlyt6ejlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZiIdyTDHA7pCkcmz9Qumw3H fAVKtV+5KN57w7BgM3/chxsrA9yPsJpIZmrNNFdSmrQQAA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Description =========== In the Linux kernel, the following vulnerability has been resolved: powerpc/qspinlock: Fix deadlock in MCS queue If an interrupt occurs in queued_spin_lock_slowpath() after we increment qnodesp->count and before node->lock is initialized, another CPU might see stale lock values in get_tail_qnode(). If the stale lock value happens to match the lock on that CPU, then we write to the "next" pointer of the wrong qnode. This causes a deadlock as the former CPU, once it becomes the head of the MCS queue, will spin indefinitely until it's "next" pointer is set by its successor in the queue. Running stress-ng on a 16 core (16EC/16VP) shared LPAR, results in occasional lockups similar to the following: $ stress-ng --all 128 --vm-bytes 80% --aggressive \ --maximize --oomable --verify --syslog \ --metrics --times --timeout 5m watchdog: CPU 15 Hard LOCKUP ...... NIP [c0000000000b78f4] queued_spin_lock_slowpath+0x1184/0x1490 LR [c000000001037c5c] _raw_spin_lock+0x6c/0x90 Call Trace: 0xc000002cfffa3bf0 (unreliable) _raw_spin_lock+0x6c/0x90 raw_spin_rq_lock_nested.part.135+0x4c/0xd0 sched_ttwu_pending+0x60/0x1f0 __flush_smp_call_function_queue+0x1dc/0x670 smp_ipi_demux_relaxed+0xa4/0x100 xive_muxed_ipi_action+0x20/0x40 __handle_irq_event_percpu+0x80/0x240 handle_irq_event_percpu+0x2c/0x80 handle_percpu_irq+0x84/0xd0 generic_handle_irq+0x54/0x80 __do_irq+0xac/0x210 __do_IRQ+0x74/0xd0 0x0 do_IRQ+0x8c/0x170 hardware_interrupt_common_virt+0x29c/0x2a0 --- interrupt: 500 at queued_spin_lock_slowpath+0x4b8/0x1490 ...... NIP [c0000000000b6c28] queued_spin_lock_slowpath+0x4b8/0x1490 LR [c000000001037c5c] _raw_spin_lock+0x6c/0x90 --- interrupt: 500 0xc0000029c1a41d00 (unreliable) _raw_spin_lock+0x6c/0x90 futex_wake+0x100/0x260 do_futex+0x21c/0x2a0 sys_futex+0x98/0x270 system_call_exception+0x14c/0x2f0 system_call_vectored_common+0x15c/0x2ec The following code flow illustrates how the deadlock occurs. For the sake of brevity, assume that both locks (A and B) are contended and we call the queued_spin_lock_slowpath() function. CPU0 CPU1 ---- ---- spin_lock_irqsave(A) | spin_unlock_irqrestore(A) | spin_lock(B) | | | ▼ | id = qnodesp->count++; | (Note that nodes[0].lock == A) | | | ▼ | Interrupt | (happens before "nodes[0].lock = B") | | | ▼ | spin_lock_irqsave(A) | | | ▼ | id = qnodesp->count++ | nodes[1].lock = A | | | ▼ | Tail of MCS queue | | spin_lock_irqsave(A) ▼ | Head of MCS queue ▼ | CPU0 is previous tail ▼ | Spin indefinitely ▼ (until "nodes[1].next != NULL") prev = get_tail_qnode(A, CPU0) | ▼ prev == &qnodes[CPU0].nodes[0] (as qnodes[CPU0].nodes[0].lock == A) | ▼ WRITE_ONCE(prev->next, node) | ▼ Spin indefinitely (until nodes[0].locked == 1) Thanks to Saket Kumar Bhaskar for help with recreating the issue The Linux kernel CVE team has assigned CVE-2024-46797 to this issue. Affected and fixed versions =========================== Issue introduced in 6.2 with commit 84990b169557 and fixed in 6.6.51 with commit d84ab6661e8d Issue introduced in 6.2 with commit 84990b169557 and fixed in 6.10.10 with commit f06af737e4be Issue introduced in 6.2 with commit 84990b169557 and fixed in 6.11 with commit 734ad0af3609 Please see https://www.kernel.org for a full list of currently supported kernel versions by the kernel community. Unaffected versions might change over time as fixes are backported to older supported kernel versions. The official CVE entry at https://cve.org/CVERecord/?id=CVE-2024-46797 will be updated if fixes are backported, please check that for the most up to date information about this issue. Affected files ============== The file(s) affected by this issue are: arch/powerpc/lib/qspinlock.c Mitigation ========== The Linux kernel CVE team recommends that you update to the latest stable kernel version for this, and many other bugfixes. Individual changes are never tested alone, but rather are part of a larger kernel release. Cherry-picking individual commits is not recommended or supported by the Linux kernel community at all. If however, updating to the latest release is impossible, the individual changes to resolve this issue can be found at these commits: https://git.kernel.org/stable/c/d84ab6661e8d09092de9b034b016515ef9b66085 https://git.kernel.org/stable/c/f06af737e4be28c0e926dc25d5f0a111da4e2987 https://git.kernel.org/stable/c/734ad0af3609464f8f93e00b6c0de1e112f44559