lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240417-x86-fix-kexec-with-llvm-18-v1-0-5383121e8fb7@kernel.org>
Date: Wed, 17 Apr 2024 14:53:44 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: tglx@...utronix.de, mingo@...hat.com, bp@...en8.de, 
 dave.hansen@...ux.intel.com
Cc: x86@...nel.org, hpa@...or.com, ndesaulniers@...gle.com, 
 morbo@...gle.com, justinstitt@...gle.com, song@...nel.org, 
 ribalda@...omium.org, linux-kernel@...r.kernel.org, llvm@...ts.linux.dev, 
 patches@...ts.linux.dev, ns <0n-s@...rs.noreply.github.com>, 
 Nathan Chancellor <nathan@...nel.org>
Subject: [PATCH 0/2] x86/purgatory: Avoid kexec runtime warning with LLVM
 18

Hi all,

After LLVM commit d8a04398f949 ("Reland [X86] With large code model, put
functions into .ltext with large section flag (#73037)") [1], which
landed in the 18.x cycle, there is a runtime warning when loading a
kernel via kexec due to the presence of two text sections (.text and
ltext).

  $ kexec -l /boot/vmlinuz-linux --initrd=/boot/initramfs-linux.img --reuse-cmdline
  $ dmesg -l warn+
  ...
  [    1.264240] ------------[ cut here ]------------
  [    1.264647] WARNING: CPU: 0 PID: 96 at kernel/kexec_file.c:945 kexec_load_purgatory+0x2c8/0x3c0
  [    1.265322] Modules linked in:
  [    1.265565] CPU: 0 PID: 96 Comm: kexec Not tainted 6.9.0-rc4-00031-g96fca68c4fbf #1 eae91b3fe699ecba2dd0a886471788e49eb36ac0
  [    1.266403] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
  [    1.267268] RIP: 0010:kexec_load_purgatory+0x2c8/0x3c0
  [    1.267661] Code: 54 24 0c 48 89 c8 48 29 d0 0f 82 5d ff ff ff 49 03 54 24 1c 48 39 d1 0f 83 4f ff ff ff 49 8b 17 48 39 4a 18 0f 84 30 ff ff ff <0f> 0b e9 3b ff ff ff 66 85 c9 74 18 48 8b 5a 28 48 01 d3 45 31 e4
  [    1.269052] RSP: 0018:ffffbe28007cfb50 EFLAGS: 00010206
  [    1.269447] RAX: 0000000000000000 RBX: 00000000000000d0 RCX: 0000000000000000
  [    1.269982] RDX: ffff988c8174d000 RSI: 0000000000000010 RDI: ffffbe2801d940c0
  [    1.270527] RBP: 0000000000000002 R08: 0000003d8b4c0000 R09: cc0000000025ff00
  [    1.271063] R10: 0000003d8b4c0000 R11: cc0000000025ff00 R12: ffffbe28000d5084
  [    1.271603] R13: 000000013ffff000 R14: ffff988c8174d000 R15: ffffbe28007cfbe0
  [    1.272140] FS:  00007fec73535740(0000) GS:ffff988cbbc00000(0000) knlGS:0000000000000000
  [    1.272744] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  [    1.273178] CR2: 00007fec736b1390 CR3: 0000000101a24000 CR4: 0000000000350ef0
  [    1.273732] Call Trace:
  [    1.273929]  <TASK>
  [    1.274100]  ? __warn+0xc9/0x1c0
  [    1.274356]  ? kexec_load_purgatory+0x2c8/0x3c0
  [    1.274704]  ? report_bug+0x139/0x1e0
  [    1.274998]  ? handle_bug+0x42/0x70
  [    1.275269]  ? exc_invalid_op+0x1a/0x50
  [    1.275574]  ? asm_exc_invalid_op+0x1a/0x20
  [    1.275900]  ? kexec_load_purgatory+0x2c8/0x3c0
  [    1.276251]  bzImage64_load+0x1c1/0x6a0
  [    1.276556]  kexec_image_load_default+0x49/0x60
  [    1.276907]  __se_sys_kexec_file_load+0x606/0x790
  [    1.277280]  ? arch_exit_to_user_mode_prepare+0x6e/0x70
  [    1.277675]  do_syscall_64+0x90/0x170
  [    1.277955]  ? srso_return_thunk+0x5/0x5f
  [    1.278265]  ? __count_memcg_events+0x50/0xc0
  [    1.278597]  ? srso_return_thunk+0x5/0x5f
  [    1.278901]  ? handle_mm_fault+0xb18/0x11c0
  [    1.279218]  ? vfs_read+0x2c8/0x2f0
  [    1.279498]  ? srso_return_thunk+0x5/0x5f
  [    1.279802]  ? do_user_addr_fault+0x4d2/0x690
  [    1.280138]  ? srso_return_thunk+0x5/0x5f
  [    1.280449]  ? srso_return_thunk+0x5/0x5f
  [    1.280755]  entry_SYSCALL_64_after_hwframe+0x76/0x7e
  [    1.281136] RIP: 0033:0x7fec7363e88d
  [    1.281411] Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 73 14 0d 00 f7 d8 64 89 01 48
  [    1.282789] RSP: 002b:00007ffd136f4808 EFLAGS: 00000246 ORIG_RAX: 0000000000000140
  [    1.283354] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fec7363e88d
  [    1.283893] RDX: 00000000000000c5 RSI: 0000000000000005 RDI: 0000000000000003
  [    1.284427] RBP: 0000000000000003 R08: 0000000000000000 R09: 00005628517eef10
  [    1.284966] R10: 00005628580a75f0 R11: 0000000000000246 R12: 0000000000000003
  [    1.285500] R13: 00005628517f89a8 R14: 00007ffd136f4b98 R15: 0000000000000004
  [    1.286036]  </TASK>
  [    1.286210] ---[ end trace 0000000000000000 ]---

Unlike LTO and PGO, which were disabled for the purgatory in commit
97b6b9cbba40 ("x86/purgatory: remove PGO flags") and commit 75b2f7e4c9e0
("x86/purgatory: Remove LTO flags"), this optimization has no flag to
opt out of it. One way to resolve this would be to use '.ltext' and
'.lrodata' as the text and read-only data sections in the out of line
assembly in arch/x86/purgatory but there is nothing that stops future
changes from splitting the text section further.

Properly avoid the warning by using a linker script to coalesce all
separate text sections into one, which was alluded to by both the change
that introduced the warning and 75b2f7e4c9e0... I think this really
should have been done then but I wasn't looking too far ahead :) To
avoid backsliding now that all sections are properly described by the
linker script, turn on orphan section warnings as well.

[1]: https://github.com/llvm/llvm-project/commit/d8a04398f9492f043ffd8fbaf2458778f7d0fcd5

---
Nathan Chancellor (2):
      x86/purgatory: Add a linker script
      x86/purgatory: Enable orphan section warnings

 arch/x86/purgatory/.gitignore      |  1 +
 arch/x86/purgatory/Makefile        | 19 +++---------
 arch/x86/purgatory/purgatory.lds.S | 63 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 14 deletions(-)
---
base-commit: 0bbac3facb5d6cc0171c45c9873a2dc96bea9680
change-id: 20240416-x86-fix-kexec-with-llvm-18-c986b21845c5

Best regards,
-- 
Nathan Chancellor <nathan@...nel.org>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ