Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4374453pxu; Wed, 9 Dec 2020 15:50:03 -0800 (PST) X-Google-Smtp-Source: ABdhPJyhTIEGV1lOj+fDNk0nX0EWzeCgFMdisqbvPGmn/0miclbOP+htvfO4abcIZzG96vq9pBHw X-Received: by 2002:a17:906:cc9c:: with SMTP id oq28mr4123263ejb.224.1607557803582; Wed, 09 Dec 2020 15:50:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607557803; cv=none; d=google.com; s=arc-20160816; b=YTTPtReH7PvvAN1NVngRjT4pYomvcAWH6mtjpE/UQqxcktXFB7KxtMWzuzkZv3gPan j4XzNV/krZpsN3s7TiOvfT9jdu9McRGfpBe3J7R4fxvY3jzw2az7z740VOKHANXDAKkA FoDxcLsVEwTF6H3xc7VPu9rO6k1Z3aTEvCXBhlqBzC6mbEld65DRnHBUf/PRob8clDg7 3eASm9RkjWTbDz5orx8PNROxfuVTL9636zilw8u9iZUqWI1qpZFmXRKvpMYqvz40HWYO O9GU6p/rWMXli5byKMShIArfij1XbLmtYBF0TkxXt5L+TByyrZSVlUu+To1IPFAiB9+L hw0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=13W9y/glUb8I3SzOqOuxO+1MJwZs/tFHH0a5DtYqn+g=; b=AsSZg7e83L0DmIrZ86HDuiBJWp6/8X722ZP5+KVnSE9aMawOlOpUj7tADUNqloqvg5 vJ9r2J0kFo569SxFx+oPQVR5RAPaUf/3uKKOhpIsE8YlmnqrIKmFgD7ZcaIbbwESrEyp Nb/ddozepjG4afgnUx1R+k0URFI+KdgBXaPXlciawxl0KDZpPnSo0yB9xs8omYBSxlhD ZkXOtrIpqdHQ5HGmp9JJgag3Ltl8qrNl9aaBHZ4u3k/hvvKF4TIJ3eHcjFFMBDf8LP28 LvrxL1jb3T27CMbrE9z2vfwFr8eXqtABsKo4trR/oicFrLi3UqfnrdeJY4q65cmGWAs3 AhGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=TZVpGynK; 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=linux.microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h7si1709823edf.503.2020.12.09.15.49.41; Wed, 09 Dec 2020 15:50:03 -0800 (PST) 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=@linux.microsoft.com header.s=default header.b=TZVpGynK; 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=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388107AbgLITrF (ORCPT + 99 others); Wed, 9 Dec 2020 14:47:05 -0500 Received: from linux.microsoft.com ([13.77.154.182]:47492 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387857AbgLITnG (ORCPT ); Wed, 9 Dec 2020 14:43:06 -0500 Received: from tusharsu-Ubuntu.lan (c-71-197-163-6.hsd1.wa.comcast.net [71.197.163.6]) by linux.microsoft.com (Postfix) with ESMTPSA id A6EB720B7189; Wed, 9 Dec 2020 11:42:24 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com A6EB720B7189 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1607542945; bh=13W9y/glUb8I3SzOqOuxO+1MJwZs/tFHH0a5DtYqn+g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TZVpGynKEEZSZfv4sGpjoXpRov6wDOKUZe6Bk2s0M7IyWfEjL11cvBW/RiftHz9k1 8vI8zRWmbI63YTH0/dTkHJXgwqs1bxLGX1+6La9EI/+jASChz6i/LT+0FX+9tNXTrX ACemq6NpMQLBt4kUsRNpMutGXMRsw7tTv2AaleWY= From: Tushar Sugandhi To: zohar@linux.ibm.com, stephen.smalley.work@gmail.com, casey@schaufler-ca.com, agk@redhat.com, snitzer@redhat.com, gmazyland@gmail.com, paul@paul-moore.com Cc: tyhicks@linux.microsoft.com, sashal@kernel.org, jmorris@namei.org, nramas@linux.microsoft.com, linux-integrity@vger.kernel.org, selinux@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, dm-devel@redhat.com Subject: [PATCH v7 4/8] IMA: add policy rule to measure critical data Date: Wed, 9 Dec 2020 11:42:08 -0800 Message-Id: <20201209194212.5131-5-tusharsu@linux.microsoft.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201209194212.5131-1-tusharsu@linux.microsoft.com> References: <20201209194212.5131-1-tusharsu@linux.microsoft.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org A new IMA policy rule is needed for the IMA hook ima_measure_critical_data() and the corresponding func CRITICAL_DATA for measuring the input buffer. The policy rule should ensure the buffer would get measured only when the policy rule allows the action. The policy rule should also support the necessary constraints (flags etc.) for integrity critical buffer data measurements. Add a policy rule to define the constraints for restricting integrity critical data measurements. Signed-off-by: Tushar Sugandhi --- security/integrity/ima/ima_policy.c | 35 +++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 2a0c0603626e..9a8ee80a3128 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -34,6 +34,7 @@ #define IMA_PCR 0x0100 #define IMA_FSNAME 0x0200 #define IMA_KEYRINGS 0x0400 +#define IMA_DATA_SOURCE 0x0800 #define UNKNOWN 0 #define MEASURE 0x0001 /* same as IMA_MEASURE */ @@ -85,6 +86,7 @@ struct ima_rule_entry { } lsm[MAX_LSM_RULES]; char *fsname; struct ima_rule_opt_list *keyrings; /* Measure keys added to these keyrings */ + struct ima_rule_opt_list *data_source; /* Measure data from this source */ struct ima_template_desc *template; }; @@ -479,6 +481,12 @@ static bool ima_match_rule_data(struct ima_rule_entry *rule, else opt_list = rule->keyrings; break; + case CRITICAL_DATA: + if (!rule->data_source) + return true; + else + opt_list = rule->data_source; + break; default: break; } @@ -518,13 +526,19 @@ static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode, { int i; - if (func == KEY_CHECK) { - return (rule->flags & IMA_FUNC) && (rule->func == func) && - ima_match_rule_data(rule, func_data, cred); - } if ((rule->flags & IMA_FUNC) && (rule->func != func && func != POST_SETATTR)) return false; + + switch (func) { + case KEY_CHECK: + case CRITICAL_DATA: + return ((rule->func == func) && + ima_match_rule_data(rule, func_data, cred)); + default: + break; + } + if ((rule->flags & IMA_MASK) && (rule->mask != mask && func != POST_SETATTR)) return false; @@ -1119,6 +1133,19 @@ static bool ima_validate_rule(struct ima_rule_entry *entry) if (ima_rule_contains_lsm_cond(entry)) return false; + break; + case CRITICAL_DATA: + if (entry->action & ~(MEASURE | DONT_MEASURE)) + return false; + + if (!(entry->flags & IMA_DATA_SOURCE) || + (entry->flags & ~(IMA_FUNC | IMA_UID | IMA_PCR | + IMA_DATA_SOURCE))) + return false; + + if (ima_rule_contains_lsm_cond(entry)) + return false; + break; default: return false; -- 2.17.1