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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88882C48BE4 for ; Mon, 24 Jun 2019 01:52:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 68FB52054F for ; Mon, 24 Jun 2019 01:52:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726797AbfFXBw2 (ORCPT ); Sun, 23 Jun 2019 21:52:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3888 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726795AbfFXBw2 (ORCPT ); Sun, 23 Jun 2019 21:52:28 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CB2E6C04959F; Mon, 24 Jun 2019 01:52:23 +0000 (UTC) Received: from dhcp-128-65.nay.redhat.com (ovpn-12-23.pek2.redhat.com [10.72.12.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3A55310018F9; Mon, 24 Jun 2019 01:52:14 +0000 (UTC) Date: Mon, 24 Jun 2019 09:52:06 +0800 From: Dave Young To: Matthew Garrett Cc: James Morris , Jiri Bohac , Linux API , kexec@lists.infradead.org, Linux Kernel Mailing List , David Howells , LSM List , Andy Lutomirski Subject: Re: [PATCH V31 07/25] kexec_file: Restrict at runtime if the kernel is locked down Message-ID: <20190624015206.GB2976@dhcp-128-65.nay.redhat.com> References: <20190326182742.16950-1-matthewgarrett@google.com> <20190326182742.16950-8-matthewgarrett@google.com> <20190621064340.GB4528@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Mon, 24 Jun 2019 01:52:28 +0000 (UTC) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: On 06/21/19 at 01:18pm, Matthew Garrett wrote: > On Thu, Jun 20, 2019 at 11:43 PM Dave Young wrote: > > > > On 03/26/19 at 11:27am, Matthew Garrett wrote: > > > From: Jiri Bohac > > > > > > When KEXEC_SIG is not enabled, kernel should not load images through > > > kexec_file systemcall if the kernel is locked down. > > > > > > [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. Modified by Matthew Garrett to remove the IMA > > > integration, which will be replaced by integrating with the IMA > > > architecture policy patches.] > > > > > > Signed-off-by: Jiri Bohac > > > Signed-off-by: David Howells > > > Signed-off-by: Matthew Garrett > > > Reviewed-by: Jiri Bohac > > > cc: kexec@lists.infradead.org > > > --- > > > kernel/kexec_file.c | 6 ++++++ > > > 1 file changed, 6 insertions(+) > > > > > > diff --git a/kernel/kexec_file.c b/kernel/kexec_file.c > > > index 67f3a866eabe..a1cc37c8b43b 100644 > > > --- a/kernel/kexec_file.c > > > +++ b/kernel/kexec_file.c > > > @@ -239,6 +239,12 @@ kimage_file_prepare_segments(struct kimage *image, int kernel_fd, int initrd_fd, > > > } > > > > > > ret = 0; > > > + > > > + if (kernel_is_locked_down(reason, LOCKDOWN_INTEGRITY)) { > > > + ret = -EPERM; > > > + goto out; > > > + } > > > + > > > > Checking here is late, it would be good to move the check to earlier > > code around below code: > > /* We only trust the superuser with rebooting the system. */ > > if (!capable(CAP_SYS_BOOT) || kexec_load_disabled) > > return -EPERM; > > I don't think so - we want it to be possible to load images if they > have a valid signature. I know it works like this way because of the previous patch. But from the patch log "When KEXEC_SIG is not enabled, kernel should not load images", it is simple to check it early for !IS_ENABLED(CONFIG_KEXEC_SIG) && kernel_is_locked_down(reason, LOCKDOWN_INTEGRITY) instead of depending on the late code to verify signature. In that way, easier to understand the logic, no? Thanks Dave