linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RESEND PATCH v2 1/2] arch/x86/tools/objdump_reformat.awk: Ensure regex matches fwait
       [not found] <20221112090418.284656-1-samuelzeter@gmail.com>
@ 2022-11-12  9:04 ` Samuel Zeter
  2022-11-12  9:04 ` [RESEND PATCH v2 2/2] arch/x86/tools/objdump_reformat.awk: Allow for spaces Samuel Zeter
  2023-10-13 17:17 ` [RESEND PATCH v2 0/2] *** Fix reformat_objdump.awk *** Kees Cook
  2 siblings, 0 replies; 3+ messages in thread
From: Samuel Zeter @ 2022-11-12  9:04 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: Samuel Zeter, Masami Hiramatsu, linux-kernel, llvm

If there is "wait" mnemonic in the line being parsed, it is incorrectly
handled by the script, and an extra line of "fwait" in
objdump_reformat's output is inserted. As insn_decoder_test relies
upon the formatted output, the test fails.

This is reproducible when disassembling with llvm-objdump:

Pre-processed lines:
ffffffff81033e72: 9b                    wait
ffffffff81033e73: 48 c7 c7 89 50 42 82  movq

After objdump_reformat.awk:
ffffffff81033e72:       9b      fwait
ffffffff81033e72:                               wait
ffffffff81033e73:       48 c7 c7 89 50 42 82    movq

The regex match now accepts spaces or tabs, along with the "fwait"
instruction.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Samuel Zeter <samuelzeter@gmail.com>
---
 arch/x86/tools/objdump_reformat.awk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/tools/objdump_reformat.awk b/arch/x86/tools/objdump_reformat.awk
index f418c91b71f0..276e572a6f60 100644
--- a/arch/x86/tools/objdump_reformat.awk
+++ b/arch/x86/tools/objdump_reformat.awk
@@ -12,7 +12,7 @@ BEGIN {
 	prev_hex = ""
 	prev_mnemonic = ""
 	bad_expr = "(\\(bad\\)|^rex|^.byte|^rep(z|nz)$|^lock$|^es$|^cs$|^ss$|^ds$|^fs$|^gs$|^data(16|32)$|^addr(16|32|64))"
-	fwait_expr = "^9b "
+	fwait_expr = "^9b[ \t]*fwait"
 	fwait_str="9b\tfwait"
 }
 
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [RESEND PATCH v2 2/2] arch/x86/tools/objdump_reformat.awk: Allow for spaces
       [not found] <20221112090418.284656-1-samuelzeter@gmail.com>
  2022-11-12  9:04 ` [RESEND PATCH v2 1/2] arch/x86/tools/objdump_reformat.awk: Ensure regex matches fwait Samuel Zeter
@ 2022-11-12  9:04 ` Samuel Zeter
  2023-10-13 17:17 ` [RESEND PATCH v2 0/2] *** Fix reformat_objdump.awk *** Kees Cook
  2 siblings, 0 replies; 3+ messages in thread
From: Samuel Zeter @ 2022-11-12  9:04 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Nathan Chancellor, Nick Desaulniers, Tom Rix
  Cc: Samuel Zeter, Masami Hiramatsu, linux-kernel, llvm

objdump and llvm-objdump have differing output formats. Specifically,
objump will format its output as: address:<tab>hex, whereas
llvm-objdump displays its output as address:<space>hex.

objdump_reformat.awk incorrectly handles this discrepancy due to
the unexpected space and as a result insn_decoder_test fails, as
its input is garbled.

The instruction line being tokenized now handles a space and colon,
or tab delimiter.

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Tested-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Samuel Zeter <samuelzeter@gmail.com>
---
 arch/x86/tools/objdump_reformat.awk | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/tools/objdump_reformat.awk b/arch/x86/tools/objdump_reformat.awk
index 276e572a6f60..a4120d907277 100644
--- a/arch/x86/tools/objdump_reformat.awk
+++ b/arch/x86/tools/objdump_reformat.awk
@@ -22,7 +22,7 @@ BEGIN {
 }
 
 /^ *[0-9a-f]+:/ {
-	if (split($0, field, "\t") < 3) {
+	if (split($0, field, /: |\t/) < 3) {
 		# This is a continuation of the same insn.
 		prev_hex = prev_hex field[2]
 	} else {
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RESEND PATCH v2 0/2] *** Fix reformat_objdump.awk ***
       [not found] <20221112090418.284656-1-samuelzeter@gmail.com>
  2022-11-12  9:04 ` [RESEND PATCH v2 1/2] arch/x86/tools/objdump_reformat.awk: Ensure regex matches fwait Samuel Zeter
  2022-11-12  9:04 ` [RESEND PATCH v2 2/2] arch/x86/tools/objdump_reformat.awk: Allow for spaces Samuel Zeter
@ 2023-10-13 17:17 ` Kees Cook
  2 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-10-13 17:17 UTC (permalink / raw)
  To: Samuel Zeter, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Dave Hansen, x86, H. Peter Anvin, Masami Hiramatsu, linux-kernel,
	llvm

*thread necromancy*

These patches still apply and are still needed to correctly process
objdump output. It accidentally doesn't produce any errors currently,
but manual inspection shows mangled results.

Can an x86 maintainer take these two patches please? I can carry them if
that's preferred?

Note that there is an older Ack from Masami:

https://lore.kernel.org/all/20220107205259.e66ff1bd90ac218611bf1178@kernel.org/

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

And I've now reviewed and tested this too:

Reviewed-by: Kees Cook <keescook@chromium.org>
Tested-by: Kees Cook <keescook@chromium.org>

Thanks!

-Kees

On Sat, Nov 12, 2022 at 07:04:15PM +1000, Samuel Zeter wrote:
> These are two small patches which originally dealt with
> the problem found at:
> 
> https://github.com/ClangBuiltLinux/linux/issues/1364
> 
> The original steps to reproduce were:
> $ make -skj"$(nproc)" LLVM=1 LLVM_IAS=1 defconfig
> $ scripts/config -e X86_DECODER_SELFTEST
> $ make -skj"$(nproc)" LLVM=1 LLVM_IAS=1 olddefconfig bzImage
> 
> Which resulted in the error:
> arch/x86/tools/insn_decoder_test: warning: objdump says 0 bytes, but
> insn_get_length() says 2
> 
> Upon inspection it turned out llvm-objdump was formatting its
> output differently, which caused objdump_reformat.awk to incorrectly
> output its values.
> 
> After fixing that bug, a second one was seen where the instruction
> "wait" was incorrectly matched with "fwait", which again caused
> insn_decoder_test to fail.
> 
> Samuel Zeter (2):
>   arch/x86/tools/objdump_reformat.awk: Ensure regex matches fwait
>   arch/x86/tools/objdump_reformat.awk: Allow for spaces
> 
>  arch/x86/tools/objdump_reformat.awk | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> 
> base-commit: 151297128990b4b44be8d70b983053831fa857f6
> -- 
> 2.38.1
> 

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-13 17:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20221112090418.284656-1-samuelzeter@gmail.com>
2022-11-12  9:04 ` [RESEND PATCH v2 1/2] arch/x86/tools/objdump_reformat.awk: Ensure regex matches fwait Samuel Zeter
2022-11-12  9:04 ` [RESEND PATCH v2 2/2] arch/x86/tools/objdump_reformat.awk: Allow for spaces Samuel Zeter
2023-10-13 17:17 ` [RESEND PATCH v2 0/2] *** Fix reformat_objdump.awk *** Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).