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: <20231122092855.4440-3-shijie@os.amperecomputing.com>
Date:   Wed, 22 Nov 2023 17:28:53 +0800
From:   Huang Shijie <shijie@...amperecomputing.com>
To:     catalin.marinas@....com
Cc:     will@...nel.org, mark.rutland@....com, suzuki.poulose@....com,
        broonie@...nel.org, linux-arm-kernel@...ts.infradead.org,
        linux-kernel@...r.kernel.org, anshuman.khandual@....com,
        robh@...nel.org, oliver.upton@...ux.dev, maz@...nel.org,
        patches@...erecomputing.com,
        Huang Shijie <shijie@...amperecomputing.com>
Subject: [PATCH 2/4] arm64: alternative: handle the kernel exception table

In arch/arm64/lib/copy_templates.S, some macros involve kernel exception table,
such as ldp1/stp1/strh1/str1,etc. Current alternative_if does not support
to embed them.

This patch adds the support to embed them into alternative_if:
	1.) Modify the @insn to the right address,
	2.) Sort the kernel exception table.

Signed-off-by: Huang Shijie <shijie@...amperecomputing.com>
---
 arch/arm64/kernel/alternative.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
index 8ff6610af496..4c73f9cc9a85 100644
--- a/arch/arm64/kernel/alternative.c
+++ b/arch/arm64/kernel/alternative.c
@@ -19,6 +19,7 @@
 #include <asm/sections.h>
 #include <asm/vdso.h>
 #include <linux/stop_machine.h>
+#include <linux/extable.h>
 
 #define __ALT_PTR(a, f)		((void *)&(a)->f + (a)->f)
 #define ALT_ORIG_PTR(a)		__ALT_PTR(a, orig_offset)
@@ -101,6 +102,22 @@ static __always_inline u32 get_alt_insn(struct alt_instr *alt, __le32 *insnptr,
 	return insn;
 }
 
+/* Check the kernel exception table */
+static void check_extable(__le32 *origptr, __le32 *updptr, __le32 *replptr)
+{
+	struct exception_table_entry *e;
+	unsigned long addr = (unsigned long)replptr;
+
+	e = (struct exception_table_entry *)search_kernel_exception_table(addr);
+	if (e) {
+		/* Modify the @insn to the right address */
+		e->insn = cpu_to_le32((int)((long)(origptr) - (long)(&e->insn)));
+
+		/* Sort the kernel exception table */
+		__sort_main_extable();
+	}
+}
+
 static noinstr void patch_alternative(struct alt_instr *alt,
 			      __le32 *origptr, __le32 *updptr, int nr_inst)
 {
@@ -112,6 +129,7 @@ static noinstr void patch_alternative(struct alt_instr *alt,
 		u32 insn;
 
 		insn = get_alt_insn(alt, origptr + i, replptr + i);
+		check_extable(origptr + i, updptr + i, replptr + i);
 		updptr[i] = cpu_to_le32(insn);
 	}
 }
-- 
2.40.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ