Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp1871935ybd; Sun, 23 Jun 2019 18:52:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwags+X7r8x+Ye/Dml6dJEeYh59BgKFiLqBiSxpwwaAyLC2D6SLzgcjvRQgfC2Zq3FQIZEQ X-Received: by 2002:a63:b90d:: with SMTP id z13mr29915973pge.16.1561341172893; Sun, 23 Jun 2019 18:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561341172; cv=none; d=google.com; s=arc-20160816; b=BdrN2KOKtFLxG+Pyfy8jgeqNWcYD1SDG/MB9x++PlXq9LsTyP0dJX/vaWZI7FZSnyK lDvk2dWMRRQj73sv+EH+6tUF4Tb4tw6dNZTJpiBVHvMH8lvHSGOH9DwA9MBh+Jfv8nz/ ntWRwsMAoz+b+/ChQlrPX/3UVSjrdEkwaRudB0ghx3Ym5GLtdDoLB/alDXr+A+rdOkD1 YbzvwuBn54vbRWYCeFqyPiXtKgn2d8OSgNKMcYDWuXiBGlvAQNQmdSh+rMNHIts70H6b EJBJWCmZ8xxFaQ7e0cB193GU3F+sRP5Wc234smMiI5hTozJInrS940zxq3MU9W/NoOO7 84Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=nTgyS+9PfENiZ7kBhdC6dAljVg1caM16ebIjMvi6Y2E=; b=NgHNTCTXwluZqRE3ioLzaCF4GSfqOaNfQB9kbk2EQ1JhmpSaYJ/doCFoCinTzqE6xr kKbVW7gh7QcR+uhzAH7i9iQ3mLYKY5S/rq2Q12VHybc4v7Swv9nw0kd/9kuO3Vj5pABG 5lsdR+suWDLdEqm7ONyARamK6OCCorW+1TgWfPfOO6UrbK/HhrjTMJffspBVUKMB35bM 1RcUqHFxl7ye+eUet8CvRMKzTS9eVldC410u5E/Pnrv/vJqPO7ScjWGyeExLWRu639J1 AiMQ3fW4+EjFcEk4T6Mo8cGI0izorG6aC8Ew21PQpOYWslo117L6RqkcglfpmvQKGFWb whGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i17si9723531pju.96.2019.06.23.18.52.37; Sun, 23 Jun 2019 18:52:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbfFXBw3 (ORCPT + 99 others); Sun, 23 Jun 2019 21:52:29 -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: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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