All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: hpa@zytor.com
Cc: Denys Vlasenko <dvlasenk@redhat.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Julien Thierry <julien.thierry@arm.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	valentin.schneider@arm.com, Will Deacon <will.deacon@arm.com>,
	Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@redhat.com>, James Morse <james.morse@arm.com>,
	Andrew Lutomirski <luto@kernel.org>,
	Brian Gerst <brgerst@gmail.com>, Borislav Petkov <bp@alien8.de>,
	Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@kernel.org>,
	"linux-alpha@vger.kernel.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [RFC][PATCH] objtool: STAC/CLAC validation
Date: Mon, 25 Feb 2019 14:21:03 +0100	[thread overview]
Message-ID: <20190225132103.GD32494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <15DE0017-9AE5-4E7A-96CD-E5E9F5B72516@zytor.com>

On Mon, Feb 25, 2019 at 12:47:00AM -0800, hpa@zytor.com wrote:
> It doesn't have to understand the contents of the memop, but it seems
> that the presence of a modrm with mode ≠ 3 should be plenty. It needs
> to know that much in order to know the length of instructions anyway.
> For extra credit, ignore LEA or hinting instructions.

A little something like so then?

arch/x86/kernel/fpu/signal.o: warning: objtool: .altinstr_replacement+0x9c: UACCESS disable without MEMOPs: copy_fpstate_to_sigframe()

00000000023c  000200000002 R_X86_64_PC32     0000000000000000 .text + 604
000000000240  000700000002 R_X86_64_PC32     0000000000000000 .altinstr_replacement + 99
000000000249  000200000002 R_X86_64_PC32     0000000000000000 .text + 610
00000000024d  000700000002 R_X86_64_PC32     0000000000000000 .altinstr_replacement + 9c

.text

604:   90                      nop
605:   90                      nop
606:   90                      nop
607:   83 ce 03                or     $0x3,%esi
60a:   89 b3 00 02 00 00       mov    %esi,0x200(%rbx)
610:   90                      nop
611:   90                      nop
612:   90                      nop

.altinstr_replacement

99:   0f 01 cb                stac
9c:   0f 01 ca                clac

Which looks like the tool failed to recognise that MOV as a memop.



---
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -37,7 +37,8 @@
 #define INSN_CLAC		12
 #define INSN_STD		13
 #define INSN_CLD		14
-#define INSN_OTHER		15
+#define INSN_MEMOP		15
+#define INSN_OTHER		16
 #define INSN_LAST		INSN_OTHER
 
 enum op_dest_type {
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -123,6 +123,9 @@ int arch_decode_instruction(struct elf *
 		modrm_mod = X86_MODRM_MOD(modrm);
 		modrm_reg = X86_MODRM_REG(modrm);
 		modrm_rm = X86_MODRM_RM(modrm);
+
+		if (modrm_mod != 3)
+			*type = INSN_MEMOP;
 	}
 
 	if (insn.sib.nbytes)
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2047,6 +2047,7 @@ static int validate_branch(struct objtoo
 				WARN_FUNC("recursive UACCESS enable", sec, insn->offset);
 
 			state.uaccess = true;
+			state.memop = false;
 			break;
 
 		case INSN_CLAC:
@@ -2058,6 +2059,9 @@ static int validate_branch(struct objtoo
 				break;
 			}
 
+			if (!state.memop && insn->func)
+				WARN_FUNC("UACCESS disable without MEMOPs: %s()", sec, insn->offset, insn->func->name);
+
 			state.uaccess = false;
 			break;
 
@@ -2075,6 +2079,10 @@ static int validate_branch(struct objtoo
 			state.df = false;
 			break;
 
+		case INSN_MEMOP:
+			state.memop = true;
+			break;
+
 		default:
 			break;
 		}
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -31,7 +31,7 @@ struct insn_state {
 	int stack_size;
 	unsigned char type;
 	bool bp_scratch;
-	bool drap, end, uaccess, uaccess_safe, df;
+	bool drap, end, uaccess, uaccess_safe, df, memop;
 	int drap_reg, drap_offset;
 	struct cfi_reg vals[CFI_NUM_REGS];
 };

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Peter Zijlstra <peterz@infradead.org>
To: hpa@zytor.com
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Julien Thierry <julien.thierry@arm.com>,
	Will Deacon <will.deacon@arm.com>,
	Andy Lutomirski <luto@amacapital.net>,
	Ingo Molnar <mingo@kernel.org>,
	Linux List Kernel Mailing <linux-kernel@vger.kernel.org>,
	"linux-alpha@vger.kernel.org"
	<linux-arm-kernel@lists.infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Catalin Marinas <catalin.marinas@arm.com>,
	James Morse <james.morse@arm.com>,
	valentin.schneider@arm.com, Brian Gerst <brgerst@gmail.com>,
	Josh Poimboeuf <jpoimboe@redhat.com>,
	Andrew Lutomirski <luto@kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	Denys Vlasenko <dvlasenk@redhat.com>
Subject: Re: [RFC][PATCH] objtool: STAC/CLAC validation
Date: Mon, 25 Feb 2019 14:21:03 +0100	[thread overview]
Message-ID: <20190225132103.GD32494@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <15DE0017-9AE5-4E7A-96CD-E5E9F5B72516@zytor.com>

On Mon, Feb 25, 2019 at 12:47:00AM -0800, hpa@zytor.com wrote:
> It doesn't have to understand the contents of the memop, but it seems
> that the presence of a modrm with mode ≠ 3 should be plenty. It needs
> to know that much in order to know the length of instructions anyway.
> For extra credit, ignore LEA or hinting instructions.

A little something like so then?

arch/x86/kernel/fpu/signal.o: warning: objtool: .altinstr_replacement+0x9c: UACCESS disable without MEMOPs: copy_fpstate_to_sigframe()

00000000023c  000200000002 R_X86_64_PC32     0000000000000000 .text + 604
000000000240  000700000002 R_X86_64_PC32     0000000000000000 .altinstr_replacement + 99
000000000249  000200000002 R_X86_64_PC32     0000000000000000 .text + 610
00000000024d  000700000002 R_X86_64_PC32     0000000000000000 .altinstr_replacement + 9c

.text

604:   90                      nop
605:   90                      nop
606:   90                      nop
607:   83 ce 03                or     $0x3,%esi
60a:   89 b3 00 02 00 00       mov    %esi,0x200(%rbx)
610:   90                      nop
611:   90                      nop
612:   90                      nop

.altinstr_replacement

99:   0f 01 cb                stac
9c:   0f 01 ca                clac

Which looks like the tool failed to recognise that MOV as a memop.



---
--- a/tools/objtool/arch.h
+++ b/tools/objtool/arch.h
@@ -37,7 +37,8 @@
 #define INSN_CLAC		12
 #define INSN_STD		13
 #define INSN_CLD		14
-#define INSN_OTHER		15
+#define INSN_MEMOP		15
+#define INSN_OTHER		16
 #define INSN_LAST		INSN_OTHER
 
 enum op_dest_type {
--- a/tools/objtool/arch/x86/decode.c
+++ b/tools/objtool/arch/x86/decode.c
@@ -123,6 +123,9 @@ int arch_decode_instruction(struct elf *
 		modrm_mod = X86_MODRM_MOD(modrm);
 		modrm_reg = X86_MODRM_REG(modrm);
 		modrm_rm = X86_MODRM_RM(modrm);
+
+		if (modrm_mod != 3)
+			*type = INSN_MEMOP;
 	}
 
 	if (insn.sib.nbytes)
--- a/tools/objtool/check.c
+++ b/tools/objtool/check.c
@@ -2047,6 +2047,7 @@ static int validate_branch(struct objtoo
 				WARN_FUNC("recursive UACCESS enable", sec, insn->offset);
 
 			state.uaccess = true;
+			state.memop = false;
 			break;
 
 		case INSN_CLAC:
@@ -2058,6 +2059,9 @@ static int validate_branch(struct objtoo
 				break;
 			}
 
+			if (!state.memop && insn->func)
+				WARN_FUNC("UACCESS disable without MEMOPs: %s()", sec, insn->offset, insn->func->name);
+
 			state.uaccess = false;
 			break;
 
@@ -2075,6 +2079,10 @@ static int validate_branch(struct objtoo
 			state.df = false;
 			break;
 
+		case INSN_MEMOP:
+			state.memop = true;
+			break;
+
 		default:
 			break;
 		}
--- a/tools/objtool/check.h
+++ b/tools/objtool/check.h
@@ -31,7 +31,7 @@ struct insn_state {
 	int stack_size;
 	unsigned char type;
 	bool bp_scratch;
-	bool drap, end, uaccess, uaccess_safe, df;
+	bool drap, end, uaccess, uaccess_safe, df, memop;
 	int drap_reg, drap_offset;
 	struct cfi_reg vals[CFI_NUM_REGS];
 };

  reply	other threads:[~2019-02-25 13:21 UTC|newest]

Thread overview: 171+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-15 13:58 [PATCH v3 0/4] uaccess: Add unsafe accessors for arm64 Julien Thierry
2019-01-15 13:58 ` Julien Thierry
2019-01-15 13:58 ` [PATCH v3 1/4] arm64: uaccess: Cleanup get/put_user() Julien Thierry
2019-01-15 13:58   ` Julien Thierry
2019-01-15 13:58 ` [PATCH v3 2/4] arm64: uaccess: Implement unsafe accessors Julien Thierry
2019-01-15 13:58   ` Julien Thierry
2019-01-15 13:58 ` [PATCH v3 3/4] uaccess: Check no rescheduling function is called in unsafe region Julien Thierry
2019-01-15 13:58   ` Julien Thierry
2019-01-30 16:58   ` Valentin Schneider
2019-01-30 16:58     ` Valentin Schneider
2019-02-04 13:27     ` Julien Thierry
2019-02-04 13:27       ` Julien Thierry
2019-02-11 13:45   ` Ingo Molnar
2019-02-11 13:45     ` Ingo Molnar
2019-02-11 13:51     ` Peter Zijlstra
2019-02-11 13:51       ` Peter Zijlstra
2019-02-12  9:15       ` Julien Thierry
2019-02-12  9:15         ` Julien Thierry
2019-02-13  8:21         ` Ingo Molnar
2019-02-13  8:21           ` Ingo Molnar
2019-02-13 10:35         ` Peter Zijlstra
2019-02-13 10:35           ` Peter Zijlstra
2019-02-13 10:50           ` Julien Thierry
2019-02-13 10:50             ` Julien Thierry
2019-02-13 13:17             ` Peter Zijlstra
2019-02-13 13:17               ` Peter Zijlstra
2019-02-13 13:20               ` Peter Zijlstra
2019-02-13 13:20                 ` Peter Zijlstra
2019-02-13 14:00               ` Will Deacon
2019-02-13 14:00                 ` Will Deacon
2019-02-13 14:07                 ` Julien Thierry
2019-02-13 14:07                   ` Julien Thierry
2019-02-13 14:17                 ` Peter Zijlstra
2019-02-13 14:17                   ` Peter Zijlstra
2019-02-13 14:24                   ` Julien Thierry
2019-02-13 14:24                     ` Julien Thierry
2019-02-13 14:40                     ` Peter Zijlstra
2019-02-13 14:40                       ` Peter Zijlstra
2019-02-13 15:08                       ` Peter Zijlstra
2019-02-13 15:08                         ` Peter Zijlstra
2019-02-13 14:25                 ` Peter Zijlstra
2019-02-13 14:25                   ` Peter Zijlstra
2019-02-13 14:39                   ` Julien Thierry
2019-02-13 14:39                     ` Julien Thierry
2019-02-13 14:41                     ` Peter Zijlstra
2019-02-13 14:41                       ` Peter Zijlstra
2019-02-13 15:45                       ` Peter Zijlstra
2019-02-13 15:45                         ` Peter Zijlstra
2019-02-13 18:54                         ` Peter Zijlstra
2019-02-13 18:54                           ` Peter Zijlstra
     [not found]                         ` <D61C430D-4321-4114-AB85-671A3C7B8EAE@amacapital.net>
2019-02-13 22:21                           ` Peter Zijlstra
2019-02-13 22:21                             ` Peter Zijlstra
2019-02-13 22:49                             ` Andy Lutomirski
2019-02-13 22:49                               ` Andy Lutomirski
2019-02-14 10:14                               ` [PATCH] sched/x86: Save [ER]FLAGS on context switch Peter Zijlstra
2019-02-14 10:14                                 ` Peter Zijlstra
2019-02-14 16:18                                 ` Brian Gerst
2019-02-14 16:18                                   ` Brian Gerst
2019-02-14 19:34                                   ` Peter Zijlstra
2019-02-14 19:34                                     ` Peter Zijlstra
2019-02-15 14:34                                     ` Brian Gerst
2019-02-15 14:34                                       ` Brian Gerst
2019-02-15 17:18                                     ` Linus Torvalds
2019-02-15 17:18                                       ` Linus Torvalds
2019-02-15 17:40                                       ` Peter Zijlstra
2019-02-15 17:40                                         ` Peter Zijlstra
2019-02-15 18:28                                         ` Andy Lutomirski
2019-02-15 18:28                                           ` Andy Lutomirski
2019-02-15 23:34                                         ` Peter Zijlstra
2019-02-15 23:34                                           ` Peter Zijlstra
2019-02-16  0:21                                           ` Linus Torvalds
2019-02-16  0:21                                             ` Linus Torvalds
2019-02-16 10:32                                             ` Peter Zijlstra
2019-02-16 10:32                                               ` Peter Zijlstra
2019-02-16  4:06                                 ` hpa
2019-02-16  4:06                                   ` hpa
2019-02-16 10:30                                   ` Peter Zijlstra
2019-02-16 10:30                                     ` Peter Zijlstra
2019-02-18 22:30                                     ` H. Peter Anvin
2019-02-18 22:30                                       ` H. Peter Anvin
2019-02-19  0:24                                       ` Linus Torvalds
2019-02-19  0:24                                         ` Linus Torvalds
2019-02-19  2:20                                         ` Andy Lutomirski
2019-02-19  2:20                                           ` Andy Lutomirski
2019-02-19  2:46                                           ` H. Peter Anvin
2019-02-19  2:46                                             ` H. Peter Anvin
2019-02-19  9:07                                             ` Julien Thierry
2019-02-19  9:07                                               ` Julien Thierry
2019-02-19  8:53                                         ` Julien Thierry
2019-02-19  8:53                                           ` Julien Thierry
2019-02-19  9:15                                         ` Peter Zijlstra
2019-02-19  9:15                                           ` Peter Zijlstra
2019-02-19  9:19                                           ` Peter Zijlstra
2019-02-19  9:19                                             ` Peter Zijlstra
2019-02-19  9:04                                       ` Peter Zijlstra
2019-02-19  9:04                                         ` Peter Zijlstra
2019-02-19  9:21                                         ` hpa
2019-02-19  9:21                                           ` hpa
2019-02-19  9:44                                         ` Peter Zijlstra
2019-02-19  9:44                                           ` Peter Zijlstra
2019-02-19 11:38                                           ` Thomas Gleixner
2019-02-19 11:38                                             ` Thomas Gleixner
2019-02-19 11:58                                             ` Peter Zijlstra
2019-02-19 11:58                                               ` Peter Zijlstra
2019-02-19 12:48                                         ` Will Deacon
2019-02-19 12:48                                           ` Will Deacon
2019-02-20 22:55                                           ` H. Peter Anvin
2019-02-20 22:55                                             ` H. Peter Anvin
2019-02-21 12:06                                             ` Julien Thierry
2019-02-21 12:06                                               ` Julien Thierry
2019-02-21 21:35                                               ` Thomas Gleixner
2019-02-21 21:35                                                 ` Thomas Gleixner
2019-02-21 22:08                                                 ` Linus Torvalds
2019-02-21 22:08                                                   ` Linus Torvalds
2019-02-22 12:58                                                   ` Peter Zijlstra
2019-02-22 12:58                                                     ` Peter Zijlstra
2019-02-22 18:10                                                   ` Thomas Gleixner
2019-02-22 18:10                                                     ` Thomas Gleixner
2019-02-22 22:26                                                     ` [RFC][PATCH] objtool: STAC/CLAC validation Peter Zijlstra
2019-02-22 22:26                                                       ` Peter Zijlstra
2019-02-22 23:34                                                       ` Linus Torvalds
2019-02-22 23:34                                                         ` Linus Torvalds
2019-02-23  8:43                                                         ` Peter Zijlstra
2019-02-23  8:43                                                           ` Peter Zijlstra
2019-02-22 23:39                                                       ` hpa
2019-02-22 23:39                                                         ` hpa
2019-02-23  8:39                                                         ` Peter Zijlstra
2019-02-23  8:39                                                           ` Peter Zijlstra
2019-02-25  8:47                                                           ` hpa
2019-02-25  8:47                                                             ` hpa
2019-02-25 13:21                                                             ` Peter Zijlstra [this message]
2019-02-25 13:21                                                               ` Peter Zijlstra
2019-03-01 15:07                                                               ` Peter Zijlstra
2019-03-01 15:07                                                                 ` Peter Zijlstra
2019-02-25  8:49                                                           ` hpa
2019-02-25  8:49                                                             ` hpa
2019-02-22 23:55                                                       ` Andy Lutomirski
2019-02-22 23:55                                                         ` Andy Lutomirski
2019-02-23  8:37                                                         ` Peter Zijlstra
2019-02-23  8:37                                                           ` Peter Zijlstra
2019-02-23 10:52                                                           ` Peter Zijlstra
2019-02-23 10:52                                                             ` Peter Zijlstra
2019-02-25 10:51                                                         ` Peter Zijlstra
2019-02-25 10:51                                                           ` Peter Zijlstra
2019-02-25 11:53                                                           ` Peter Zijlstra
2019-02-25 11:53                                                             ` Peter Zijlstra
2019-02-25 15:36                                                             ` Andy Lutomirski
2019-02-25 15:36                                                               ` Andy Lutomirski
2019-02-23  0:34                                                       ` Andy Lutomirski
2019-02-23  1:12                                                         ` Linus Torvalds
2019-02-23  1:16                                                           ` Andy Lutomirski
2019-02-23  1:33                                                             ` Linus Torvalds
2019-02-23  1:40                                                             ` Linus Torvalds
2019-02-25  8:33                                                       ` Julien Thierry
2019-02-25  8:33                                                         ` Julien Thierry
2019-02-25 11:55                                                         ` Peter Zijlstra
2019-02-25 11:55                                                           ` Peter Zijlstra
2019-02-21 12:46                                             ` [PATCH] sched/x86: Save [ER]FLAGS on context switch Will Deacon
2019-02-21 12:46                                               ` Will Deacon
2019-02-21 22:06                                               ` Andy Lutomirski
2019-02-21 22:06                                                 ` Andy Lutomirski
2019-02-18  9:03                                 ` [PATCH v2] " Peter Zijlstra
2019-02-18  9:03                                   ` Peter Zijlstra
2019-02-13 23:19                         ` [PATCH v3 3/4] uaccess: Check no rescheduling function is called in unsafe region Linus Torvalds
2019-02-13 23:19                           ` Linus Torvalds
2019-01-15 13:58 ` [PATCH v3 4/4] arm64: uaccess: Implement user_access_region_active Julien Thierry
2019-01-15 13:58   ` Julien Thierry
2019-01-25 14:27 ` [PATCH v3 0/4] uaccess: Add unsafe accessors for arm64 Catalin Marinas
2019-01-25 14:27   ` Catalin Marinas
2019-01-30 16:17 ` Julien Thierry
2019-01-30 16:17   ` Julien Thierry

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=20190225132103.GD32494@hirez.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=bp@alien8.de \
    --cc=brgerst@gmail.com \
    --cc=catalin.marinas@arm.com \
    --cc=dvlasenk@redhat.com \
    --cc=hpa@zytor.com \
    --cc=james.morse@arm.com \
    --cc=jpoimboe@redhat.com \
    --cc=julien.thierry@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=luto@kernel.org \
    --cc=mingo@kernel.org \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=valentin.schneider@arm.com \
    --cc=will.deacon@arm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.