Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6182810ybc; Wed, 27 Nov 2019 16:48:14 -0800 (PST) X-Google-Smtp-Source: APXvYqz3INDw0rGbRhw4D1NnpkMf2v2WvxnQ8CYW1/FAJJ7DzFYT8HhBN6rA4HA6g7SlWCwWLHyh X-Received: by 2002:a05:6402:c10:: with SMTP id co16mr10717282edb.180.1574902094291; Wed, 27 Nov 2019 16:48:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574902094; cv=none; d=google.com; s=arc-20160816; b=ZKfNOu49hBZ9Q81hEZ38CPYsm9tSHMYfbSE0WXgN8mOaHc4F0gaIYW5/A7LSI04YBP EVKPctKeTqUupA3Nf51RSGKZd7838eR8OQajIbqW73ZDgDA8fajArUj2hyQOQ9yY9qxG MYf+PpC92593OV5CoXdWbd0hN+4vzfPzdA85rfta0MR1vKvz2aLlqzCW6ZIqsDMY59Dc LGtjz/MHQnON3WtTw4WJor+E5TXTfE7tkmZPLPU3YbaO3CyOqkOzGfX0R16v7JxeIAye SfE4TZwAFKsRHtQ1DEPPQQM1miqY5K6d30n1Py8W4gJ6hMu/jL6DUXhN4b4nLf9pt3gw CkRQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature:dkim-filter; bh=i45B9K6gVEFEes7FGLuQ9jYlPqhzKWyb3Cu2Dwz50MQ=; b=y8+vgY458nHaM82wpfO5M+tTWQC0RlFywt534kMe/ujeF/QLiT3kyjyWtD5BGpsx5M lTkVKvOM9ofF/ok8xOQa8P12lHe5JWXQBlCQZdwx6UV40Jr6jRoi3HO4wiGiICiNkuNl sDZiK5izFhcZtrnDjjMonC81wX+0Lk5FWyy6eddOcS2F3xRmzaY+h5852afyjgwJ42lC UmuMez/LVKVXT0mVF8sSima3vdlBcQdlYl9QJtl0xyf0NSv+Ij9fbM+rlN8TRu3SM9E6 hw9WaIvI1ScwpP2PF9i5j1EmozlpuL4t7+Jdj2LGLLzFIVUMoeiRNjOntwycZyKnHU7Y c1WQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Xg9GNm45; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id y21si4164368ejp.88.2019.11.27.16.47.50; Wed, 27 Nov 2019 16:48:14 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=Xg9GNm45; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1727150AbfK1Ao3 (ORCPT + 99 others); Wed, 27 Nov 2019 19:44:29 -0500 Received: from linux.microsoft.com ([13.77.154.182]:59684 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727031AbfK1Ao3 (ORCPT ); Wed, 27 Nov 2019 19:44:29 -0500 Received: from [10.137.112.108] (unknown [131.107.174.108]) by linux.microsoft.com (Postfix) with ESMTPSA id 6AB9720B7185; Wed, 27 Nov 2019 16:44:28 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 6AB9720B7185 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1574901868; bh=i45B9K6gVEFEes7FGLuQ9jYlPqhzKWyb3Cu2Dwz50MQ=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=Xg9GNm45D60C+1lHv95rf09FhgFgasrx8uaOEEbCT6ewMV3l5IisnA0yQyyAlr2Cm jKqcnwQSUCdd3rxD4IollqF7uIV9leFHlvoGIMnx1CB+1xudRcLTwqjq1Foyoqdl4r ViIuxUNiaQZqSrL8PnBgxvEmLbnvMILJj3zG4yPs= Subject: Re: [PATCH v9 5/6] IMA: Add support to limit measuring keys To: Mimi Zohar , linux-integrity@vger.kernel.org Cc: eric.snowberg@oracle.com, dhowells@redhat.com, matthewgarrett@google.com, sashal@kernel.org, jamorris@linux.microsoft.com, linux-kernel@vger.kernel.org, keyrings@vger.kernel.org References: <20191127015654.3744-1-nramas@linux.microsoft.com> <20191127015654.3744-6-nramas@linux.microsoft.com> <1574880741.4793.292.camel@linux.ibm.com> From: Lakshmi Ramasubramanian Message-ID: <18b30666-7c44-f81e-8515-189052007e47@linux.microsoft.com> Date: Wed, 27 Nov 2019 16:44:22 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1 MIME-Version: 1.0 In-Reply-To: <1574880741.4793.292.camel@linux.ibm.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/27/19 10:52 AM, Mimi Zohar wrote: Hi Mimi, >> +static bool ima_match_keyring(struct ima_rule_entry *rule, >> + const char *keyring) >> +{ >> + /* >> + * "keyrings=" is specified in the policy in the format below: >> + * keyrings=.builtin_trusted_keys|.ima|.evm >> + * >> + * Each keyring name in the option is separated by a '|' and >> + * the last keyring name is null terminated. >> + * >> + * The given keyring is considered matched only if >> + * the whole keyring name matched a keyring name specified >> + * in the "keyrings=" option. >> + */ >> + p = strstr(rule->keyrings, keyring); >> + if (p) { >> + /* >> + * Found a substring match. Check if the character >> + * at the end of the keyring name is | (keyring name >> + * separator) or is the terminating null character. >> + * If yes, we have a whole string match. >> + */ >> + p += strlen(keyring); >> + if (*p == '|' || *p == '\0') >> + return true; >> + } >> + > > Using "while strsep()" would simplify this code, removing the need for > such a long comment. > > Mimi strsep() modifies the source string (replaces the delimiter with '\0' and also updates the source string pointer). I am not sure it can be used for our scenario. Please correct me if I am wrong. Initial IMA policy: ------------------- measure func=KEY_CHECK keyrings=.ima|.evm|.builtin_trusted_keys|.blacklist template=ima-buf Policy after adding a key to .ima keyring: ------------------------------------------ measure func=KEY_CHECK keyrings=.evm|.builtin_trusted_keys|.blacklist template=ima-buf Policy after adding a key to a keyring that is not listed in the policy: ------------------------------------------------------------------------ measure func=KEY_CHECK keyrings= template=ima-buf ******************************************************************************** Please see the description from the man page for strsep(): http://man7.org/linux/man-pages/man3/strsep.3.html char *strsep(char **stringp, const char *delim); This function finds the first token in the string *stringp, that is delimited by one of the bytes in the string delim. This token is terminated by overwriting the delimiter with a null byte ('\0'), and *stringp is updated to point past the token. thanks, -lakshmi