Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1832729ybt; Thu, 2 Jul 2020 15:19:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxynO8w5UNz/sMJ+JV7RDOb95chGKtY2NJ1f55Jc9e2UhfdBTSWDG9h43Q7KigiXWOOvbLt X-Received: by 2002:a17:906:c155:: with SMTP id dp21mr28239039ejc.92.1593728374505; Thu, 02 Jul 2020 15:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593728374; cv=none; d=google.com; s=arc-20160816; b=yyGmt9kKpzINki0OHJZ2EAE7+0eBXfK4fZsBim+6OOKMsNHL6QcrWtkXIM0Lu2pg+u l+CvT069ijX46rOFPa4ReTLLYp/tTPCly4gonbsDZGL0mTIRn2a3DvakVBXuzX7HOQHt N3iOCPWnKnXTAApz+bl7o1PPBzyIphtih2k35ETR8VDAFT1R2CRRHrkbSwiS0brUX6xg Ma9r84zf6+MqPt1D8UBaWF4X/WzELe2s+9DbKZXI2P91+8zx5WsrDD1FZIcUMWtKLtT8 2T/KoOaK+r7fxC9FYFKkZSupE10Ay0PZ1V5n/g7ODnmlsCUianIRsRgv2L3CqseTafWl uQbw== 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:dkim-filter; bh=oF/uy0h2kLORBOaWz4SneoVrme6PATdmsVREbyRum0g=; b=Z3YMTJkomEB4KFZEpn/vMqMCs0ALgJSufTLyr71RZtMczzJFr7Xzay2evtDwa6EuX7 tG3Qr3vkAj4Fw8a7F2Db6RLxc7AD1LOhYVTzLRoYYqymGzYNOGftxsR5NbyOhSw6ZOLE sLGbT1Epjd64bQuld5zPW6RIM9e8vWzwvpMvPWvWS1Lj78K/r+r+ItUXzswfKisQJoWO y3i+Wb5gpVIQaXFsMuxi8TgVIlvts9YqUXBRIID/ifeT2Z+tU93+6cOhSAX+YJW5NqHE U2oxi7/YHU8pWyWdJfv+yRx8fZ53g/wiSs8SxZRD+Cdrhz8oyXsYZAwcB1LqyKd7onI/ vy5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=PFMZdTTF; 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 dh2si6681464edb.55.2020.07.02.15.19.10; Thu, 02 Jul 2020 15:19:34 -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=@linux.microsoft.com header.s=default header.b=PFMZdTTF; 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 S1726356AbgGBWRA (ORCPT + 99 others); Thu, 2 Jul 2020 18:17:00 -0400 Received: from linux.microsoft.com ([13.77.154.182]:33104 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726121AbgGBWQ7 (ORCPT ); Thu, 2 Jul 2020 18:16:59 -0400 Received: from sequoia (162-237-133-238.lightspeed.rcsntx.sbcglobal.net [162.237.133.238]) by linux.microsoft.com (Postfix) with ESMTPSA id 3454E20B717A; Thu, 2 Jul 2020 15:16:58 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3454E20B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1593728218; bh=oF/uy0h2kLORBOaWz4SneoVrme6PATdmsVREbyRum0g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PFMZdTTFgv5iNVM4ImGmNBoS/pvR9L0heXpZKAZMOxhPhktoVwM67LJRd8IGKuMp+ hsVbe/ezG63jAQaTHYIibsgW44l4YWhhShkGXgLfJnP5lJ695+dZFexJkvSWwrLoXu EKLjodVxz2+a49rtE8yf+rCbSjRVinzD7f3Lub6c= Date: Thu, 2 Jul 2020 17:16:56 -0500 From: Tyler Hicks To: Mimi Zohar Cc: Dmitry Kasatkin , James Morris , "Serge E . Hallyn" , Lakshmi Ramasubramanian , Prakhar Srivastava , linux-kernel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [PATCH v2 09/11] ima: Move validation of the keyrings conditional into ima_validate_rule() Message-ID: <20200702221656.GH4694@sequoia> References: <20200626223900.253615-1-tyhicks@linux.microsoft.com> <20200626223900.253615-10-tyhicks@linux.microsoft.com> <1593558449.5057.12.camel@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1593558449.5057.12.camel@linux.ibm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-06-30 19:07:29, Mimi Zohar wrote: > On Fri, 2020-06-26 at 17:38 -0500, Tyler Hicks wrote: > > Use ima_validate_rule() to ensure that the combination of a hook > > function and the keyrings conditional is valid and that the keyrings > > conditional is not specified without an explicit KEY_CHECK func > > conditional. This is a code cleanup and has no user-facing change. > > > > Signed-off-by: Tyler Hicks > > --- > > > > * v2 > > - Allowed IMA_DIGSIG_REQUIRED, IMA_PERMIT_DIRECTIO, > > IMA_MODSIG_ALLOWED, and IMA_CHECK_BLACKLIST conditionals to be > > present in the rule entry flags for non-buffer hook functions. > > > > security/integrity/ima/ima_policy.c | 13 +++++++++++-- > > 1 file changed, 11 insertions(+), 2 deletions(-) > > > > diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c > > index 8cdca2399d59..43d49ad958fb 100644 > > --- a/security/integrity/ima/ima_policy.c > > +++ b/security/integrity/ima/ima_policy.c > > @@ -1000,6 +1000,15 @@ static bool ima_validate_rule(struct ima_rule_entry *entry) > > case KEXEC_KERNEL_CHECK: > > case KEXEC_INITRAMFS_CHECK: > > case POLICY_CHECK: > > + if (entry->flags & ~(IMA_FUNC | IMA_MASK | IMA_FSMAGIC | > > + IMA_UID | IMA_FOWNER | IMA_FSUUID | > > + IMA_INMASK | IMA_EUID | IMA_PCR | > > + IMA_FSNAME | IMA_DIGSIG_REQUIRED | > > + IMA_PERMIT_DIRECTIO | > > + IMA_MODSIG_ALLOWED | > > + IMA_CHECK_BLACKLIST)) > > Other than KEYRINGS, this patch should continue to behave the same. > ?However, this list gives the impressions that all of these flags are > permitted on all of the above flags, which isn't true. > > For example, both IMA_MODSIG_ALLOWED & IMA_CHECK_BLACKLIST are limited > to appended signatures, meaning KERNEL_CHECK and KEXEC_KERNEL_CHECK. Just to clarify, are both IMA_MODSIG_ALLOWED and IMA_CHECK_BLACKLIST limited to KEXEC_KERNEL_CHECK, KEXEC_INITRAMFS_CHECK, and MODULE_CHECK? That's what ima_hook_supports_modsig() suggests. > ?Both should only be allowed on APPRAISE action rules. For completeness, it looks like DONT_APPRAISE should not be allowed. > IMA_PCR should be limited to MEASURE action rules. It looks like DONT_MEASURE should not be allowed. > IMA_DIGSIG_REQUIRED should be limited to APPRAISE action rules. It looks like DONT_APPRAISE should not be allowed. > > > + return false; > > + > > break; > > case KEXEC_CMDLINE: > > if (entry->action & ~(MEASURE | DONT_MEASURE)) > > @@ -1027,7 +1036,8 @@ static bool ima_validate_rule(struct ima_rule_entry *entry) > > default: > > return false; > > } > > - } > > + } else if (entry->flags & IMA_KEYRINGS) > > + return false; > > IMA_MODSIG_ALLOWED and IMA_CHECK_BLACKLIST need to be added here as > well. That makes sense. Tyler > > Mimi > > > > > return true; > > } > > @@ -1209,7 +1219,6 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) > > keyrings_len = strlen(args[0].from) + 1; > > > > if ((entry->keyrings) || > > - (entry->func != KEY_CHECK) || > > (keyrings_len < 2)) { > > result = -EINVAL; > > break;