Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp540371ybg; Wed, 10 Jun 2020 07:21:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnbvjuXLtxgi0kkSot2js/3Sd4rXt1sI7qX89X90k4ZDVEzb9qZFSnG7gPCTAS57OHLEdi X-Received: by 2002:a17:906:4f13:: with SMTP id t19mr3417175eju.269.1591798866821; Wed, 10 Jun 2020 07:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591798866; cv=none; d=google.com; s=arc-20160816; b=Z3JyDzU0XJNCMJPvM5K0kTevc9ewaD1gOrFUVySnN0z/3akdUZWAQaJw1dHDJ9NuxH Pwvsn135lip7Xs1xoMzJoyybE3KhU+U34kXPeLaN99/YIVk65OKQ0tZfQftSyjFua61/ dXEZAHeav84CtpLvrc8s6TlCYgUucDXzgkkpIW888gMSdZbIvnEociW0Jt4voUs5GHo9 Om3Mwwi3G5Yj5FPRGV1gZJzMapRtwFQQXaC2T6czPYmiFjD7+lPtZJgotdp/BxyPLVu3 4XghU5v7lPF3YiK2Kn10t6HteJ+12k1/ds1RwwODJEOSyz9ZDEvM455SYmQ2R3t0Xalf 7/Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject:dkim-signature; bh=OI3aCfsDdegeLI3ZNTVz0fiZIXbxW2AX3bbw/1MUDHM=; b=FjYeLcEPKDIpd4C1WPIshdj2rBOmvdNa26VIlmgXhlBwUYuYfMhsi0pRdxUOZbRnAr M9JO2ruyQHYNQXp+6iR1mGyl9nNj2X9KnbEsvzvs2VoIDc3AtPOi6qUGGFBHZVkPYaJS Vh908FzOjNBUELADibBZoNdwClwYPN8eYUs7mLAvs30Zl2MXjnBbqF1iwPkU1Oz5kKSH 7pc3ymorBbfO18iUb42qUQ9MHv/E9dkROioQN0PO8NyhfiNn9yQ7Y3zJ0SFbsdAOe+1K HjBOexFm8reFXVG+UQzdeaaZ6hUwOiJcwHOYR5VFKasBX/bcxP0/ufhRAwjfwPKsCMXZ mk+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jKGASy0+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d13si64627ejw.753.2020.06.10.07.20.43; Wed, 10 Jun 2020 07:21:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=jKGASy0+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbgFJIV5 (ORCPT + 99 others); Wed, 10 Jun 2020 04:21:57 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:28918 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726081AbgFJIV5 (ORCPT ); Wed, 10 Jun 2020 04:21:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591777315; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OI3aCfsDdegeLI3ZNTVz0fiZIXbxW2AX3bbw/1MUDHM=; b=jKGASy0+2eUDcNnvnsxJ59efVtXdEuANsfTcfOkAzYRo8dhKsRoUty5YUHZgdna32QBNxm 36bHigOS1JS49f9Iqb/jCkIyoUXEnfNSHB888gtSHcFK9+chX6DYtMNSQUMaPy2WHHCi4t si7W+oASvIJDD7HRqyOodmDz4vxOBEA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-6cSuREqVPdadQqwv8jTYFQ-1; Wed, 10 Jun 2020 04:21:51 -0400 X-MC-Unique: 6cSuREqVPdadQqwv8jTYFQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D946018A8220; Wed, 10 Jun 2020 08:21:49 +0000 (UTC) Received: from [10.72.12.51] (ovpn-12-51.pek2.redhat.com [10.72.12.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 45A125D9D3; Wed, 10 Jun 2020 08:21:42 +0000 (UTC) Subject: Re: [PATCH v2] kexec: Do not verify the signature without the lockdown or mandatory signature From: lijiang To: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, "ebiederm@xmission.com" Cc: kexec@lists.infradead.org, ebiederm@xmission.com, jbohac@suse.cz, jmorris@namei.org, mjg59@google.com, dyoung@redhat.com, bhe@redhat.com References: <20200602045952.27487-1-lijiang@redhat.com> Message-ID: <49d2af1c-bcbf-41d8-071c-93cce024b47b@redhat.com> Date: Wed, 10 Jun 2020 16:21:40 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200602045952.27487-1-lijiang@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I just noticed that I forgot to add Eric Biederman in cc list, so sorry for this. Thanks. Lianbo 在 2020年06月02日 12:59, Lianbo Jiang 写道: > Signature verification is an important security feature, to protect > system from being attacked with a kernel of unknown origin. Kexec > rebooting is a way to replace the running kernel, hence need be > secured carefully. > > In the current code of handling signature verification of kexec kernel, > the logic is very twisted. It mixes signature verification, IMA signature > appraising and kexec lockdown. > > If there is no KEXEC_SIG_FORCE, kexec kernel image doesn't have one of > signature, the supported crypto, and key, we don't think this is wrong, > Unless kexec lockdown is executed. IMA is considered as another kind of > signature appraising method. > > If kexec kernel image has signature/crypto/key, it has to go through the > signature verification and pass. Otherwise it's seen as verification > failure, and won't be loaded. > > Seems kexec kernel image with an unqualified signature is even worse than > those w/o signature at all, this sounds very unreasonable. E.g. If people > get a unsigned kernel to load, or a kernel signed with expired key, which > one is more dangerous? > > So, here, let's simplify the logic to improve code readability. If the > KEXEC_SIG_FORCE enabled or kexec lockdown enabled, signature verification > is mandated. Otherwise, we lift the bar for any kernel image. > > Signed-off-by: Lianbo Jiang > --- > Changes since v1: > [1] Modify the log level(suggested by Jiri Bohac) > > kernel/kexec_file.c | 34 ++++++---------------------------- > 1 file changed, 6 insertions(+), 28 deletions(-) > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > index faa74d5f6941..fae496958a68 100644 > --- a/kernel/kexec_file.c > +++ b/kernel/kexec_file.c > @@ -181,34 +181,19 @@ void kimage_file_post_load_cleanup(struct kimage *image) > static int > kimage_validate_signature(struct kimage *image) > { > - const char *reason; > int ret; > > ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf, > image->kernel_buf_len); > - switch (ret) { > - case 0: > - break; > + if (ret) { > > - /* Certain verification errors are non-fatal if we're not > - * checking errors, provided we aren't mandating that there > - * must be a valid signature. > - */ > - case -ENODATA: > - reason = "kexec of unsigned image"; > - goto decide; > - case -ENOPKG: > - reason = "kexec of image with unsupported crypto"; > - goto decide; > - case -ENOKEY: > - reason = "kexec of image with unavailable key"; > - decide: > if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) { > - pr_notice("%s rejected\n", reason); > + pr_notice("Enforced kernel signature verification failed (%d).\n", ret); > return ret; > } > > - /* If IMA is guaranteed to appraise a signature on the kexec > + /* > + * If IMA is guaranteed to appraise a signature on the kexec > * image, permit it even if the kernel is otherwise locked > * down. > */ > @@ -216,17 +201,10 @@ kimage_validate_signature(struct kimage *image) > security_locked_down(LOCKDOWN_KEXEC)) > return -EPERM; > > - return 0; > - > - /* All other errors are fatal, including nomem, unparseable > - * signatures and signature check failures - even if signatures > - * aren't required. > - */ > - default: > - pr_notice("kernel signature verification failed (%d).\n", ret); > + pr_debug("kernel signature verification failed (%d).\n", ret); > } > > - return ret; > + return 0; > } > #endif > >