From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 482DE2222CB for ; Wed, 20 Aug 2025 15:32:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755703948; cv=none; b=kpqUI8mYRn9Cxu7NiTh2nf1JnEvFPtdp2eJ6ybcxUlfI+B98WTBwv9yPvNkW1zT3Y3gCE6YEe/PwSZRDM130iL0Vy3zAZPQdRo7aidN/CxFCkdIFKijO6epXvPGUDiCpnBw2PwQmar7YyhGWb54a2SNL/5T+kZ3aris8XZVMtxY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755703948; c=relaxed/simple; bh=Oj2rUQPBTbVXCNonKJQVBRB6l9mgFlzgEV5PABAQRKQ=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=li1m6Zst9ArdB/VjThEpFQ2F1zfUHVt3m6puMEnytLvRtPUADWwAPCiOTW++3ceQetojyTqxdT18UJd23K6yip7m2J4TYcgQUHqrGj5jutIehkL0ntVZPBFRpmD1fV13Ip9CeaZExXTpg+dwHEIHYe9JWePzfDU22jC8mZ8O4EQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=l11FYh4a; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="l11FYh4a" Received: from [127.0.0.1] (c-76-133-66-138.hsd1.ca.comcast.net [76.133.66.138]) (authenticated bits=0) by mail.zytor.com (8.18.1/8.17.1) with ESMTPSA id 57KFVpaU3792580 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Wed, 20 Aug 2025 08:31:51 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 57KFVpaU3792580 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2025072201; t=1755703912; bh=kDdPsDC036RlSG5rF5xs5Yi0pdY8GgqS9PqHNG1E8d8=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=l11FYh4adiJZfrKeirIc6V7+vC81ezO819L1ACIFIoEvCol5m0JiUZv2z5QuFyGux qMmFPiQA2PvvWXu+D0ojqOrB4kjcBPmWO+E329bqaZNZjn2LJtaXNPIcP4QJ8pm6E0 kEK9kSzyDDpNw6IEa+ODEs2UwK+IRz/aafYYBThXM6TUUIOiiTLCNmWzn/jBqwEgcz Jv393b7grajs5VWDj1tTrYlpPtAo63A7368kkcZKEkg5QEac0SWS3NJfC1BBRsAGm5 GbQ1i02WHSvcb6cR+Pzr1kIK1rNU/fiaq1i9bDcFrs48exEDuoG8U7WmbTA4ANcr8B IhCLLrkZCzJbQ== Date: Wed, 20 Aug 2025 08:31:48 -0700 From: "H. Peter Anvin" To: Marcos Del Sol Vives , linux-kernel@vger.kernel.org CC: marcos@orca.pet, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, Peter Zijlstra , Kees Cook , "Xin Li (Intel)" , Sabyrzhan Tasbolatov Subject: Re: [PATCH v2] x86: add hintable NOPs emulation User-Agent: K-9 Mail for Android In-Reply-To: <20250820110437.560107-1-marcos@orca.pet> References: <20250820110437.560107-1-marcos@orca.pet> Message-ID: <9EDED468-AB68-4558-8D94-C3756170C364@zytor.com> 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 August 20, 2025 4:04:35 AM PDT, Marcos Del Sol Vives = wrote: >Hintable NOPs are a series of instructions introduced by Intel with the >Pentium Pro (i686), and described in US patent US5701442A=2E > >These instructions were reserved to allow backwards-compatible changes >in the instruction set possible, by having old processors treat them as >variable-length NOPs, while having other semantics in modern processors= =2E > >Some modern uses are: > - Multi-byte/long NOPs > - Indirect Branch Tracking (ENDBR32) > - Shadow Stack (part of CET) > >Some processors advertising i686 compatibility lack full support for >them, which may cause #UD to be incorrectly triggered, crashing software >that uses then with an unexpected SIGILL=2E > >One such software is sudo in Debian bookworm, which is compiled with >GCC -fcf-protection=3Dbranch and contains ENDBR32 instructions=2E It cras= hes >on my Vortex86DX3 processor and VIA C3 Nehalem processors [1]=2E > >This patch is a much simplified version of my previous patch for x86 >instruction emulation [2], that only emulates hintable NOPs=2E > >When #UD is raised, it checks if the opcode corresponds to a hintable NOP >in user space=2E If true, it warns the user via the dmesg and advances th= e >instruction pointer, thus emulating its expected NOP behaviour=2E > >[1]: https://lists=2Edebian=2Eorg/debian-devel/2023/10/msg00118=2Ehtml >[2]: https://lore=2Ekernel=2Eorg/all/20210626130313=2E1283485-1-marcos@or= ca=2Epet/ > >Signed-off-by: Marcos Del Sol Vives >--- > arch/x86/Kconfig | 29 +++++++++++++++++++++++++++++ > arch/x86/kernel/traps=2Ec | 33 +++++++++++++++++++++++++++++++++ > 2 files changed, 62 insertions(+) > >diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig >index 58d890fe2100=2E=2Ea6daebdc2573 100644 >--- a/arch/x86/Kconfig >+++ b/arch/x86/Kconfig >@@ -1286,6 +1286,35 @@ config X86_IOPL_IOPERM > ability to disable interrupts from user space which would be > granted if the hardware IOPL mechanism would be used=2E >=20 >+config X86_HNOP_EMU >+ bool "Hintable NOPs emulation" >+ depends on X86_32 >+ default y >+ help >+ Hintable NOPs are a series of instructions introduced by Intel with >+ the Pentium Pro (i686), and described in US patent US5701442A=2E >+ >+ These instructions were reserved to allow backwards-compatible >+ changes in the instruction set possible, by having old processors >+ treat them as variable-length NOPs, while having other semantics in >+ modern processors=2E >+ >+ Some modern uses are: >+ - Multi-byte/long NOPs >+ - Indirect Branch Tracking (ENDBR32) >+ - Shadow Stack (part of CET) >+ >+ Some processors advertising i686 compatibility (such as Cyrix MII, >+ VIA C3 Nehalem or DM&P Vortex86DX3) lack full support for them, >+ which may cause SIGILL to be incorrectly raised in user space when >+ a hintable NOP is encountered=2E >+ >+ Say Y here if you want the kernel to emulate them, allowing programs >+ that make use of them to run transparently on such processors=2E >+ >+ This emulation has no performance penalty for processors that >+ properly support them, so if unsure, enable it=2E >+ > config TOSHIBA > tristate "Toshiba Laptop support" > depends on X86_32 >diff --git a/arch/x86/kernel/traps=2Ec b/arch/x86/kernel/traps=2Ec >index 36354b470590=2E=2E22b51c4186e7 100644 >--- a/arch/x86/kernel/traps=2Ec >+++ b/arch/x86/kernel/traps=2Ec >@@ -295,12 +295,45 @@ DEFINE_IDTENTRY(exc_overflow) > do_error_trap(regs, 0, "overflow", X86_TRAP_OF, SIGSEGV, 0, NULL); > } >=20 >+static bool handle_hnop(struct pt_regs *regs) >+{ >+ unsigned char buf[MAX_INSN_SIZE]; >+ unsigned long nr_copied; >+ struct insn insn; >+ >+ if (!IS_ENABLED(CONFIG_X86_HNOP_EMU)) >+ return false; >+ >+ nr_copied =3D insn_fetch_from_user(regs, buf); >+ if (nr_copied <=3D 0) >+ return false; >+ >+ if (!insn_decode_from_regs(&insn, regs, buf, nr_copied)) >+ return false; >+ >+ /* Hintable NOPs cover 0F 18 to 0F 1F */ >+ if (insn=2Eopcode=2Ebytes[0] !=3D 0x0F || >+ insn=2Eopcode=2Ebytes[1] < 0x18 || insn=2Eopcode=2Ebytes[1] > 0x1F) >+ return false; >+ >+ pr_warn_once("%s[%d] uses hintable NOPs that your processor does not su= pport=2E\n" >+ "The kernel is emulating them; the performance of this " >+ "and other executables using them will be impacted=2E\n", >+ current->comm, task_pid_nr(current)); >+ >+ regs->ip +=3D insn=2Elength; >+ return true; >+} >+ > #ifdef CONFIG_X86_F00F_BUG > void handle_invalid_op(struct pt_regs *regs) > #else > static inline void handle_invalid_op(struct pt_regs *regs) > #endif > { >+ if (user_mode(regs) && handle_hnop(regs)) >+ return; >+ > do_error_trap(regs, 0, "invalid opcode", X86_TRAP_UD, SIGILL, > ILL_ILLOPN, error_get_trap_addr(regs)); > } Interesting that they build with endbr32 support, since the kernel vdso is= n't endbr32 compliant, as I found=2E=2E=2E