Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp570304ybg; Tue, 28 Jul 2020 13:04:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4DdcyOSt9OJ8k9kY+Cj3KXRwKdiNpxJ3voGGZlH/aklQWm9EzxKjoPuiqQdSc00nxzWKJ X-Received: by 2002:a05:6402:1a54:: with SMTP id bf20mr15806994edb.217.1595966694096; Tue, 28 Jul 2020 13:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595966694; cv=none; d=google.com; s=arc-20160816; b=XLVeLr5rgNdKxbJclWYQyPjeW7Ws92c1nIrdosoMp2NnRmbQrhHf3ZUkA+mbD21eud J/TgFZ8xjsUzcU2+NWIfsXxPVd4YVIcsiJNqdfPx97KDwetnLqsvpsNMK9x8F9Nw0oc6 jqYn7PXCPDw2Y0Y8x6MvvUPvIOq7Dwe02xZE/3WOgI0f+QFPtKoM123Xwd0AKmRwr2vD QRhr/Gh9MQuZs/VBzqa0J2QQUq3FkYjT9BAl5PnbDceRZY0cCoCveGEF/PBLYsRPmU+P MVLPMP7k+OCgkt4rlzZyTLBoFpiryI6ZndIm3YziBgsUu1tMyl5WxZT0ANn2FBxOTLW9 XN+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=NjjWAW6FgXIfls/hqkrF/yquAYJxvalgxXMqC5yfkB8=; b=beLtzifgap4f/FJ+Q6IK9FbM7Y1oXt1Uj62oudQUuK7FLva0jwzTXs5XJimmf+c1Yq SU/dtgWGqcQubdBhiBg3NvU/kcMi5tQfWQF+T9saMMdLXUuJ76qBsSY7OMZ3ZSZ7V0bi 4zmEPySdpsv54ZKXHS883HrA73StwF0KL1Vu1AM64kWMVV4eWgVhRqYcnkLh+AOcMi7k MhsD0AhdKpEwXQBeJXEbs5tFyRtgABPZb8ROsj8zemcj5P2/3cUgAG9Rs71w0Bzc4Tf0 gD2ZDINnq4itR1NM7c2PTbP2YOJ03FdsYGirB/YppMM//lLpUwogCwcJ3aJZ2KQsB8j6 UBzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=KIalYCFn; 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=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r8si8305797edq.393.2020.07.28.13.04.32; Tue, 28 Jul 2020 13:04:54 -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=@chromium.org header.s=google header.b=KIalYCFn; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733006AbgG1TpE (ORCPT + 99 others); Tue, 28 Jul 2020 15:45:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732976AbgG1Tox (ORCPT ); Tue, 28 Jul 2020 15:44:53 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE8E8C0619D6 for ; Tue, 28 Jul 2020 12:44:52 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id k13so2692977plk.13 for ; Tue, 28 Jul 2020 12:44:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=NjjWAW6FgXIfls/hqkrF/yquAYJxvalgxXMqC5yfkB8=; b=KIalYCFnh0ooJeOFJkJKg6Aj3ezi1dT2pKr43ERudEvFuNaAJ3+4031cCKI/mpqsHN jPODHusawyatNlhEIpveO4bRm2Qv8DouYUrTDu4x7sAqumvD4p0DaIwI9w47ua+Y+Lm8 r5WIEN2ftI2xGaXzPY44IJT2WhYYdppfLz2ds= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=NjjWAW6FgXIfls/hqkrF/yquAYJxvalgxXMqC5yfkB8=; b=o6RMfk4htq/SzxChCkLZPWy8vWB/7EikacOZyqyXgeNF3QjroyzKpC54VoIULM7NcF ClyBHm9S+RcZ/beXcF6hI7YtFVejNG9CYOhsnIc7xq/3KyYz8sQ78e2jeQyyp/a6kTP3 dVkdjiBpoDvBcpxsk5SngVXXpoq0fjFmRewFaZr7m1hbvrdgxXB1gpUvuyMvvK7PfeeZ fffUlP0YyayVaUrIlObYdzTJqWed84bTy1jEkXTpXy0o9JSVuhcJ5yK71GFYSH2GfdzH nMSafgEQ2fhGlzG7s4vwURLJ1Rxymns87TUu6FHsNubch63r4UgvtWfmLwTb1vzfLQr1 6ISw== X-Gm-Message-State: AOAM532cyatWaoftPrq2qce8qqpAdFDPWs4V9mfJKgUHoG0qudh778Rp 4a6ptCfuu7YW+xySfIKRADUpjw== X-Received: by 2002:a17:902:7446:: with SMTP id e6mr7253416plt.267.1595965492443; Tue, 28 Jul 2020 12:44:52 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id m31sm4012561pjb.52.2020.07.28.12.44.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 Jul 2020 12:44:51 -0700 (PDT) Date: Tue, 28 Jul 2020 12:44:50 -0700 From: Kees Cook To: Mimi Zohar Cc: Greg Kroah-Hartman , 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 Subject: Re: [PATCH v3 15/19] IMA: Add support for file reads without contents Message-ID: <202007281244.2F2681AE9@keescook> References: <20200724213640.389191-1-keescook@chromium.org> <20200724213640.389191-16-keescook@chromium.org> <1595856214.4841.86.camel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1595856214.4841.86.camel@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 27, 2020 at 09:23:34AM -0400, Mimi Zohar wrote: > 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 Sure! Greg, shall I send a v4 with added Reviews and the comment change or is that minor enough that you're able to do it? Thanks for the reviews Mimi! -Kees > > > --- > > 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] = { > -- Kees Cook