Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp49495ybg; Tue, 9 Jun 2020 16:03:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyoKEBwMdYMekuCYwyBYKO1LusOQMgt5Z8D46xoaO9XCaCPoNrq8E3AjP/fiUCAlegNBcCK X-Received: by 2002:a05:6402:144f:: with SMTP id d15mr72806edx.114.1591743808611; Tue, 09 Jun 2020 16:03:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591743808; cv=none; d=google.com; s=arc-20160816; b=uOVaN/R50vDSfIy4+Q6JN5w8QbeVDXXq6zPtfwrA58Sn4lU1wrF+9mIlZ09SD3CSHd NCdiFBM76Im4oS8SnqhiPD3Rm/2vp/XV89hQbmkl9FhuXqKAIljhEYPkiaph1pukZiZo +r6UU8OmlpVr6Pq7mi/OvnQy+s4ZRRL58RvqfKLNI0DOPpVdXMfle6ZKQjuYxktQyvlH mj4kSvYFxEa39+XOdbY5V1QAu3y9yNWFLvVeYBKB0JwXLWVG60cWZjxfzmflPlbcqUWw W436QV3MrOWjayGgnw0DKHoxFWDLAxLdbB13R57PDDYR4IpxzMpspTZuYosZcPW1JAdG 8/xQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=cM+rCpZobNDrkDN9s+cJ/Q1XgGFeWXzm3UzYtFYpyy4=; b=D0WPIWbgiscGKWZ454OtkkDeR5w+NpDbwoBST4bTLfORuFKabRN/1yEOYalWP1GA2x CpB5PJlqkQXzJtxn/KEb/tRoviEsIsc5OrasW0XpJgw2K5GgOYjfW2pmZ7Fblj59EvNw agmHc3chAayec2j69/ZXguSxDQQmK21Q08X5+kZXEma5lbbcrwZZfG6QrHKKvIr1dsGS 4nelb8i1+2zWKlIvdmPaZ2XvZ4CyqwTZeU7/RYUQJH6cxB2EX4CRXdYTKKFcpDEjGGCz 0fASX2LD0ipAxxkERnjngOzIsaPhx9p7bRqV6ud2WFZedvlCz+H5hOw4ot1GbdnDzeo2 PpQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=ByJPGZ0f; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h19si11772420ejd.365.2020.06.09.16.02.15; Tue, 09 Jun 2020 16:03:28 -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=@broadcom.com header.s=google header.b=ByJPGZ0f; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbgFIW6i (ORCPT + 99 others); Tue, 9 Jun 2020 18:58:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60734 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729014AbgFIW5l (ORCPT ); Tue, 9 Jun 2020 18:57:41 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3181FC08C5C4 for ; Tue, 9 Jun 2020 15:57:36 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id 10so214209pfx.8 for ; Tue, 09 Jun 2020 15:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=cM+rCpZobNDrkDN9s+cJ/Q1XgGFeWXzm3UzYtFYpyy4=; b=ByJPGZ0fwC+pHYx4+jr86EPnUJT03kDN80FFAKD7I5rX+wsF2f7csCPEgbu0Vv5JXD ZyLWQTOAA/02+ZV08uuMrd6LxZHpZq8t+zpNoZQcJEL4vViRm5Z4Qrylf4XzyxMH9i+e 6RPwx+6tj/r3KDMiIgbqsv1cvcx5htVk6ttBo= 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; bh=cM+rCpZobNDrkDN9s+cJ/Q1XgGFeWXzm3UzYtFYpyy4=; b=HonB/4o38+9BdOtX3iOOYejUweGcjeoXitQDuL/MjNzLpQRic4cUc6hhjP6YLUa7Yn sLRvuZ87+zwEv8ZeVb4uKfdhceFgI53SHruLH+XrRRMuZf1ZeneW5sDf33lsIi5GRjkF Ohuft5RU3pl+BbqDBsP22QwhzYBAoND1zJ/Dwbupb1uqeO2NK4teJrIBjAZ32ZYmGpwh +hwydtLDoqrSWzKNI6klk+X3DMcYNt3oDqnBVpgtc8NI8RSZtk6H31F8abGH8uj741Bp m+LvUCS/sSKYSZrKQg6T4NLkYvGv1ZngO/ZqoVaL/dHqUV2D3H8LTZbRyzQqCB8w/YoC /yHQ== X-Gm-Message-State: AOAM530eAqbBO8cNg6ylHVjo4Dhg8wCldjbJyrUdeArc9LTsojAGKYzG VB/wy7KxEsnvflX1ERANxBv1dA== X-Received: by 2002:a63:145f:: with SMTP id 31mr212923pgu.383.1591743455670; Tue, 09 Jun 2020 15:57:35 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id p8sm9104978pgs.29.2020.06.09.15.57.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2020 15:57:34 -0700 (PDT) From: Scott Branden To: Luis Chamberlain , Wolfram Sang , Greg Kroah-Hartman , David Brown , Alexander Viro , Shuah Khan , bjorn.andersson@linaro.org, Shuah Khan , Arnd Bergmann Cc: Mimi Zohar , "Rafael J . Wysocki" , linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-fsdevel@vger.kernel.org, BCM Kernel Feedback , Olof Johansson , Andrew Morton , Dan Carpenter , Colin Ian King , Kees Cook , Takashi Iwai , linux-kselftest@vger.kernel.org, Andy Gross , linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, Scott Branden Subject: [PATCH v8 8/8] ima: add FIRMWARE_PARTIAL_READ support Date: Tue, 9 Jun 2020 15:56:56 -0700 Message-Id: <20200609225656.18663-9-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200609225656.18663-1-scott.branden@broadcom.com> References: <20200609225656.18663-1-scott.branden@broadcom.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add FIRMWARE_PARTIAL_READ support for integrity measurement on partial reads of firmware files. Signed-off-by: Scott Branden --- security/integrity/ima/ima_main.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c index 800fb3bba418..fc5134807acf 100644 --- a/security/integrity/ima/ima_main.c +++ b/security/integrity/ima/ima_main.c @@ -609,6 +609,9 @@ void ima_post_path_mknod(struct dentry *dentry) */ int ima_read_file(struct file *file, enum kernel_read_file_id read_id) { + enum ima_hooks func; + u32 secid; + /* * READING_FIRMWARE_PREALLOC_BUFFER * @@ -617,11 +620,27 @@ int ima_read_file(struct file *file, enum kernel_read_file_id read_id) * of IMA's signature verification any more than when using two * buffers? */ - return 0; + if (read_id != READING_FIRMWARE_PARTIAL_READ) + return 0; + + if (!file) { + if ((ima_appraise & IMA_APPRAISE_FIRMWARE) && + (ima_appraise & IMA_APPRAISE_ENFORCE)) { + pr_err("Prevent firmware loading_store.\n"); + return -EACCES; /* INTEGRITY_UNKNOWN */ + } + return 0; + } + + 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] = { [READING_FIRMWARE] = FIRMWARE_CHECK, + [READING_FIRMWARE_PARTIAL_READ] = FIRMWARE_CHECK, [READING_FIRMWARE_PREALLOC_BUFFER] = FIRMWARE_CHECK, [READING_MODULE] = MODULE_CHECK, [READING_KEXEC_IMAGE] = KEXEC_KERNEL_CHECK, @@ -648,6 +667,9 @@ int ima_post_read_file(struct file *file, void *buf, loff_t size, enum ima_hooks func; u32 secid; + if (read_id == READING_FIRMWARE_PARTIAL_READ) + return 0; + if (!file && read_id == READING_FIRMWARE) { if ((ima_appraise & IMA_APPRAISE_FIRMWARE) && (ima_appraise & IMA_APPRAISE_ENFORCE)) { -- 2.17.1