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-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <ebe11b73d1015a17034a2c4bedf093fa57f5d29f.1662032631.git.christophe.leroy@csgroup.eu>
Date:   Thu,  1 Sep 2022 13:48:20 +0200
From:   Christophe Leroy <christophe.leroy@...roup.eu>
To:     Michael Ellerman <mpe@...erman.id.au>,
        Nicholas Piggin <npiggin@...il.com>, sv@...ux.ibm.com,
        bgray@...ux.ibm.com, agust@...x.de, jpoimboe@...nel.org,
        peterz@...radead.org, jbaron@...mai.com, rostedt@...dmis.org,
        ardb@...nel.org, tglx@...utronix.de, mingo@...hat.com,
        bp@...en8.de, dave.hansen@...ux.intel.com, hpa@...or.com
Cc:     Christophe Leroy <christophe.leroy@...roup.eu>,
        linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org,
        x86@...nel.org, chenzhongjin@...wei.com
Subject: [PATCH v3 1/6] Fixup for "objtool/powerpc: Add --mcount specific implementation"

Make arch_decode_instruction() more future proof and less error prone:
- Use local vars for type and imm so that GCC will detect when we
forget to update them
- Handle imm outside the branch type check
- Adapt len for prefixed instructions

Handle the four branch types b, bl, ba, bla

Part of it should probably go into "objtool/powerpc: Enable objtool
to be built on ppc" for instance the setup of the len. Maybe all the
skeleton with the local vars, the switch with its default, etc ...
Then following patches only have to add stuff inside the switch.

Signed-off-by: Christophe Leroy <christophe.leroy@...roup.eu>
---
 tools/objtool/arch/powerpc/decode.c | 39 +++++++++++++++++++++--------
 1 file changed, 28 insertions(+), 11 deletions(-)

diff --git a/tools/objtool/arch/powerpc/decode.c b/tools/objtool/arch/powerpc/decode.c
index b71c265ed503..f9932351908c 100644
--- a/tools/objtool/arch/powerpc/decode.c
+++ b/tools/objtool/arch/powerpc/decode.c
@@ -50,31 +50,48 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec
 {
 	u32 insn;
 	unsigned int opcode;
+	unsigned long imm;
+	enum insn_type typ;
 
-	*immediate = 0;
 	insn = bswap_if_needed(file->elf, *(u32 *)(sec->data->d_buf + offset));
-	*len = 4;
-	*type = INSN_OTHER;
 
 	opcode = insn >> 26;
 
 	switch (opcode) {
-	case 18: /* bl */
-		if ((insn & 3) == 1) {
-			*type = INSN_CALL;
-			*immediate = insn & 0x3fffffc;
-			if (*immediate & 0x2000000)
-				*immediate -= 0x4000000;
-		}
+	case 18: /* bl/b/bla/ba */
+		if (insn & 1)
+			typ = INSN_CALL;
+		else
+			typ = INSN_JUMP_UNCONDITIONAL;
+
+		imm = insn & 0x3fffffc;
+		if (imm & 0x2000000)
+			imm -= 0x4000000;
+		imm |= insn & 2;	/* AA flag */
+		break;
+	default:
+		typ = INSN_OTHER;
+		imm = 0;
 		break;
 	}
 
+	if (opcode == 1)
+		*len = 8;
+	else
+		*len = 4;
+
+	*type = typ;
+	*immediate = imm;
+
 	return 0;
 }
 
 unsigned long arch_jump_destination(struct instruction *insn)
 {
-	return insn->offset +  insn->immediate;
+	if (insn->immediate & 2)
+		return insn->immediate & ~2;
+
+	return insn->offset + insn->immediate;
 }
 
 void arch_initial_func_cfi_state(struct cfi_init_state *state)
-- 
2.37.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ