Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2499384ybh; Fri, 24 Jul 2020 14:39:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSGd18PkfioWZKcJ4GwYfIVTWdpgvU9DECVF3G9qJZug3pTK5PfnNS1LcGcC/f1Id4CMez X-Received: by 2002:a05:6402:1c0f:: with SMTP id ck15mr10440907edb.155.1595626791486; Fri, 24 Jul 2020 14:39:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595626791; cv=none; d=google.com; s=arc-20160816; b=Uo4kS4Hq3ZcqyTqVtWluNubWlz4i1k7KALcEDtc5btQ696MvYsGVsDEWZ60Sp1tdb4 5BtfOjR9Hfw3bUF4xD79wKSV9AmkMk+KYUFrgcnPa76avvRLajX6e9l/u+7OIIimQxRU 4WNnvzi6eLwIAjnK47VLN1knMujvqmw2tyNjuuSy+5s+LzSaPSXJtTfOv4ier0JSW/xy IS7sp010nL8ElGdSbqJKIMnMIN2hQdPnH2GWjuIzGoFkEoiRYej5iKeXtHbHsQZznBiK ke9ZJJwecX4jzZRYWHY2ybkeO3FBMdkNW8Lg2OeQ1W9L6yzJo96FY++e/g2UGqyRbDmy Hqhg== 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:message-id:date:subject:cc:to:from :dkim-signature; bh=Qku51F3DrWa6qngs3brRCvs/T/eVZDmg+FQ8m7DJ84Y=; b=ZIZb9xEfgaQ1jqReEvC+gY7cM5nljfTsYFAkTd4xYgQvfh/zYX1zznMp3FUP80gXWa iLQPp6LU1Pk7JOIv5xgLPuKbkNmPSl+WO9jAQIc65SmvRp5KY78G4hhG8XwwdbiT1f8V tDNkYmVaBhHtdtpI6F5a90OiXKMQk3tJDHwautC3A+fDuRNtGCoYACW3sY+SU//y3oU9 rDmGChddsGkVG9MVOCUuFcYyaQfbYjnp356U4yJPtVnI6M0QmBpLlWHgPQ53qdfo0Fuw OqerlwSONiGHwy0KYHZyM/Qg6CErLTMpZ2qO50Z2PcalqY/nXu8WoBwfnyBsc38eeu2V bYbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ErJl9x76; 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 re20si1259855ejb.31.2020.07.24.14.39.27; Fri, 24 Jul 2020 14:39:51 -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=ErJl9x76; 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 S1727125AbgGXVhD (ORCPT + 99 others); Fri, 24 Jul 2020 17:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727112AbgGXVg5 (ORCPT ); Fri, 24 Jul 2020 17:36:57 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C31AC08C5F4 for ; Fri, 24 Jul 2020 14:36:56 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id cv18so6395892pjb.1 for ; Fri, 24 Jul 2020 14:36:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Qku51F3DrWa6qngs3brRCvs/T/eVZDmg+FQ8m7DJ84Y=; b=ErJl9x76PRS3MiK8WeCfMVbTqv2T1HWSOaBV6g16182sJx2KTiDvaZ66SBx1g+ohPj IRVh3Mqg9H7OczMYYITojtZNthP78brV4cxTHi/IYEYpcwzAJMjxxGbCMFk1r7YXuMpN ilJTX5tTBecVZbZ/0f7uMr2IwzT4Xw/bqZfaM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Qku51F3DrWa6qngs3brRCvs/T/eVZDmg+FQ8m7DJ84Y=; b=B1QNj6aOzL6srBxTsA4FmuMWxUS0BOUWB0CQyN9eh2CbF4gaisXnGySYKGDVMDc1GY oqjDQhjvzS9BKzzlhZFaBN8c2dd7emY8kiu7kntb/Dj6YqmaUAWezaZx77rr68+Rc58U rSwmYrztNjo+gxgxk4X3zWZalf8pYYLE0WuEmwUJtalBeDhUFRfWnru8MjWcDJrJmcvK Wa57CJOap3owu5Mgc6NlP6pS1DCX5sztcXzgvnKmofJarw2dR0X0rtPWneQAOjUST23t 02LgG4cXCNXusYSmXj2Sx4HdzuRdECVfG1eSYmzPAoMo+Jf69bIeVXsgjSYCM9/CHqe/ bI8A== X-Gm-Message-State: AOAM53105XApqmqOfQOa0kmN2smkZlJXlEnFSHPUQJIywSLq9PAOfRui 8i6vU2yU9Kbn6FxbtIkDINreLw== X-Received: by 2002:a17:902:8a85:: with SMTP id p5mr9869112plo.89.1595626615673; Fri, 24 Jul 2020 14:36:55 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f2sm7244500pfb.184.2020.07.24.14.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 14:36:53 -0700 (PDT) From: Kees Cook To: Greg Kroah-Hartman Cc: Kees Cook , Scott Branden , Mimi Zohar , 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: [PATCH v3 15/19] IMA: Add support for file reads without contents Date: Fri, 24 Jul 2020 14:36:36 -0700 Message-Id: <20200724213640.389191-16-keescook@chromium.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200724213640.389191-1-keescook@chromium.org> References: <20200724213640.389191-1-keescook@chromium.org> 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 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 --- 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. */ + 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] = { -- 2.25.1