From patchwork Thu Feb 28 23:11:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Garrett X-Patchwork-Id: 10834275 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 EEBFE180E for ; Thu, 28 Feb 2019 23:14:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF2C82FC2B for ; Thu, 28 Feb 2019 23:14:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3B262FC46; Thu, 28 Feb 2019 23:14:30 +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 73A572FC2B for ; Thu, 28 Feb 2019 23:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727952AbfB1XO3 (ORCPT ); Thu, 28 Feb 2019 18:14:29 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:47903 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387660AbfB1XM0 (ORCPT ); Thu, 28 Feb 2019 18:12:26 -0500 Received: by mail-qt1-f202.google.com with SMTP id m34so20213338qtb.14 for ; Thu, 28 Feb 2019 15:12:25 -0800 (PST) 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=tidnH0SwpTHfWgiR4IAR+/7Oaon7P2ll4DVIIUwAK1A=; b=igrS5HgB6YoQ6TPI8HVmjgJSBGpxMZDjnongg0RDlIULoSoIBEWheX+KyE784QzsOc UIRZuYFKM7JHDXbOddtqKM80DdSv7MPgMll/F1ZFqrW1Pp2ZlBLUHK9RLz4by0hYv1z/ aSdRD9d1RIke2hei05b9KoVmbaSVc/qb6h6f9T3Zyd/MZt+xEdiF0o4izzAiknNAP4EM 8qHLUMmsAJQ/o6uDLspeXOcce9hPfZ+qB9KYGarrFSWP/SZcwpgOM1ZgWckg0K+oQjoL XFXPNP2bpa/FRZ6857TPx1ZtwNTVQLoiEw0KoHdBQvdKwNM0TS1tpJKGx0Pt2cN72RI2 Fnow== 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=tidnH0SwpTHfWgiR4IAR+/7Oaon7P2ll4DVIIUwAK1A=; b=Qr/Rpht+fzE1sndWG9AlYmIzfjWvKOQ4pP4tbfEpHZd9AtS6K9YntXdL7vW2I2Jn4k H4xOwHd5+cdDLlmfUW/ERbwnVC0vcS29ENwcDDCC4YpEdCcRJBYkUrsW9Sq/kxHhYKT3 zpiXPyR0Jij/PqJ6GwF2NUX7rjxwKafMN6xOnFo+uK4SRKXXFxdku/wjUQxih9U5/p9+ dl2uvWDyNSrloMNuA3ncIXAn/b1RgPnFvwmBdx7t9my2seuVEuE8GiOwuYzp40+OkyX+ BOnZyFq9S+RTrsrY2Ff6Zmtf0Orxb2Kcwzo6pkTSw//Es1lx3Y6O+G+hJlt06IMYntF7 lXvA== X-Gm-Message-State: APjAAAVdqqbsRwllp6iSxhyE61UJr0TygYLJRjBX1PfbxNWkIsYgO9a9 8EV4Zzh2SN4SJbop598T8un7it1JTQC5DN88dWRslA== X-Google-Smtp-Source: APXvYqxxh4UKFzo0o0AatfkgMLGjfdiyDrhWhba8RfpyN7BBOY9rHrdV/RINtiBM3Olzir4oUoZC+bWEwdQSMny+julvFw== X-Received: by 2002:ac8:2539:: with SMTP id 54mr1091576qtm.45.1551395544912; Thu, 28 Feb 2019 15:12:24 -0800 (PST) Date: Thu, 28 Feb 2019 15:11:44 -0800 In-Reply-To: <20190228231203.212359-1-matthewgarrett@google.com> Message-Id: <20190228231203.212359-8-matthewgarrett@google.com> Mime-Version: 1.0 References: <20190228231203.212359-1-matthewgarrett@google.com> X-Mailer: git-send-email 2.21.0.352.gf09ad66450-goog Subject: [PATCH 08/27] kexec_file: Restrict at runtime if the kernel is locked down From: Matthew Garrett To: jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Jiri Bohac When KEXEC_SIG is not enabled, kernel should not load images through kexec_file systemcall if the kernel is locked down unless IMA can be used to validate the image. [Modified by David Howells to fit with modifications to the previous patch and to return -EPERM if the kernel is locked down for consistency with other lockdowns] Signed-off-by: Jiri Bohac Signed-off-by: David Howells Reviewed-by: Jiri Bohac Cc: Matthew Garrett cc: Chun-Yi Lee cc: kexec@lists.infradead.org --- include/linux/ima.h | 6 ++++++ kernel/kexec_file.c | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/include/linux/ima.h b/include/linux/ima.h index b5e16b8c50b7..b35ed0725a05 100644 --- a/include/linux/ima.h +++ b/include/linux/ima.h @@ -127,4 +127,10 @@ static inline int ima_inode_removexattr(struct dentry *dentry, return 0; } #endif /* CONFIG_IMA_APPRAISE */ + +static inline bool is_ima_kexec_appraise_enabled(void) +{ + return IS_ENABLED(CONFIG_IMA_APPRAISE_REQUIRE_KEXEC_SIGS); +} + #endif /* _LINUX_IMA_H */ diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c index 67f3a866eabe..b4e938dff4be 100644 --- a/kernel/kexec_file.c +++ b/kernel/kexec_file.c @@ -239,6 +239,14 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, } ret = 0; + if (is_ima_kexec_appraise_enabled()) + break; + + if (kernel_is_locked_down(reason)) { + ret = -EPERM; + goto out; + } + break; /* All other errors are fatal, including nomem, unparseable