Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp124745imb; Thu, 28 Feb 2019 18:14:31 -0800 (PST) X-Google-Smtp-Source: APXvYqyFA97hJA+QP0n9BIsqzIiv98Z/XcBhmCqDeR+Bmk5NWzqB1FUk1/q7ylrvkmAI7gz5zWaX X-Received: by 2002:a63:2ad4:: with SMTP id q203mr2452286pgq.43.1551406470914; Thu, 28 Feb 2019 18:14:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551406470; cv=none; d=google.com; s=arc-20160816; b=Qogngn/BaLOGNuZlR+6hDO4QBviEncTm6EM6JHQbTCMRuST+sfFsOuosv20nfGfFTE ZS7AE+ioLxx+t7mm5gKP44/EcJ9qGDlWU3F01pOhyJ8UxgllQHM28Y/Y3BJXvaflredR Ym0tlH1GJaQuteIge95m4IowCRr618bYq5tlyHjhQ4PAES+zfpc57A0UqmEdUH8QhOLC sGAX2fQqOXyHp9HfhoV1GoJkBQk4RGSqCa9vO0tf+5P9jeN67hH5vXd1QZKegMduX3SA CErMLjaa1obDibM1uPDnOZghAmvF8qLEjGhG34HtNl/1KoZDoUEG+SLxlRgqN+pD2Tw2 m7GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :mime-version:references:in-reply-to:date:cc:to:from:subject; bh=3wsweOikEdJltleAxxgXlD4OeQbVeyj2bXQgDfqY93k=; b=JJjmy51Wg9foKO9Qb9zs7UZdT/naSzrCad2r8+8WKwSHiUTsyQpokHvK2MR6lWP7nn c/xE77+i2+BxKC+6/qSP3FZ+QA6M4oc3NFe3WYKzXQCKfhuTa02FEgcmkFXzxORCZHZR EB6c1THO4T7NpzhoMry2eOqFY2BvEhawbYVI49RIljH2LbSdRmNl+GyyRoXIuQstlDOS JH3r9tfJ7H5sCvqzol1HXyPGn5Mpiz2v/aV5SOjEsEn7uBORXIFY7qDbsrVtvpVYfTDG Lp4rY5zGz3EjEPa1gpVV6p+dzJ52ZcyyIILQvBQ71YO2YvVgzcjG4UNwoI9GHwS89mZN nfuQ== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6si19035749pfg.192.2019.02.28.18.14.15; Thu, 28 Feb 2019 18:14:30 -0800 (PST) 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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728709AbfCACGN (ORCPT + 99 others); Thu, 28 Feb 2019 21:06:13 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53968 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727222AbfCACGM (ORCPT ); Thu, 28 Feb 2019 21:06:12 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x2124Sdm117702 for ; Thu, 28 Feb 2019 21:06:11 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 2qxtk4jfyh-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 28 Feb 2019 21:06:10 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 1 Mar 2019 02:06:09 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Fri, 1 Mar 2019 02:06:05 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x21264n616908422 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 1 Mar 2019 02:06:05 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E14FC4C052; Fri, 1 Mar 2019 02:06:04 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1BCAF4C040; Fri, 1 Mar 2019 02:06:04 +0000 (GMT) Received: from localhost.localdomain (unknown [9.80.108.117]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 1 Mar 2019 02:06:03 +0000 (GMT) Subject: Re: [PATCH 08/27] kexec_file: Restrict at runtime if the kernel is locked down From: Mimi Zohar To: Matthew Garrett , jmorris@namei.org Cc: linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dhowells@redhat.com Date: Thu, 28 Feb 2019 21:05:53 -0500 In-Reply-To: <20190228231203.212359-8-matthewgarrett@google.com> References: <20190228231203.212359-1-matthewgarrett@google.com> <20190228231203.212359-8-matthewgarrett@google.com> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.20.5 (3.20.5-1.fc24) Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 x-cbid: 19030102-0008-0000-0000-000002C64A58 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19030102-0009-0000-0000-000022329DF1 Message-Id: <1551405953.10911.281.camel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-03-01_02:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903010011 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jiri, Thank you for thinking about IMA. On Thu, 2019-02-28 at 15:11 -0800, 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 unless IMA can be used > to validate the image. This patch is a partial solution, but it doesn't take into account the architecture specific or custom policies. Mimi > [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