From patchwork Tue Aug 13 19:21:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 11092787 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8604414D5 for ; Tue, 13 Aug 2019 19:21:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 76188204FA for ; Tue, 13 Aug 2019 19:21:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 68EEF28706; Tue, 13 Aug 2019 19:21:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_HI,USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0ADD204FA for ; Tue, 13 Aug 2019 19:21:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726188AbfHMTVj (ORCPT ); Tue, 13 Aug 2019 15:21:39 -0400 Received: from mail-ua1-f73.google.com ([209.85.222.73]:42551 "EHLO mail-ua1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725944AbfHMTVj (ORCPT ); Tue, 13 Aug 2019 15:21:39 -0400 Received: by mail-ua1-f73.google.com with SMTP id h45so161133uae.9 for ; Tue, 13 Aug 2019 12:21:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=bm7tpjWVOUDYZx97BncdSkZ9NvRhZO8YSsPPBr5vkok=; b=slazxnn157c/8d5NLixGKQHNLN7VTx1GaxxgepSJpk+EhBUjfJoNCOjXNoBlzwtTgz ATQMg1/p6wmxCiwn3NqDaSdbn0sOCgj18C/YAUSAxFH1lVQCg5+UIR6idPpfaL02EAZH IIEIw4YVgw2HCssS06onnz1SgWi3wxL7U0JMJr/iDDouwY06MoWIPdhHHDmKOO16YIkx j5G4kkndQqP76ENddQHpPGQGcFOITR7tjSD3KkUsaWPXuqX9KcbxTR2w0/9BFBqYyGaY 8WoBEUCB9UM2pRs0iCKC8r+peYhTnubEAyqgJUXHJQvwP1KZzcqzE6ODHz9/GnNc2FLx LSWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=bm7tpjWVOUDYZx97BncdSkZ9NvRhZO8YSsPPBr5vkok=; b=pcCw6Km8RbPvRa5BMoEsSTdsKnBi4vNO30MWb/mO2CYaS3TSAn1wMzAvYniWbBeVah AKCHTfiQrH5R6cE65g/XUCNl+9XuMNRDI/Q2UZvSMzkpMtnNCIMFyoxSwCnyHYnkr8mV HZl8JNqnLQtQ4qhNw3OPEeKIrN3WLiHhjSPeUv5SUtd5gEw4Y5ZdvQ9N75r5hGBFP3tE TV1eXG/Y4M/y9Bs6DYwNauyn/cV5FGK+svHVefwAKDXJ6rKlrcDYUyBaAfbYsX9BnpXC P2vtH5pl2JJ68qxfff0zyx7hSGZq7M9p/PRMj9FMmpqchiYHQFzH18IJSWZgliUj4/Ri qzTA== X-Gm-Message-State: APjAAAWJg/nyeOHJn8q5HR78UIrZSjXgEZ8yeZK4O45e1UnJBv3NKzDB nn4VLQWYD/k8hyFI/0muu2mPpsaktmIcI5efTtES4w== X-Google-Smtp-Source: APXvYqzRVkooHVUD52Jj7apoZc5mIoEhdYnVm95g08oervUdSjOgObCJlOhYCdmCQD7I3YQEPRfXBlAg4kq7Nznq8SGZ4Q== X-Received: by 2002:a1f:ec41:: with SMTP id k62mr7315266vkh.32.1565724098096; Tue, 13 Aug 2019 12:21:38 -0700 (PDT) Date: Tue, 13 Aug 2019 12:21:23 -0700 In-Reply-To: <20190813192126.122370-1-matthewgarrett@google.com> Message-Id: <20190813192126.122370-4-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190813192126.122370-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.23.0.rc1.153.gdeed80330f-goog Subject: [PATCH 3/6] Avoid build warning when !CONFIG_KEXEC_SIG From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, Matthew Garrett , Matthew Garrett , Jiri Bohac , Dave Young , kexec@lists.infradead.org Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP Refactor the signature validation and lockdown integration a little in order to avoid an unused variable. Signed-off-by: Matthew Garrett Cc: Jiri Bohac Cc: Dave Young Cc: kexec@lists.infradead.org --- kernel/kexec_file.c | 72 ++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index be0c13076056..e878587715b9 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -177,36 +177,13 @@ void kimage_file_post_load_cleanup(struct kimage *image) image->image_loader_data = NULL; } -/* - * In file mode list of segments is prepared by kernel. Copy relevant - * data from user space, do error checking, prepare segment list - */ +#ifdef CONFIG_KEXEC_SIG static int -kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, - const char __user *cmdline_ptr, - unsigned long cmdline_len, unsigned flags) +kimage_validate_signature(struct kimage *image) { const char *reason; int ret; - void *ldata; - loff_t size; - - ret = kernel_read_file_from_fd(kernel_fd, &image->kernel_buf, - &size, INT_MAX, READING_KEXEC_IMAGE); - if (ret) - return ret; - image->kernel_buf_len = size; - - /* IMA needs to pass the measurement list to the next kernel. */ - ima_add_kexec_buffer(image); - /* Call arch image probe handlers */ - ret = arch_kexec_kernel_image_probe(image, image->kernel_buf, - image->kernel_buf_len); - if (ret) - goto out; - -#ifdef CONFIG_KEXEC_SIG ret = arch_kexec_kernel_verify_sig(image, image->kernel_buf, image->kernel_buf_len); switch (ret) { @@ -228,7 +205,7 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, decide: if (IS_ENABLED(CONFIG_KEXEC_SIG_FORCE)) { pr_notice("%s rejected\n", reason); - goto out; + break; } ret = 0; @@ -251,9 +228,44 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, */ default: pr_notice("kernel signature verification failed (%d).\n", ret); - goto out; + break; } + + return ret; +} +#endif + +/* + * In file mode list of segments is prepared by kernel. Copy relevant + * data from user space, do error checking, prepare segment list + */ +static int +kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, + const char __user *cmdline_ptr, + unsigned long cmdline_len, unsigned flags) +{ + int ret; + void *ldata; + loff_t size; + + ret = kernel_read_file_from_fd(kernel_fd, &image->kernel_buf, + &size, INT_MAX, READING_KEXEC_IMAGE); + if (ret) + return ret; + image->kernel_buf_len = size; + + /* Call arch image probe handlers */ + ret = arch_kexec_kernel_image_probe(image, image->kernel_buf, + image->kernel_buf_len); + if (ret) + goto out; + +#ifdef CONFIG_KEXEC_SIG + ret = kimage_validate_signature(image); + if (ret) + goto out; #endif + /* It is possible that there no initramfs is being loaded */ if (!(flags & KEXEC_FILE_NO_INITRAMFS)) { ret = kernel_read_file_from_fd(initrd_fd, &image->initrd_buf, @@ -279,8 +291,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, ret = -EINVAL; goto out; } + + ima_kexec_cmdline(image->cmdline_buf, + image->cmdline_buf_len - 1); } + /* IMA needs to pass the measurement list to the next kernel. */ + ima_add_kexec_buffer(image); + /* Call arch image load handlers */ ldata = arch_kexec_kernel_image_load(image);