mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Borislav Petkov (AMD)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: David Howells <dhowells@redhat.com>,
	"Borislav Petkov (AMD)" <bp@alien8.de>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/bugs] Revert "x86/retpoline: Remove .text..__x86.return_thunk section"
Date: Thu, 19 Oct 2023 09:40:42 -0000	[thread overview]
Message-ID: <169770844297.3135.7611435585309229027.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20231018175531.GEZTAcE2p92U1AuVp1@fat_crate.local>

The following commit has been merged into the x86/bugs branch of tip:

Commit-ID:     59e6ce1eaaa2d9b2f9c89a108ce3fc7510bcd7ea
Gitweb:        https://git.kernel.org/tip/59e6ce1eaaa2d9b2f9c89a108ce3fc7510bcd7ea
Author:        Borislav Petkov (AMD) <bp@alien8.de>
AuthorDate:    Thu, 19 Oct 2023 11:09:41 +02:00
Committer:     Borislav Petkov (AMD) <bp@alien8.de>
CommitterDate: Thu, 19 Oct 2023 11:25:19 +02:00

Revert "x86/retpoline: Remove .text..__x86.return_thunk section"

This reverts commit e92626af3234708fe30f53b269d210d202b95206.

David Howells reported his box freezing without being able to see
a panic. However, it managed to issue a warning beforehand:

  missing return thunk: __x86_indirect_thunk_r15+0xa/0x5f-0x0: eb 74 66 66 2e
  WARNING: CPU: 0 PID: 0 at arch/x86/kernel/alternative.c:755 apply_returns+0xca/0x247
  Modules linked in:
  CPU: 0 PID: 0 Comm: swapper/0 Not tainted 6.6.0-rc5-next-20231013-build3+ #3044
  Hardware name: ASUS All Series/H97-PLUS, BIOS 2306 10/09/2014
  RIP: 0010:apply_returns+0xca/0x247

this happened with linux-next and with gcc 13. Looking at the compiler
output and particularly paying attention to the two JMP instructions:

  <__x86_indirect_thunk_r14>:
         e8 01 00 00 00          call   ffffffff81d71206 <__x86_indirect_thunk_r14+0x6>
         cc                      int3
         4c 89 34 24             mov    %r14,(%rsp)
         e9 91 00 00 00          jmp    ffffffff81d712a0 <__x86_return_thunk>
         66 66 2e 0f 1f 84 00    data16 cs nopw 0x0(%rax,%rax,1)
         00 00 00 00
         66 0f 1f 44 00 00       nopw   0x0(%rax,%rax,1)

  <__x86_indirect_thunk_r15>:
         e8 01 00 00 00          call   ffffffff81d71226 <__x86_indirect_thunk_r15+0x6>
         cc                      int3
         4c 89 3c 24             mov    %r15,(%rsp)
         eb 74                   jmp    ffffffff81d712a0 <__x86_return_thunk>

the second JMP is a short JMP one. This is likely some new gcc
optimization to size the JMP offsets and generate a small one if it
fits.

However, the apply_returns() logic does not expect a short JMP:

  if (op == JMP32_INSN_OPCODE)
        dest = addr + insn.length + insn.immediate.value;

and that JMP32_INSN_OPCODE is 0xe9.

Now, if __x86_return_thunk is in another section, the compiler cannot do
those shortcuts and will have to generate a JMP with a s32 offset.

As a matter of fact, the removal of the section  broke another case, see

  https://lore.kernel.org/r/20231010171020.462211-2-david.kaplan@amd.com

so revert for now until all the possible code generation issues have
been assessed, addressed and verified properly.

Reported-by: David Howells <dhowells@redhat.com>
Tested-by: David Howells <dhowells@redhat.com>
Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>
Link: https://lore.kernel.org/r/20231018175531.GEZTAcE2p92U1AuVp1@fat_crate.local
---
 arch/x86/kernel/vmlinux.lds.S | 3 +++
 arch/x86/lib/retpoline.S      | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 9cdb1a7..54a5596 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -132,7 +132,10 @@ SECTIONS
 		LOCK_TEXT
 		KPROBES_TEXT
 		SOFTIRQENTRY_TEXT
+#ifdef CONFIG_RETPOLINE
 		*(.text..__x86.indirect_thunk)
+		*(.text..__x86.return_thunk)
+#endif
 		STATIC_CALL_TEXT
 
 		ALIGN_ENTRY_TEXT_BEGIN
diff --git a/arch/x86/lib/retpoline.S b/arch/x86/lib/retpoline.S
index 6376d01..d410aba 100644
--- a/arch/x86/lib/retpoline.S
+++ b/arch/x86/lib/retpoline.S
@@ -129,6 +129,8 @@ SYM_CODE_END(__x86_indirect_jump_thunk_array)
 
 #ifdef CONFIG_RETHUNK
 
+	.section .text..__x86.return_thunk
+
 #ifdef CONFIG_CPU_SRSO
 
 /*

  parent reply	other threads:[~2023-10-19  9:40 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-10 17:10 [PATCH 0/3] Ensure default return thunk isn't used at runtime David Kaplan
2023-10-10 17:10 ` [PATCH 1/3] Revert "x86/retpoline: Remove .text..__x86.return_thunk section" David Kaplan
2023-10-10 17:48   ` Peter Zijlstra
2023-10-10 19:57     ` Josh Poimboeuf
2023-10-10 20:04       ` Borislav Petkov
2023-10-10 20:19         ` Josh Poimboeuf
2023-10-10 20:40           ` Kaplan, David
2023-10-10 21:22           ` Josh Poimboeuf
2023-10-11  7:41             ` Peter Zijlstra
2023-10-11  9:34               ` Borislav Petkov
2023-10-11 16:28               ` Josh Poimboeuf
2023-10-11 22:35                 ` Peter Zijlstra
2023-10-11 22:42                   ` Ingo Molnar
2023-10-12  2:27                   ` Josh Poimboeuf
2023-10-12  2:47                     ` [PATCH v2] objtool: Fix return thunk patching in retpolines Josh Poimboeuf
2023-10-12  6:25                       ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-10-12  8:16                       ` [PATCH v2] " Peter Zijlstra
2023-10-12 17:50                       ` [tip: x86/bugs] " tip-bot2 for Josh Poimboeuf
2023-10-20 11:37                       ` tip-bot2 for Josh Poimboeuf
2023-10-12  8:16                     ` [PATCH 1/3] Revert "x86/retpoline: Remove .text..__x86.return_thunk section" Peter Zijlstra
2023-10-10 17:10 ` [PATCH 2/3] x86/vdso: Run objtool on vdso32-setup David Kaplan
2023-10-12 17:50   ` [tip: x86/bugs] x86/vdso: Run objtool on vdso32-setup.o tip-bot2 for David Kaplan
2023-10-20 11:37   ` tip-bot2 for David Kaplan
2023-10-10 17:10 ` [PATCH 3/3] x86/retpoline: Ensure default return thunk isn't used at runtime David Kaplan
2023-10-10 19:36   ` Josh Poimboeuf
2023-10-10 20:14     ` Kaplan, David
2023-10-10 20:41       ` Josh Poimboeuf
2023-10-12 14:10         ` [PATCH -v2] " Borislav Petkov
2023-10-12 17:11           ` Josh Poimboeuf
2023-10-12 17:50           ` [tip: x86/bugs] " tip-bot2 for David Kaplan
2023-10-16 21:10             ` Nathan Chancellor
2023-10-16 21:29               ` Borislav Petkov
2023-10-16 21:48                 ` Nathan Chancellor
2023-10-17  4:31                   ` Kaplan, David
2023-10-17  5:28                     ` Josh Poimboeuf
2023-10-17 13:54                       ` Kaplan, David
2023-10-17 15:24                       ` Nick Desaulniers
2023-10-17 15:26                         ` Marco Elver
2023-10-17 15:32                       ` Nathan Chancellor
2023-10-17 16:59                         ` [PATCH] x86/srso: Fix panic in return thunk during boot Josh Poimboeuf
2023-10-17 17:52                           ` [tip: x86/bugs] x86/retpoline: Make sure there are no unconverted return thunks due to KCSAN tip-bot2 for Josh Poimboeuf
2023-10-20 11:37                           ` tip-bot2 for Josh Poimboeuf
2023-10-18 13:23             ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Borislav Petkov
2023-10-18 13:38               ` Ingo Molnar
2023-10-18 15:12                 ` Borislav Petkov
2023-10-18 15:54                   ` Josh Poimboeuf
2023-10-18 17:55                     ` Borislav Petkov
2023-10-18 18:14                       ` Josh Poimboeuf
2023-10-18 18:22                         ` Borislav Petkov
2023-10-18 18:39                           ` Josh Poimboeuf
2023-10-18 18:44                             ` Borislav Petkov
2023-10-18 19:14                               ` Josh Poimboeuf
2023-10-18 20:04                                 ` Borislav Petkov
2023-10-18 20:37                       ` Borislav Petkov
2023-10-19  6:35                         ` Josh Poimboeuf
2023-10-19  6:59                           ` Josh Poimboeuf
2023-10-19 14:15                             ` Borislav Petkov
2023-10-19 14:21                               ` Kaplan, David
2023-10-19 14:39                                 ` Borislav Petkov
2023-10-19 15:20                                   ` Josh Poimboeuf
2023-10-24 20:19                                     ` Borislav Petkov
2024-01-03 18:46                                       ` Borislav Petkov
2024-01-04 13:12                                         ` Borislav Petkov
2024-01-04 13:24                                           ` [PATCH -v2] " Borislav Petkov
2024-01-04 13:26                                             ` Borislav Petkov
2024-02-07 17:50                                               ` Josh Poimboeuf
2024-02-07 18:53                                                 ` Borislav Petkov
2024-02-07 19:49                                                   ` Josh Poimboeuf
2024-02-12 10:43                                                     ` Borislav Petkov
2024-04-03 17:10                                                       ` Klara Modin
2024-04-03 17:30                                                         ` Borislav Petkov
2024-04-03 20:26                                                           ` Klara Modin
2024-04-03 20:41                                                             ` Borislav Petkov
2024-04-03 22:25                                                               ` Klara Modin
2024-04-04 14:44                                                                 ` Borislav Petkov
2024-04-16  9:27                                                         ` Borislav Petkov
2024-04-17  3:59                                                           ` Klara Modin
2024-04-17 16:20                                                         ` [tip: x86/urgent] x86/retpolines: Enable the default thunk warning only on relevant configs tip-bot2 for Borislav Petkov (AMD)
2023-10-19  7:43                         ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime Peter Zijlstra
2023-10-19  9:40                       ` tip-bot2 for Borislav Petkov (AMD) [this message]
2023-10-19  9:40                       ` [tip: x86/bugs] Revert "x86/retpoline: Ensure default return thunk isn't used at runtime" tip-bot2 for Borislav Petkov (AMD)
2024-10-04 19:37                         ` Peter Zijlstra
2024-02-12 14:13   ` [tip: x86/bugs] x86/retpoline: Ensure default return thunk isn't used at runtime tip-bot2 for Josh Poimboeuf
2024-02-15  3:20     ` Nathan Chancellor
2024-02-15  8:30       ` Nikolay Borisov
2024-02-15 15:53       ` Borislav Petkov
2024-02-16  5:42         ` Josh Poimboeuf
2024-02-16 21:27           ` Borislav Petkov
2024-02-20  5:57             ` [PATCH] x86/vdso: Fix rethunk patching for vdso-image-{32,64}.o Josh Poimboeuf
2024-02-20 12:31       ` [tip: x86/core] " tip-bot2 for Josh Poimboeuf
2023-10-10 17:52 ` [PATCH 0/3] Ensure default return thunk isn't used at runtime Peter Zijlstra
2023-10-20 11:28 ` Subject: [PATCH] x86/retpoline: Document some thunk handling aspects (was: Re: [PATCH 0/3] Ensure default return thunk isn't used at runtime) Borislav Petkov
2023-10-20 11:37 ` [tip: x86/bugs] x86/retpoline: Document some thunk handling aspects tip-bot2 for Borislav Petkov (AMD)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=169770844297.3135.7611435585309229027.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=bp@alien8.de \
    --cc=dhowells@redhat.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®