From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (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 209493FC5D9 for ; Fri, 26 Jun 2026 16:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782491762; cv=none; b=E8RxES74/8KlTSUuVWnprGGIPLB0XuB/ewZdGURXQ+dtEM1t/8B6tBIdhg5JXXfAcT4MpFgyphBztGy6oHmdUXcKuS/2S2N5Dg06aNOZXlMfQigGHSO2HFMqSU6Q4bl/xwbdJcCzj9HnZIA81cF3vl+SiQXEKpW0ym3B7JMVV9k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782491762; c=relaxed/simple; bh=jfKMfNtA0m2tzWAAaJhQh72SwYzYGPRTh1/ufIvgsvY=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QxwuSI9NaG4fzVfR2Z59NZHXYsaHlLUj9tTN9mJSuDTLho/ED2UDqSAWJa8e4HUw2x20SJmxRRlU/ph6oQiR5T3HeHxvi1NiKG840+puH5o9h4WSbpeqN3bp5WXknZukPBbfjfsqiKhsAnEyv74zCf6i8X2Xw8RnXpvJeRguQ/Y= 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=q0hW2IO/; arc=none smtp.client-ip=209.85.128.54 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="q0hW2IO/" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-490b3637b90so7678625e9.3 for ; Fri, 26 Jun 2026 09:35:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782491758; x=1783096558; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=l+4pZ54hLA2erkBLlLpycb2Ho8SVAKzZfrHin6zD0vY=; b=q0hW2IO/GrwT+uAMmBU4TREeOiXUHrv13fY8ZaCbIDcGOKwZBdaswKa3thqgcKFCHH Xu4IAC/i+TqS8F3if9219TtQuBHA7SGma3enYHgP+NBWizO2o1UItF6F1KyH+/rEfh+9 jOxHmgvjTQhhWYlGaDCpTe295IzifHPY8fIa71pdsRLHR/RS+4f34WYpStMQVArfCMQZ WKClu2BvUEehcgkKzbJPwj1z15KypFa4WKNI5yXL6OH3NeAa5/k9mSH62O2dP7/WmWyc KMvmZmzYjj+0Htt6XnAxtcN4fdyNHsxGhX8DSk5viHH2m8L9y1Fc3KtXPn0hedHnEo3k 8iJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782491758; x=1783096558; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=l+4pZ54hLA2erkBLlLpycb2Ho8SVAKzZfrHin6zD0vY=; b=pmM+xtkEEvLAj7aDqoXSeUU3/g8QzNsUPsoW7hyKOuEfDMJERDyOynLM1XxTJeUWBG hLbQmmBw0f7Rmr38eRq3+iZ/UzhVNgS6Av/tOMX1IXS7a407ZJ4k9DwJw71aqEkE1Q0q CbPn7S9Z2VfNiPnkDHhLkFPRxcEmAfEwoTxNzDyB1cZJEv4gLzfcVLNUB6cqGUNAzWrZ B/05c6yt/fgdOVpT4E8W1qgBjFvXg0UekeCYggnYZCr+TMnwOeEh5QT0acNx/C3S+c8r XOCjh/hYZXuqeW86B7U8GFdnBZIIEBd3lFAKnu3OkcvZgoxpPGaQJyWnFDjN2CQq3nae 8PKw== X-Forwarded-Encrypted: i=1; AFNElJ/1XACrTpjbPyp2/qz65lHvac58wZfcsScrewgPHOKydioq/xj/zbe8lHmeBmT4VmaMhcy4qpYcZZjpC5w=@vger.kernel.org X-Gm-Message-State: AOJu0Yx/NMIx/Owx8AUG0bvKLCDkZVELkMdo5YEUkG604nZ1wc0y7ab9 Rd0iFKLv6RN/t/JAijAlN9lYcqZqEdG5HKhKRoDek2VyjUtoSDOCkwhC X-Gm-Gg: AfdE7cmIxVU+FJ4HXS9Vt5Xr5L0DeH3WGsag8Z1lljXdT49X0kaJRSm5MLsIC3ekTq1 xr/Kj1q7hto4zZ/+CS19v+IcGT8e8dqzbVTPvNnOYHr4zGR3byTcwfuC65KJVw2DK7fscFH+YHu x80vwumHBE1mJJIVmQCpHgov+hBOAWy48AT8pHUwcIw/gg+CzXvquVgwhxnMyrQXS+bcbUzMdf4 ZAJh37lnaCpmWGGRYagdDjFrfohK5JjD8r7Ist58+RrQBB1qK1K1GhVo5LzAllXuxl/hbVcvmO2 GMmRXspaLLEfkzmjvY9R60Y9dvy19Q+/w7r/Uyy/Lpt54PpbCtyA4vnSAQiKKGXnOtjSNRDxy3D Ru1WWRc/LDZB8ZvmqA3D3iMawstlMGS9A6UPVkmTxPO0/U5KFt86e04wigU29wa54kZ+uKHooWl nB1iUGDXIv5dXHk5jlA5VPeY5sucmerm8C9Af/i7u+jz+AYBljY7LL+FKk8p4Z X-Received: by 2002:a05:600d:6452:10b0:492:1e36:85dc with SMTP id 5b1f17b1804b1-4926689ac37mr92438895e9.36.1782491758352; Fri, 26 Jun 2026 09:35:58 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49268ffe204sm92361655e9.7.2026.06.26.09.35.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jun 2026 09:35:57 -0700 (PDT) Date: Fri, 26 Jun 2026 17:35:56 +0100 From: David Laight To: Russell King Cc: Linus Walleij , slipher , Nathan Chancellor , Kees Cook , Sami Tolvanen , "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" , "regressions@lists.linux.dev" , "linus.walleij@linaro.org" Subject: Re: [REGRESSION] 32-bit ARM's BKPT instruction no longer works Message-ID: <20260626173556.0535ffe5@pumpkin> In-Reply-To: References: <20260626145356.4183d8c5@pumpkin> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, 26 Jun 2026 16:38:02 +0100 Russell King wrote: > On Fri, Jun 26, 2026 at 02:53:56PM +0100, David Laight wrote: > > On Fri, 26 Jun 2026 14:53:56 +0200 > > Linus Walleij wrote: > > =20 > > > [Adding Nathan and Kees so we can figure out how best to deal with th= is] > > >=20 > > > On Sun, Jun 21, 2026 at 9:15=E2=80=AFPM slipher wrote: > > > =20 > > > > Consider the C program for 32-bit ARM architectures: > > > > > > > > > > > > int main() { > > > > __asm__ __volatile__ ("BKPT"); > > > > return 0; > > > > } > > > > > > > > Expected behavior is that this raises SIGTRAP. Since Linux 6.10 thi= s no > > > > longer happens; instead execution perpetually resumes at the same > > > > instruction, using 100% of CPU. It does not matter whether GDB is > > > > attached. I have tested with an armv7l CPU, but I imagine any other > > > > variants with the BKPT instruction would be equally affected. > > > > > > > > I believe the culprit to be commit > > > > c3f89986fde7bb9ccc86a901bf28e1f7d69fc3b3 "ARM: 9391/2: hw_breakpoin= t: > > > > Handle CFI breakpoints". The commit defines the method-of-entry co= de 3 > > > > as "ARM_ENTRY_CFI_BREAKPOINT", but this is the code used for any BK= PT > > > > instruction - see > > > > https://developer.arm.com/documentation/ddi0379/a/Debug-Register-Re= ference/Control-and-status-registers/Debug-Status-and-Control-Register--DSC= R-?lang=3Den > > > > "Method of Debug Entry (MOE), bits [5:2]". If the CFI option is dis= abled > > > > in the kernel config, hw_breakpoint_pending() returns 0 indicating= the > > > > breakpoint was handled, but takes no action. So breakpoints cannot = be > > > > used by user-space code, regardless of how CONFIG_CFI is set. The b= log > > > > post > > > > https://www.jwhitham.org/2015/04/the-mystery-of-fifteen-millisecond= .html > > > > gives a nice overview of the control flow in older, working kernels= . =20 > > >=20 > > > Does simply reverting the patch solve the issue? > > > =20 > > > > The following Systemtap script can be used to demonstrate that the > > > > ARM_ENTRY_CFI_BREAKPOINT path is used, when running the above C pro= gram. =20 > > >=20 > > > Yeah it's definitely that one causing it. > > >=20 > > > I sent the naive solution to it, and before anyone point it out: no i= t does > > > not allow custom breakpoints to be mixed with kernel CFI, but it > > > probably makes legacy systems work on newer kernels since they > > > probably don't select CFI. > > > https://lore.kernel.org/linux-arm-kernel/20260626-arm32-cfi-bug-v1-1-= a467b5050c0b@kernel.org/T/#u > > >=20 > > > I understand that this is not solving everything. =20 > >=20 > > I'm confused. > > Why would building a kernel with CFI (to check kernel indirect calls) > > change the behaviour of executing anything in userspace? > >=20 > > If userspace is compiled with CFI and gets an equivalent fail then you'd > > (probably) want a fatal signal - but isn't that entirely unrelated to > > the kernel code. > > Do those checks even need kernel support? I know shadow stacks do. =20 >=20 > CFI generates instructions that can check the type of the function > against the caller. It appears that on 32-bit ARM, Clang close that, > in the case of a mismatch, it would cause a BKPT instruction to be > executed. >=20 > Linus' code in commit c3f89986fde7 ("ARM: 9391/2: hw_breakpoint: > Handle CFI breakpoints") added code to handle this BKPT use. >=20 > However, we now have a regression reported as a result of that commit > where there is a userspace program that has explicit BKPT instructions > encoded within it, and the program relies on the kernel behaviour that > was introduced in f81ef4a920c8 ("ARM: 6356/1: hw-breakpoint: add ARM > backend for the hw-breakpoint framework") in 2.6.37 - and this "new" > behaviour is conditional on CONFIG_PERF_EVENTS being enabled - where > it raises a SIGTRAP. >=20 > Prior to this commit, or whenever CONFIG_PERF_EVENTS is disabled, the > kernel will raise a SIGBUS instead. >=20 > Both SIGTRAP and SIGBUS are "forced" signals - the kernel will force > them to be delivered to the program irrespective of whether the program > has blocked or ignored these signals, since this is the kernel trying > to save the system (because it doesn't know how to handle it.) >=20 > Moreover, BKPT was only introduced around the ARMv5TE era, and the > FSR code for it was only added in later architecture reference manuals, > changing an existing FSR code from an implementation defined "Terminal > Exception" to an architecturally defined "Debug Exception". >=20 > Support for this "Debug Exception" was only added with patch 6356/1, > but that did not handle the BKPT instruction. Linus' commit above > (9391/1) added support for the CFI case, but meant that userspace > would now spin on a BKPT instruction rather than force a signal, > thereby causing the regression. >=20 > We can't fix BKPT handling - this userspace program relies on the fact > that the kernel doesn't handle this instruction (for example, it relies > on the PC not being advanced) and advancing the PC by one instruction > after a SIGTRAP handler returns may not be the correct way to handle > it anyway. Consider BKPT being used as an "assert" type context, where > the compiler doesn't expect execution to continue, and a literal pool > following the instruction. >=20 > We are now stuck with the sorry state that BKPT is, and as I have said > many times now, BKPT should be avoided - it's an utter trainwreck. The > only sensible use that BKPT has is with a hardware debugger that traps > the BKPT entry into debug mode (a special hardware debugger mode that > the CPU enters which software can't see). >=20 I'd probably forgotten a bit in the middle of that. (Possibly backing up the pc.) I guess it would need a flag in an elf header/section to set the behaviour on a per program basis (horrid). David