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=1796387571; b=PBe8kivGzbbIRqBWuJjV9Pv3LvcnEccU1KxCOscNAoBppiT9HnuF44aujt4xxf0wkibO X2B5Y6YG2NkQv/aI5qmhtUYpFQAQYnDGYSPUTPobDf9CaJC4B2He4JKbtMK5KM5LyAxpl 6t4UHlcWQ1AvemnCOFXIKwiDSbFGdnIY0o8fEmXD47phNSsD42WD1qO/NbSHY4K5OyMUD 7b+EkxfrggocCaW6oebrmTROIrTvsdLWY+1mViYsKjCB6fpsbDQnQBnsfvR+bxkmddRee rqvFcmHbnbRq0kRugaGJ5iCUCKqmObc5xNHdBLLZMoVGbKxuVzPK13FsGdYqISxjGiw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387571; 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-Type:Content-Transfer-Encoding; bh=EP2tM6on3toyqBr9SOyFLUArTB5jCWuoy5fp3qlhdUI=; b=4PloZY16xD4HVjBZzFdcf6ONGXmvudRqz4JqjWsmWxBBSokMEhAVCL9tfRbWmLBgTHqn W2IlpPzc0yM9wM4oz3/a+p+0g4atQsQEjDbQdDWoPbE5UKmCHML3juh8gUc0LV0KhOUkR b7jDC5kbR7d9IJyWWsulkbm9PHTOJ4fXxC1aT47v7dNl+ukfBNa6z7D8IgNeY0I/8BN4R DqPtU5/FU+UdSy+Opa4CaDIx+zU+O4GW0DdS+FQF5D/NS1jtqSQZvLhougnixG8skm4mF MGkIKSGVEwq07W98sdaAWGsvY62CMcmKvo5gu3G7+mHbTtgz613fZkG4NWs5ZumYAKw== 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=M7Fj9k7z; 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 9380E606A322; Fri, 4 Dec 2026 12:32:51 +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=M7Fj9k7z Received: by smtp.kernel.org (Postfix) with ESMTPSA id 078B41F000C2; Fri, 4 Dec 2026 12:32:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387571; bh=EP2tM6on3toyqBr9SOyFLUArTB5jCWuoy5fp3qlhdUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=M7Fj9k7zyLN6q5x1X0OIVJe9ZlMBEYePulovugUrN0ibi/1/VzQglMBrpq44wuqde q/47/AA9O4dsHKYOqX2kO6bUrqmWxe8vDMGO8TsTsrSARgobQzmuDr6uTUSCjvvIJy Hh/bJQZlrzPeJsSGD7XFeepygbUO27j6fACy9VKY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Michal=20Such=C3=A1nek?= , "Christophe Leroy (CS GROUP)" , Hari Bathini , Shrikanth Hegde , Samir Mulani , Madhavan Srinivasan , Sasha Levin Subject: [PATCH 6.1 0300/1059] powerpc/ftrace: Dont restore r13 during ftrace_regs_caller Date: Fri, 4 Dec 2026 18:57:11 +0900 Message-ID: <20261204100652.044825504@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shrikanth Hegde [ Upstream commit af5f0870883ae4aea7f668d06cbb7ad0e12824c8 ] Michal reported a stack-protector failure and subsequent panic when running kernel builds. This was observed with full/lazy preemption. Initially it was suspected as KVM, but later turned out to be due to a bcc tool running in parallel. Issue was recreated using a bcc tool. For example, running below in parallel leads to crash. ./funccount sched* -d 100 and make -j 64 The same crash was observed when running kprobe for schedule() function, while simpler function tracer for schedule() didn't cause the crash. This helped to narrow it down to ftrace backed kprobes area. The crash occurs as follows: ftrace_regs_caller entry on CPU A | +-> save r13 = CPU A PACA into pt_regs | +-> call kprobe_ftrace_handler() | +-> ftrace_test_recursion_unlock() | +-> preempt_enable +-> task can schedule and migrate to CPU B +-> task resumes with live r13 = CPU B PACA | +-> REST_GPRS(2, 31) | +-> restore saved r13 = CPU A PACA | |-> The task then continues running on CPU B with r13 pointing | to CPU A's PACA. The stack-protector canary is accessed through the PACA. After the task migrates, CPU A may run a different task and update its PACA with that task's canary. Restoring the saved r13 then causes the migrated task's saved stack canary to be compared against the canary in CPU A's PACA, resulting in a stack-protector failure. Similarly, current is resolved through the PACA. With a stale r13, preempt_count() can access the state of the task referenced by CPU A's PACA instead of the task running on CPU B. This results in corrupted preempt-count warnings and scheduling-while-atomic failures. This path for example is called when using kprobes and parallel kernel builds can cause preemptions during ftrace_test_recursion_unlock. Do not restore r13 from the saved register frame. If the task did not migrate, the live r13 already has the saved value. If it migrated, the live r13 contains the correct PACA pointer for the CPU on which the task resumed. On PPC32, r13 is regular register. So do this fix only for PPC64 Fixes: 153086644fd1 ("powerpc/ftrace: Add support for -mprofile-kernel ftrace ABI") Reported-by: Michal Suchánek Closes: https://lore.kernel.org/all/aqKfsVArHHaIK6M9@kunlun.suse.cz/ Reviewed-by: Christophe Leroy (CS GROUP) Reviewed-by: Hari Bathini Signed-off-by: Shrikanth Hegde Tested-by: Samir Mulani Signed-off-by: Madhavan Srinivasan Link: https://patch.msgid.link/20260921072151.35531-1-sshegde@linux.ibm.com [ sashal: Applied the upstream hunk to ftrace_mprofile.S instead of ftrace_entry.S, which doesn't exist on this branch; the surrounding context is otherwise identical. ] Signed-off-by: Sasha Levin --- arch/powerpc/kernel/trace/ftrace_mprofile.S | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/powerpc/kernel/trace/ftrace_mprofile.S b/arch/powerpc/kernel/trace/ftrace_mprofile.S index f4a72b38488f7..74f7edff9eece 100644 --- a/arch/powerpc/kernel/trace/ftrace_mprofile.S +++ b/arch/powerpc/kernel/trace/ftrace_mprofile.S @@ -129,7 +129,13 @@ /* Restore gprs */ .if \allregs == 1 +#ifdef CONFIG_PPC64 + REST_GPRS(2, 12, r1) + /* Do not restore a stale PACA pointer if the task migrated */ + REST_GPRS(14, 31, r1) +#else REST_GPRS(2, 31, r1) +#endif .else REST_GPRS(3, 10, r1) #ifdef CONFIG_LIVEPATCH_64 -- 2.53.0