From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 02CA7C433F5 for ; Tue, 22 Mar 2022 03:01:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=9FYzN3VTSfTuF6g6mGC2B5Azd0xAfHKiHAMegGmif0U=; b=bZNbCgcphKeYdseEAdSZEAx7iX h/rwYCnH9o7CHKZbVaae+yG780ciO7IJrw4WVwcIRVkwUAPz6mrs9d+LSa+VH+alxvkmTyDT7Yhzx y/RfmWMpXOJJbb8wPddjimC8mce0m3U5cCAle0kR5NiTpAYTdhuM6Fkm2xNiCvvv0+gweblVs4xLw XdW0e/IN8XWOe+vF3tshg1eUGYuVrGBOcs+AwvrFXwyxPyf4CNXOmkPipHKsh4cbIJurJl+37tEGz HuFFqbJz9bYMKfirBm+AQtY2oLCtYm/7XZJvzIBVIA3YWlnch8qyHOpMirtr2D/Nvd3XyxzXVyJJ7 fOzLOAcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWUl1-009oLN-ER; Tue, 22 Mar 2022 03:00:27 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nWUkw-009oKI-HE for linux-arm-kernel@lists.infradead.org; Tue, 22 Mar 2022 03:00:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647918019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=U37WGfHK2Z4UGbsI49VyTpH6r1geuhtlIDY00CwNU9c=; b=Tk2qL6LrWj45O1EHV7Fxv8tiXtQOnkva2IuMbzrTca9LsuufjWVG3dhSiHaL0MLNW6p76Q L8CUo2QmI2jYjytIOP+nfqateG2WMkT43q+x4kqBoX8/FxAT9NPxuZm510jlAvQ7sLb9TB imCaoc7Ps8i9dW0yx3AEsknLadIwOIM= Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-204-fRylGXi_Ni2l0vzjXC__tQ-1; Mon, 21 Mar 2022 23:00:18 -0400 X-MC-Unique: fRylGXi_Ni2l0vzjXC__tQ-1 Received: by mail-pg1-f198.google.com with SMTP id p21-20020a631e55000000b00372d919267cso8123513pgm.1 for ; Mon, 21 Mar 2022 20:00:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=U37WGfHK2Z4UGbsI49VyTpH6r1geuhtlIDY00CwNU9c=; b=YP9Hkz5yFthXsudcirQSQ+gB+SQbqSIpsoahqq0scR9PH/WhRbxzJu+DCgLwqA+Bcr 7uVdwnHaUeSYfnMqZaFEJw1dYQbXDE+r9wDRfKfsPleEqcpJW1IQCFhzoxs9RKQ1z5rb jEfvAZ09QtQtPyBuZoFySh7u1AC7qIxq4PnN8cL38jAAS4TevFgmbAWRJClViPbOZilM Bg4fFjmzpJdcX466Sh2hojbK0VHcSLC+maUErYzfM9vA2rfBMrfiNqH3gJCmVv0tVtq9 GB9841STBYAYVrnUmKzcJsQd+keWvqffjqVwZnnMoUFcHWBPlWyfI+W9kzAgO0D1ShOg YWFA== X-Gm-Message-State: AOAM531JAbuSDk0r9mhkmgC06st2tIm134bPFxhaKX5LFxBObMr38dKd 7o7go6Mu4SV2qpbXOfz2wTEBaCHN+CDgYNUQEMv3sxGWh9gEWPT8hpX5DyHLWXbUv8mRkjV/1c7 apMVEh7C8JoYiwFv6zqk/gQkznPvjrj3JCbo= X-Received: by 2002:a17:902:ca0b:b0:153:b9f5:83b6 with SMTP id w11-20020a170902ca0b00b00153b9f583b6mr16154198pld.166.1647918017070; Mon, 21 Mar 2022 20:00:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvjyr6pauiubtK/5p0j4vfltwVBlreCQd2F76HK9qCghZBEHK9XsTCeHpDHCJELQ737H4j0A== X-Received: by 2002:a17:902:ca0b:b0:153:b9f5:83b6 with SMTP id w11-20020a170902ca0b00b00153b9f583b6mr16154154pld.166.1647918016474; Mon, 21 Mar 2022 20:00:16 -0700 (PDT) Received: from localhost ([240e:3a1:2e5:800:f995:6136:f760:a3d0]) by smtp.gmail.com with ESMTPSA id b20-20020a17090a991400b001befe07ae5csm768330pjp.22.2022.03.21.20.00.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 20:00:15 -0700 (PDT) Date: Tue, 22 Mar 2022 10:59:12 +0800 From: Coiby Xu To: Baoquan He Cc: kexec@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Dave Young , Will Deacon , "Eric W . Biederman" , open list Subject: Re: [PATCH v4 1/3] kexec: clean up arch_kexec_kernel_verify_sig Message-ID: <20220322025912.r2ahc2ztx3npt7av@Rk> References: <20220318094101.274950-1-coxu@redhat.com> <20220318094101.274950-2-coxu@redhat.com> MIME-Version: 1.0 In-Reply-To: Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=coxu@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220321_200022_825672_EAD1665A X-CRM114-Status: GOOD ( 22.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Mar 21, 2022 at 12:21:33PM +0800, Baoquan He wrote: >On 03/18/22 at 05:40pm, Coiby Xu wrote: >> Commit 9ec4ecef0af7 ("kexec_file,x86,powerpc: factor out kexec_file_ops >> functions") allows implementing the arch-specific implementation of kernel >> image verification in kexec_file_ops->verify_sig. Currently, there is no > >Looking back at the old commit 9ec4ecef0af7, it mistakenly added a >generic arch_kexec_kernel_verify_sig() which is marked as __weak, >and expects any architecture will add a arch specified version if needed. >In fact those arch specified difference has been removed by wrapping >them into each architecture's own struct kexec_file_ops methods. Means >in the commit, the generic arch_kexec_kernel_verify_sig() is unnecessary >at all. Thanks for looking at commit 9ec4ecef0af7 for me! Although commit 9ec4ecef0af7 added some code in arch_kexec_kernel_verify_sig so kexec_file_ops->verify_sig can be called, this commit doesn't add __weak arch_kexec_kernel_verify_sig itself. And kexec_file_ops isn't supposed to replace arch-specific implementation using __weak considering s390 and x86 still make use of __weak to implement its own version of arch_kexec_apply_relocations_add. How about the commit message as follows? Currently this no arch-specific implementation of arch_kexec_kernel_verify_sig. Even if we want to add an implementation for an architecture in the future, we can simply use "(struct kexec_file_ops*)->verify_sig". So clean it up. > >Now, you clean up that uncessary function with code change. > >I think description telling above analysis could be clearer. > >> arch-specific implementation of arch_kexec_kernel_verify_sig. So clean it >> up. >> >> Suggested-by: Eric W. Biederman >> Signed-off-by: Coiby Xu >> --- >> include/linux/kexec.h | 4 ---- >> kernel/kexec_file.c | 34 +++++++++++++--------------------- >> 2 files changed, 13 insertions(+), 25 deletions(-) >> >> diff --git a/include/linux/kexec.h b/include/linux/kexec.h >> index 0c994ae37729..755fed183224 100644 >> --- a/include/linux/kexec.h >> +++ b/include/linux/kexec.h >> @@ -196,10 +196,6 @@ int arch_kexec_apply_relocations(struct purgatory_info *pi, >> const Elf_Shdr *relsec, >> const Elf_Shdr *symtab); >> int arch_kimage_file_post_load_cleanup(struct kimage *image); >> -#ifdef CONFIG_KEXEC_SIG >> -int arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, >> - unsigned long buf_len); >> -#endif >> int arch_kexec_locate_mem_hole(struct kexec_buf *kbuf); >> >> extern int kexec_add_buffer(struct kexec_buf *kbuf); >> diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c >> index 8347fc158d2b..3720435807eb 100644 >> --- a/kernel/kexec_file.c >> +++ b/kernel/kexec_file.c >> @@ -89,25 +89,6 @@ int __weak arch_kimage_file_post_load_cleanup(struct kimage *image) >> return kexec_image_post_load_cleanup_default(image); >> } >> >> -#ifdef CONFIG_KEXEC_SIG >> -static int kexec_image_verify_sig_default(struct kimage *image, void *buf, >> - unsigned long buf_len) >> -{ >> - if (!image->fops || !image->fops->verify_sig) { >> - pr_debug("kernel loader does not support signature verification.\n"); >> - return -EKEYREJECTED; >> - } >> - >> - return image->fops->verify_sig(buf, buf_len); >> -} >> - >> -int __weak arch_kexec_kernel_verify_sig(struct kimage *image, void *buf, >> - unsigned long buf_len) >> -{ >> - return kexec_image_verify_sig_default(image, buf, buf_len); >> -} >> -#endif >> - >> /* >> * arch_kexec_apply_relocations_add - apply relocations of type RELA >> * @pi: Purgatory to be relocated. >> @@ -184,13 +165,24 @@ void kimage_file_post_load_cleanup(struct kimage *image) >> } >> >> #ifdef CONFIG_KEXEC_SIG >> +static int kexec_image_verify_sig(struct kimage *image, void *buf, >> + unsigned long buf_len) >> +{ >> + if (!image->fops || !image->fops->verify_sig) { >> + pr_debug("kernel loader does not support signature verification.\n"); >> + return -EKEYREJECTED; >> + } >> + >> + return image->fops->verify_sig(buf, buf_len); >> +} >> + >> static int >> kimage_validate_signature(struct kimage *image) >> { >> int ret; >> >> - ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf, >> - image->kernel_buf_len); >> + ret = kexec_image_verify_sig(image, image->kernel_buf, >> + image->kernel_buf_len); >> if (ret) { >> >> if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) { >> -- >> 2.34.1 >> > -- Best regards, Coiby _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel