Received: by 2002:a05:6358:c692:b0:131:369:b2a3 with SMTP id fe18csp842060rwb; Wed, 26 Jul 2023 03:57:53 -0700 (PDT) X-Google-Smtp-Source: APBJJlHCTOh7MU1waBsAZYYFWEHVymrIvHSmQg2BOTQAwmbuzfaSFNJ/zH+f5VGQmOCGa+eAow1e X-Received: by 2002:a05:6a20:2585:b0:138:64d4:b040 with SMTP id k5-20020a056a20258500b0013864d4b040mr1830053pzd.54.1690369072589; Wed, 26 Jul 2023 03:57:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690369072; cv=none; d=google.com; s=arc-20160816; b=bcHTjcZwE/hSxb1UyndA2nSQrPf8b9qBxpx9c8+V8J6bo1NdvT0d/OHo0rPVQNoJ5X CSfvvGouEZVoK1AG3DAEhTzSGCyH7V6I3HdTn79JKqOGojtKo0fqQNSfFABtVQuirqWs AfdxCPpRrMoEgDDk3y/gdkO6HLbf1sR8OW4OmfOym/fVO4IUK3lkA6ntkIZnU7kKIyKm 51bCtqnBM1JTBN8VShV/M8tkf4zXrUN+9T8J5loIGKO0kxK9U7DYrlrO7kyFZ69i0EOI LQJcaFCBWPf3Hs8c/beQC9SpLiPcPqz6VNyNND82pDM6sMBOYqJzWWn6NhXQ8pTB92RV UbtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=hagzE391dr3tCo4cDvULXXywya5f7f6Crzym/fqDDTw=; fh=628iOkxKoFjwYFpe4/UUsO7eEG2fFpt/bCqQ+fGWed4=; b=JmDblFSHdSlij9xnp4/FI7eS+cxQnNEK17p9YRkNKUKUTsWg8necSsXRFP3AaMFD0M 3KGdn1LR/uMfmCUtCF4hfoZJ8Z7Ul9PQNsWompwfKnGI5FO/ldqV5e9xcE/UwtjvrQ7O Sruesstkddet177ST2DupI3SKg7+gpzUi2kcZAXYH7EHMYjrD1KzuvbbOJAdjGoKybmE eJiCaxuRULMECe1bz+zF+gX5ZAyi8exrklBXMsk3IuBmqEkns1++m0n3zwFhRv4OCxBd OEmhNd1JZ5FnZ22aB/d8AT4iBTBgXVSOzSWOP5AaYdjq4eQTM5YgqfW99tvddDcClqll +exw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a63de57000000b00553d7157e8bsi12799099pgi.794.2023.07.26.03.57.39; Wed, 26 Jul 2023 03:57:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233708AbjGZJ4d (ORCPT + 99 others); Wed, 26 Jul 2023 05:56:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231674AbjGZJ4D (ORCPT ); Wed, 26 Jul 2023 05:56:03 -0400 Received: from frasgout12.his.huawei.com (unknown [14.137.139.154]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F6AD3A9B for ; Wed, 26 Jul 2023 02:55:11 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.18.147.229]) by frasgout12.his.huawei.com (SkyGuard) with ESMTP id 4R9pns1939z9ttCx for ; Wed, 26 Jul 2023 17:41:53 +0800 (CST) Received: from A2101119013HW2.china.huawei.com (unknown [10.81.211.226]) by APP1 (Coremail) with SMTP id LxC2BwBHo95C7cBk+WYTBQ--.33492S4; Wed, 26 Jul 2023 10:54:43 +0100 (CET) From: Petr Tesarik To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Li Huafei , Liao Chang , Masahiro Yamada , Kees Cook , Andrew Morton , Heiko Stuebner , Ricardo Ribalda , Alyssa Ross , Li Zhengyu , linux-riscv@lists.infradead.org (open list:RISC-V ARCHITECTURE), kexec@lists.infradead.org, linux-kernel@vger.kernel.org (open list) Cc: Torsten Duwe , Roberto Sassu , petr@tesarici.cz Subject: [PATCH v2 2/3] riscv/purgatory: do not link with string.o and its dependencies Date: Wed, 26 Jul 2023 11:54:00 +0200 Message-Id: <2832b3e5ac781a0c0ade9d77b15a80e7f2fb4ab2.1690365011.git.petr.tesarik.ext@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: LxC2BwBHo95C7cBk+WYTBQ--.33492S4 X-Coremail-Antispam: 1UD129KBjvJXoWxAF47uFy3CF13tF15tr43Jrb_yoWrWF1fpa yxG34kK3yUAwn7Krn2y3WUWw45AayUKryFgF4j93y5CF45AF9Ikr93W3yqyFyUJryIk348 CryFgFy5ta1FkwUanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUQS14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jryl82xGYIkIc2 x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Jr0_JF4l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_Gr0_Cr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1lc7CjxVAaw2AFwI0_Jw0_GFylc7CjxVAKzI0EY4vE52x082I5MxAIw28IcxkI7VAK I48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7 xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xII jxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1lIxAIcVCF04 k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7Cj xVAFwI0_Gr1j6F4UJbIYCTnIWIevJa73UjIFyTuYvjfUnxhLUUUUU X-CM-SenderInfo: hshw23xhvd2x3n6k3tpzhluzxrxghudrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, RCVD_IN_MSPIKE_BL,RCVD_IN_MSPIKE_L3,RDNS_DYNAMIC,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Petr Tesarik 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 Cc: Li Zhengyu Cc: stable@vger.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