[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1a5496d5031c7d4ff50b61a34973a8c975fb4972.1592510545.git.mhelsley@vmware.com>
Date: Thu, 18 Jun 2020 13:38:25 -0700
From: Matt Helsley <mhelsley@...are.com>
To: <linux-kernel@...r.kernel.org>
CC: Josh Poimboeuf <jpoimboe@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Steven Rostedt <rostedt@...dmis.org>,
Julien Thierry <jthierry@...hat.com>,
Kamalesh Babulal <kamalesh@...ux.vnet.ibm.com>,
Matt Helsley <mhelsley@...are.com>
Subject: [RFC][PATCH v5 39/51] objtool: mcount: Verify x86 instruction with memcmp()
Instead of hard-coding what amounts to a memcmp() use memcmp to
determine if the instruction we wish to replace matches what we
expect. This makes the x86 code more like that of, for instance,
ARM.
Signed-off-by: Matt Helsley <mhelsley@...are.com>
---
tools/objtool/mcount.c | 19 ++++++-------------
1 file changed, 6 insertions(+), 13 deletions(-)
diff --git a/tools/objtool/mcount.c b/tools/objtool/mcount.c
index 4d6596a031bf..5c59df0df97b 100644
--- a/tools/objtool/mcount.c
+++ b/tools/objtool/mcount.c
@@ -47,9 +47,10 @@ extern int warn_on_notrace_sect; /* warn when section has mcount not being recor
static struct elf *lf;
-static unsigned char ideal_nop5_x86_64[5] = { 0x0f, 0x1f, 0x44, 0x00, 0x00 };
-static unsigned char ideal_nop5_x86_32[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
-static unsigned char *ideal_nop;
+static const unsigned char ip_relative_call_x86[5] = { 0xe8, 0x00, 0x00, 0x00, 0x00 };
+static const unsigned char ideal_nop5_x86_64[5] = { 0x0f, 0x1f, 0x44, 0x00, 0x00 };
+static const unsigned char ideal_nop5_x86_32[5] = { 0x3e, 0x8d, 0x74, 0x26, 0x00 };
+static const unsigned char *ideal_nop;
static char rel_type_nop;
@@ -57,20 +58,12 @@ static int (*make_nop)(struct section *, size_t const offset);
static int make_nop_x86(struct section *txts, size_t const offset)
{
- uint32_t *ptr;
- unsigned char *op;
- void *map = txts->data->d_buf;
+ unsigned char *op = txts->data->d_buf + offset - 1;
if (offset < 1)
return -1;
- /* Confirm we have 0xe8 0x0 0x0 0x0 0x0 */
- ptr = map + offset;
- if (*ptr != 0)
- return -1;
-
- op = map + offset - 1;
- if (*op != 0xe8)
+ if (memcmp(op, ip_relative_call_x86, 5) != 0)
return -1;
/* convert to nop */
--
2.20.1
Powered by blists - more mailing lists