Received: by 2002:a17:90b:8d0:0:0:0:0 with SMTP id ds16csp4851125pjb; Mon, 27 Jul 2020 06:49:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHyaiFylvIsbpoVmU8ZbfKyI3XhO5u9JTWWVedjOA1dxfh81eFK8aH4NJ7ZYZ020WbX8MF X-Received: by 2002:aa7:cf1a:: with SMTP id a26mr18693507edy.51.1595857781841; Mon, 27 Jul 2020 06:49:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595857781; cv=none; d=google.com; s=arc-20160816; b=L4zI8mft9x5HFeXMnwi//jD1BHI1oBVfklG3Gf9hRcIVbm2MQJBO83217Hn8UAhxZ0 xrDkJ0Bwagln+t6AHnqFbfCnRZUfmGJjMVlkk4hXpO0oi/K+EqWRHrHs67iXGoTMW/IT lgfCHFGGnWDWK3VE8EO0cNGWzaGsdqH4Sje6QZ790xIMUrADyYRNTr5pnDi2P8z9Hh6y HGwxQmOmuhKI27B91HqtQ8cdibxdC/2HVG1ykGirtwrufaKOxJSByIfIm7V8ArM7KMfg H94rLM2ihBihrYfG7hxBTz1LYKbUYK4Ajtkq+m+VkUwngEdTgXP3NxTpmUAuFjvp+1x2 LC7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :dkim-signature; bh=AauVjN3PJW1YMnnQ9wp/goSPac/16OzlZyf9oQ5QASo=; b=SiS50S/pKuAddNrMz33ewxvRmkY3zA+8K6+8AR8PLgDzq+4bReUdJ5Ut9LE6NbF589 I3LuDDOEwUI32Y0p6CTUc90sTjGzIWPJSSRjOMsUeZTEAhAaB+AmQ9cDNGls3uwBEAMs bVZVk76h1LnruSWWAf6/oyEGSXbu4wnxbmlaULNNff9xCIS8PHLMHnqqh7Os9QfWAqMG nZudKBkkObEBWFAphdkfiYgNvRtSNp1ELtbvyLyaO5IedHKpiCaqI9r3BeY33vrU6Ae4 IQjkWpfb8Q2UKbKIEtZCKGD7z2m6ADQ/8feclnkTaOpDXZyONkbncUM/JiT/JuNRNALt xzeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vA3nhi2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e19si5364597edv.165.2020.07.27.06.49.19; Mon, 27 Jul 2020 06:49:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=vA3nhi2B; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728753AbgG0NXh (ORCPT + 99 others); Mon, 27 Jul 2020 09:23:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:60758 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726139AbgG0NXh (ORCPT ); Mon, 27 Jul 2020 09:23:37 -0400 Received: from localhost.localdomain (pool-96-246-152-186.nycmny.fios.verizon.net [96.246.152.186]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 206C62070A; Mon, 27 Jul 2020 13:23:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595856216; bh=p0/aR+7F/EhpgGtHoA2xxlJN+6ONhfFeG/VGIi12Y5k=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=vA3nhi2BjSC/lOBa5bRxZN6N7q6pt4FXD1yAUpm1nJWeVNeZVPZTszWkmyi4VUDMq kFOEenShmFSmH0HzDtGB8TrJ11XnsZxDCqiN1pnXo7w0Ww0XWPLeUNf0UEiZXwI+sL qTB0u37h/x/7Uh4mqPeVQNojXpxoXTNoCUSKv/KI= Message-ID: <1595856214.4841.86.camel@kernel.org> Subject: Re: [PATCH v3 15/19] IMA: Add support for file reads without contents From: Mimi Zohar To: Kees Cook , Greg Kroah-Hartman Cc: Scott Branden , Luis Chamberlain , Jessica Yu , SeongJae Park , KP Singh , linux-efi@vger.kernel.org, linux-security-module@vger.kernel.org, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 27 Jul 2020 09:23:34 -0400 In-Reply-To: <20200724213640.389191-16-keescook@chromium.org> References: <20200724213640.389191-1-keescook@chromium.org> <20200724213640.389191-16-keescook@chromium.org> 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: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2020-07-24 at 14:36 -0700, Kees Cook wrote: > From: Scott Branden > > When the kernel_read_file LSM hook is called with contents=false, IMA > can appraise the file directly, without requiring a filled buffer. When > such a buffer is available, though, IMA can continue to use it instead > of forcing a double read here. > > Signed-off-by: Scott Branden > Link: https://lore.kernel.org/lkml/20200706232309.12010-10-scott.branden@broadcom.com/ > Signed-off-by: Kees Cook After adjusting the comment below. Reviewed-by: Mimi Zohar > --- > security/integrity/ima/ima_main.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c > index dc4f90660aa6..459e50526a12 100644 > --- a/security/integrity/ima/ima_main.c > +++ b/security/integrity/ima/ima_main.c > @@ -613,11 +613,8 @@ void ima_post_path_mknod(struct dentry *dentry) > int ima_read_file(struct file *file, enum kernel_read_file_id read_id, > bool contents) > { > - /* Reject all partial reads during appraisal. */ > - if (!contents) { > - if (ima_appraise & IMA_APPRAISE_ENFORCE) > - return -EACCES; > - } > + enum ima_hooks func; > + u32 secid; > > /* > * Do devices using pre-allocated memory run the risk of the > @@ -626,7 +623,20 @@ int ima_read_file(struct file *file, enum kernel_read_file_id read_id, > * buffers? It may be desirable to include the buffer address > * in this API and walk all the dma_map_single() mappings to check. > */ > - return 0; > + > + /* > + * There will be a call made to ima_post_read_file() with > + * a filled buffer, so we don't need to perform an extra > + * read early here. > + */ > + if (contents) > + return 0; > + > + /* Read entire file for all partial reads during appraisal. */ In addition to verifying the file signature, the file might be included in the IMA measurement list or the file hash may be used to augment the audit record.  Please remove "during appraisal" from the comment. > + func = read_idmap[read_id] ?: FILE_CHECK; > + security_task_getsecid(current, &secid); > + return process_measurement(file, current_cred(), secid, NULL, > + 0, MAY_READ, func); > } > > const int read_idmap[READING_MAX_ID] = {