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: <2832b3e5ac781a0c0ade9d77b15a80e7f2fb4ab2.1690365011.git.petr.tesarik.ext@huawei.com>
Date:   Wed, 26 Jul 2023 11:54:00 +0200
From:   Petr Tesarik <petrtesarik@...weicloud.com>
To:     Paul Walmsley <paul.walmsley@...ive.com>,
        Palmer Dabbelt <palmer@...belt.com>,
        Albert Ou <aou@...s.berkeley.edu>,
        Conor Dooley <conor.dooley@...rochip.com>,
        Li Huafei <lihuafei1@...wei.com>,
        Liao Chang <liaochang1@...wei.com>,
        Masahiro Yamada <masahiroy@...nel.org>,
        Kees Cook <keescook@...omium.org>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Heiko Stuebner <heiko@...ech.de>,
        Ricardo Ribalda <ribalda@...omium.org>,
        Alyssa Ross <hi@...ssa.is>, Li Zhengyu <lizhengyu3@...wei.com>,
        linux-riscv@...ts.infradead.org (open list:RISC-V ARCHITECTURE),
        kexec@...ts.infradead.org, linux-kernel@...r.kernel.org (open list)
Cc:     Torsten Duwe <duwe@...e.de>,
        Roberto Sassu <roberto.sassu@...weicloud.com>, petr@...arici.cz
Subject: [PATCH v2 2/3] riscv/purgatory: do not link with string.o and its dependencies

From: Petr Tesarik <petr.tesarik.ext@...wei.com>

Linking with this object file makes kexec_file_load(2) fail because of
multiple unknown relocation types:

- R_RISCV_ADD16, R_RISCV_SUB16: used by alternatives in strcmp()
- R_RISCV_GOT_HI20: used to resolve _ctype in strcasecmp()

All this hassle is needed for one single call to memcmp() from
verify_sha256_digest() to compare 32 bytes of SHA256 checksum.

Simply replace this memcmp() call with an explicit loop over those 32 bytes
and remove the need to link with string.o and all the other object files
that provide undefined symbols from that object file.

Fixes: 838b3e28488f ("RISC-V: Load purgatory in kexec_file")
Signed-off-by: Petr Tesarik <petr.tesarik.ext@...wei.com>
Cc: Li Zhengyu <lizhengyu3@...wei.com>
Cc: stable@...r.kernel.org
---
 arch/riscv/purgatory/Makefile    | 26 +-------------------------
 arch/riscv/purgatory/purgatory.c |  6 ++++--
 2 files changed, 5 insertions(+), 27 deletions(-)

diff --git a/arch/riscv/purgatory/Makefile b/arch/riscv/purgatory/Makefile
index dc20e166983e..00f50cd29310 100644
--- a/arch/riscv/purgatory/Makefile
+++ b/arch/riscv/purgatory/Makefile
@@ -1,39 +1,21 @@
 # SPDX-License-Identifier: GPL-2.0
 OBJECT_FILES_NON_STANDARD := y
 
-purgatory-y := purgatory.o sha256.o entry.o string.o ctype.o memcpy.o memset.o
-purgatory-y += strcmp.o strlen.o strncmp.o
+purgatory-y := purgatory.o sha256.o entry.o memcpy.o memset.o
 
 targets += $(purgatory-y)
 PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
 
-$(obj)/string.o: $(srctree)/lib/string.c FORCE
-	$(call if_changed_rule,cc_o_c)
-
-$(obj)/ctype.o: $(srctree)/lib/ctype.c FORCE
-	$(call if_changed_rule,cc_o_c)
-
 $(obj)/memcpy.o: $(srctree)/arch/riscv/lib/memcpy.S FORCE
 	$(call if_changed_rule,as_o_S)
 
 $(obj)/memset.o: $(srctree)/arch/riscv/lib/memset.S FORCE
 	$(call if_changed_rule,as_o_S)
 
-$(obj)/strcmp.o: $(srctree)/arch/riscv/lib/strcmp.S FORCE
-	$(call if_changed_rule,as_o_S)
-
-$(obj)/strlen.o: $(srctree)/arch/riscv/lib/strlen.S FORCE
-	$(call if_changed_rule,as_o_S)
-
-$(obj)/strncmp.o: $(srctree)/arch/riscv/lib/strncmp.S FORCE
-	$(call if_changed_rule,as_o_S)
-
 $(obj)/sha256.o: $(srctree)/lib/crypto/sha256.c FORCE
 	$(call if_changed_rule,cc_o_c)
 
 CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
-CFLAGS_string.o := -D__DISABLE_EXPORTS
-CFLAGS_ctype.o := -D__DISABLE_EXPORTS
 
 # When profile-guided optimization is enabled, llvm emits two different
 # overlapping text sections, which is not supported by kexec. Remove profile
@@ -83,12 +65,6 @@ CFLAGS_purgatory.o		+= $(PURGATORY_CFLAGS)
 CFLAGS_REMOVE_sha256.o		+= $(PURGATORY_CFLAGS_REMOVE)
 CFLAGS_sha256.o			+= $(PURGATORY_CFLAGS)
 
-CFLAGS_REMOVE_string.o		+= $(PURGATORY_CFLAGS_REMOVE)
-CFLAGS_string.o			+= $(PURGATORY_CFLAGS)
-
-CFLAGS_REMOVE_ctype.o		+= $(PURGATORY_CFLAGS_REMOVE)
-CFLAGS_ctype.o			+= $(PURGATORY_CFLAGS)
-
 asflags-remove-y		+= $(foreach x, -g -gdwarf-4 -gdwarf-5, $(x) -Wa,$(x))
 
 $(obj)/purgatory.ro: $(PURGATORY_OBJS) FORCE
diff --git a/arch/riscv/purgatory/purgatory.c b/arch/riscv/purgatory/purgatory.c
index 80596ab5fb62..1d30103d2047 100644
--- a/arch/riscv/purgatory/purgatory.c
+++ b/arch/riscv/purgatory/purgatory.c
@@ -22,14 +22,16 @@ static int verify_sha256_digest(void)
 	struct kexec_sha_region *ptr, *end;
 	struct sha256_state ss;
 	u8 digest[SHA256_DIGEST_SIZE];
+	int i;
 
 	sha256_init(&ss);
 	end = purgatory_sha_regions + ARRAY_SIZE(purgatory_sha_regions);
 	for (ptr = purgatory_sha_regions; ptr < end; ptr++)
 		sha256_update(&ss, (uint8_t *)(ptr->start), ptr->len);
 	sha256_final(&ss, digest);
-	if (memcmp(digest, purgatory_sha256_digest, sizeof(digest)) != 0)
-		return 1;
+	for (i = 0; i < SHA256_DIGEST_SIZE; ++i)
+		if (digest[i] != purgatory_sha256_digest[i])
+			return 1;
 	return 0;
 }
 
-- 
2.25.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ