Skip to contentSkip to conversation

objtool,x86: Verify poke_int3_handler() is self contained

PATCH In review [email protected] 3 participants 6 messages Jul 27, 2020 – Jul 28, 2020 objtool

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

PATCH 1/1 objtool,x86: Verify poke_int3_handler() is self contained

Abuse the SMAP rules to ensure poke_int3_handler() doesn't call out to anything.

---
 tools/objtool/check.c |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/objtool/check.c +8 -0
@@ -551,6 +551,14 @@ static const char *uaccess_safe_builtin[
 	"__memcpy_mcsafe",
 	"mcsafe_handle_tail",
 	"ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
+	/*
+	 * Abuse alert!
+	 *
+	 * poke_int3_handler() is not in fact related to uaccess at all, we
+	 * abuse the uaccess rules to ensure poke_int3_handler() is self
+	 * contained and doesn't CALL out to other code.
+	 */
+	"poke_int3_handler",
 	NULL
 };
 
#1 lore raw
Quoted 13 lines · * [email protected] <[email protected]> wrote:

Abuse the SMAP rules to ensure poke_int3_handler() doesn't call out to anything.

---
 tools/objtool/check.c |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/objtool/check.c +0 -0
@@ -551,6 +551,14 @@ static const char *uaccess_safe_builtin[
 	"__memcpy_mcsafe",

tools/objtool/check.c static const char *uaccess_safe_builtin[ · line 561

Quoted 10 lines
tools/objtool/check.c +8 -0
 	"mcsafe_handle_tail",
 	"ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
+	/*
+	 * Abuse alert!
+	 *
+	 * poke_int3_handler() is not in fact related to uaccess at all, we
+	 * abuse the uaccess rules to ensure poke_int3_handler() is self
+	 * contained and doesn't CALL out to other code.
+	 */
+	"poke_int3_handler",

So ->uaccess_safe makes sure that we don't CALL into non-uaccess-safe functions, but it still allows CALLs into *other* uaccess-safe functions, right?

So unless I missed something in the logic, the comment should say something like "doesn't CALL out to other non-uaccess safe code" or so? Which is, arguably, like 99% of all functions - but still, a whole bunch are allowed, such as low level instrumentation and other utility functions.

Thanks,

Ingo

author maintainer
#2 lore raw
Quoted 31 lines · Ingo Molnar
Quoted 13 lines · * [email protected] <[email protected]> wrote:

Abuse the SMAP rules to ensure poke_int3_handler() doesn't call out to anything.

---
 tools/objtool/check.c |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/objtool/check.c +0 -0
@@ -551,6 +551,14 @@ static const char *uaccess_safe_builtin[
 	"__memcpy_mcsafe",

tools/objtool/check.c static const char *uaccess_safe_builtin[ · line 561

Quoted 10 lines
tools/objtool/check.c +8 -0
 	"mcsafe_handle_tail",
 	"ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
+	/*
+	 * Abuse alert!
+	 *
+	 * poke_int3_handler() is not in fact related to uaccess at all, we
+	 * abuse the uaccess rules to ensure poke_int3_handler() is self
+	 * contained and doesn't CALL out to other code.
+	 */
+	"poke_int3_handler",

So ->uaccess_safe makes sure that we don't CALL into non-uaccess-safe functions, but it still allows CALLs into *other* uaccess-safe functions, right?

Quoted 5 lines

So unless I missed something in the logic, the comment should say something like "doesn't CALL out to other non-uaccess safe code" or so? Which is, arguably, like 99% of all functions - but still, a whole bunch are allowed, such as low level instrumentation and other utility functions.

Right, so poke_int3_handler() is also noinstr and by that isn't allowed to call out into !noinstr code. The intersection should be small.

But yeah, perhaps this is a bad idea and I should add another annotation for this,.. dunno.

#3 lore raw
Quoted 38 lines · * [email protected] <[email protected]> wrote:
Quoted 31 lines · Ingo Molnar
Quoted 13 lines · * [email protected] <[email protected]> wrote:

Abuse the SMAP rules to ensure poke_int3_handler() doesn't call out to anything.

---
 tools/objtool/check.c |    8 ++++++++
 1 file changed, 8 insertions(+)
tools/objtool/check.c +0 -0
@@ -551,6 +551,14 @@ static const char *uaccess_safe_builtin[
 	"__memcpy_mcsafe",

tools/objtool/check.c static const char *uaccess_safe_builtin[ · line 561

Quoted 10 lines
tools/objtool/check.c +8 -0
 	"mcsafe_handle_tail",
 	"ftrace_likely_update", /* CONFIG_TRACE_BRANCH_PROFILING */
+	/*
+	 * Abuse alert!
+	 *
+	 * poke_int3_handler() is not in fact related to uaccess at all, we
+	 * abuse the uaccess rules to ensure poke_int3_handler() is self
+	 * contained and doesn't CALL out to other code.
+	 */
+	"poke_int3_handler",

So ->uaccess_safe makes sure that we don't CALL into non-uaccess-safe functions, but it still allows CALLs into *other* uaccess-safe functions, right?

Quoted 5 lines

So unless I missed something in the logic, the comment should say something like "doesn't CALL out to other non-uaccess safe code" or so? Which is, arguably, like 99% of all functions - but still, a whole bunch are allowed, such as low level instrumentation and other utility functions.

Quoted 5 lines

Right, so poke_int3_handler() is also noinstr and by that isn't allowed to call out into !noinstr code. The intersection should be small.

But yeah, perhaps this is a bad idea and I should add another annotation for this,.. dunno.

'nocall' ? :-)

Ingo

author maintainer
#5 lore raw
Quoted 5 lines · Thomas Gleixner
Quoted 2 lines · [email protected] writes:

Abuse the SMAP rules to ensure poke_int3_handler() doesn't call out to anything.

Yuck. Isn't that what noinstr is for or am I missing something?

Well, we don't want poke_int3_handler() to call out to noinstr either.

So noinstr only allows calling noinstr, The above hack only allows it calling uaccess-safe functions, and the group of functions that is both noinstr and uaccess-safe is 'small'.

But like I said yesterday, perhaps this wants it own annotation. Then we can also verify the lack of any dynamic code.

So yes, yuck and a bad idea, ignore this ;-)