Received: by 2002:a25:2c96:0:0:0:0:0 with SMTP id s144csp806557ybs; Sun, 24 May 2020 22:45:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy2LreRUclupXGCQM1XmfyxJctdUBGZpEt1wN9VSQZw/CTOaO5uCWZ5icZfBxMgDd1ggRSf X-Received: by 2002:aa7:d8d3:: with SMTP id k19mr13786650eds.348.1590385524217; Sun, 24 May 2020 22:45:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590385524; cv=none; d=google.com; s=arc-20160816; b=NnjFHHvarswHYKlF0eAHQaOuvLaws2xIkrMkRQ+CzCYywwp7KS09UvQtA2vl3hI4v7 t/Rp4sZLJEMLrwHGGzl2O2Yd8gH2tzj0YvrEmf77SN/6fxN8APIr9HcT33PEWi6Dk/4i jzaUje1eal8/RlDBlU7JLMfUQzQa2ezws+o7Rc1eBlM6+b5o5KH3xvg4m03waor4DGVr KSwrmrloUXMNPiTi/kPi41M5rxnccdvELjv6g+7IVMwv6yGeTXcgLSyNZVMB4uAEf8lK sDhVBc4QeGoG2DbjmZ/ttVnnl6S+KSFdEj5MHf5VmX7ncZ1ywowMBGYhzqsCe7CTZW7F jLPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=m8Q62JV0BmlHzoSRYQ9uz5MfhUk1rLzhDZGQnnGc94o=; b=vm4jMO41eHijHPLuHbcaa1291s5Mj3FYyiglZFwLzL5tBObnHVWiElmhPrAhuQhwPy 0rSUcB+duvHejPrbIuqmWikJVw+ocdjnXM+NPl9wx97/aihJUKtUyeUPaGg7YG+VXcJS AONaEDM/MtyYOwhS0qLYJGJ7bu4/dCuaB4LGAYc1DihuDUFUIL2OAWes9FIbVMw3UxrL 8S471xzBxDe0+m0xXiiQmTGgHTiPRmingxSMpa+kLhPHf7wEe4j/P9JR6etb0kbaExfu uGQOSg77rUgcrnwxmRReASYOvi//luePYUDaqN0lo+Sa/NG1b5Tr4u1rtNQ65tFZFMAe uQmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VdwSkphG; 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 e3si8618644edq.595.2020.05.24.22.45.01; Sun, 24 May 2020 22:45:24 -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=VdwSkphG; 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 S1729544AbgEYFYH (ORCPT + 99 others); Mon, 25 May 2020 01:24:07 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:35167 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725802AbgEYFYH (ORCPT ); Mon, 25 May 2020 01:24:07 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1590384245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc; bh=m8Q62JV0BmlHzoSRYQ9uz5MfhUk1rLzhDZGQnnGc94o=; b=VdwSkphGHCXKYQJUYFlGobKSCnb04N/QG128RhsYz7XjMf5ZWHzi29cBrHBkg/Aw4z03UI cLE1cF2cwIeBDHahvVIWiSVl6qTIXtwfzdwMAFyNpzVfUdDWTGYeFP+43poQEM/gUxE7A/ vtBsQN0cCI5RKH17ibsapCW5CxdjkMk= 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-130-llTZDW1GOX6Nm6zbld2OqQ-1; Mon, 25 May 2020 01:24:02 -0400 X-MC-Unique: llTZDW1GOX6Nm6zbld2OqQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AF831005510; Mon, 25 May 2020 05:24:01 +0000 (UTC) Received: from unused.redhat.com (ovpn-12-206.pek2.redhat.com [10.72.12.206]) by smtp.corp.redhat.com (Postfix) with ESMTP id ABBE319D7B; Mon, 25 May 2020 05:23:53 +0000 (UTC) From: Lianbo Jiang To: linux-kernel@vger.kernel.org Cc: kexec@lists.infradead.org, ebiederm@xmission.com, jbohac@suse.cz, jmorris@namei.org, mjg59@google.com, dyoung@redhat.com, bhe@redhat.com Subject: [PATCH] kexec: Do not verify the signature without the lockdown or mandatory signature Date: Mon, 25 May 2020 13:23:51 +0800 Message-Id: <20200525052351.24134-1-lijiang@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- kernel/kexec_file.c | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index faa74d5f6941..e4bdf0c42f35 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -181,52 +181,27 @@ 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) { + pr_debug("kernel signature verification failed (%d).\n", 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); + if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) 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. */ if (!ima_appraise_signature(READING_KEXEC_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); } - return ret; + return 0; } #endif -- 2.17.1