From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-24.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3902C4338F for ; Wed, 4 Aug 2021 20:51:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BCF9E60F22 for ; Wed, 4 Aug 2021 20:51:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236064AbhHDUvQ (ORCPT ); Wed, 4 Aug 2021 16:51:16 -0400 Received: from linux.microsoft.com ([13.77.154.182]:60682 "EHLO linux.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230218AbhHDUvP (ORCPT ); Wed, 4 Aug 2021 16:51:15 -0400 Received: from [10.137.112.111] (unknown [131.107.147.111]) by linux.microsoft.com (Postfix) with ESMTPSA id 8946B209DD68; Wed, 4 Aug 2021 13:51:02 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 8946B209DD68 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1628110262; bh=j+Jdj14wduq+3kGM8o+waUHvvZ7RhGotGzO5WNDWr9k=; h=Subject:To:References:From:Date:In-Reply-To:From; b=tIyhOAkEw/1S4aRa4rjk/WvOm2oYHRnRaaUrNvJVxp1/UwWpZGSeop//Fumx26Um/ 7GIe9SVe0qU3VJ/JfxEiAXzDcznNBe1sVQBT+vGFjYOuEZlR9LZUZ5YmuHHxSS5Gvz YkYflrSpKwBP89MYfKsZIWnqGKdRVH6daYsRWtX4= Subject: Re: [PATCH v6 4/5] IMA: add a policy option to restrict xattr hash algorithms on appraisal To: THOBY Simon , "zohar@linux.ibm.com" , "dmitry.kasatkin@gmail.com" , "linux-integrity@vger.kernel.org" , BARVAUX Didier References: <20210804092010.350372-1-simon.thoby@viveris.fr> <20210804092010.350372-5-simon.thoby@viveris.fr> From: Lakshmi Ramasubramanian Message-ID: Date: Wed, 4 Aug 2021 13:53:02 -0700 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 MIME-Version: 1.0 In-Reply-To: <20210804092010.350372-5-simon.thoby@viveris.fr> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-integrity@vger.kernel.org Hi Simon, On 8/4/2021 2:20 AM, THOBY Simon wrote: > Signed-off-by: Simon Thoby > Reviewed-by: Mimi Zohar > --- > Documentation/ABI/testing/ima_policy | 6 ++- > security/integrity/ima/ima_policy.c | 75 ++++++++++++++++++++++++++-- > 2 files changed, 76 insertions(+), 5 deletions(-) > > > +static unsigned int ima_parse_appraise_hash(char *arg) > +{ > + unsigned int res = 0; > + int idx; > + char *token; > + > + while ((token = strsep(&arg, ",")) != NULL) { > + idx = match_string(hash_algo_name, HASH_ALGO__LAST, token); > + > + if (idx < 0) { > + pr_err("unknown hash algorithm \"%s\", ignoring", > + token); > + continue; Is it right to ignore an invalid digest algorithm given in the IMA policy rule? Should "invalid ima policy" error be reported instead? Other changes look good. Reviewed-by: Lakshmi Ramasubramanian -lakshmi > + } > + > + /* Add the hash algorithm to the 'allowed' bitfield */ > + res |= (1U << idx); > + } > + > + return res; > +} > + > static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) > { > struct audit_buffer *ab; > @@ -1522,6 +1546,26 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry) > else > result = -EINVAL; > break; > + case Opt_appraise_hash: > + ima_log_string(ab, "appraise_hash", args[0].from); > + > + if (entry->allowed_hashes) { > + result = -EINVAL; > + break; > + } > + > + entry->allowed_hashes = > + ima_parse_appraise_hash(args[0].from); > + > + /* invalid or empty list of algorithms */ > + if (!entry->allowed_hashes) { > + result = -EINVAL; > + break; > + } > + > + entry->flags |= IMA_VALIDATE_HASH; > + > + break; > case Opt_permit_directio: > entry->flags |= IMA_PERMIT_DIRECTIO; > break; > @@ -1714,6 +1758,23 @@ static void ima_show_rule_opt_list(struct seq_file *m, > seq_printf(m, "%s%s", i ? "|" : "", opt_list->items[i]); > } > > +static void ima_policy_show_appraise_hash(struct seq_file *m, > + unsigned int allowed_hashes) > +{ > + int idx, list_size = 0; > + > + for (idx = 0; idx < HASH_ALGO__LAST; idx++) { > + if (!(allowed_hashes & (1U << idx))) > + continue; > + > + /* only add commas if the list contains multiple entries */ > + if (list_size++) > + seq_puts(m, ","); > + > + seq_puts(m, hash_algo_name[idx]); > + } > +} > + > int ima_policy_show(struct seq_file *m, void *v) > { > struct ima_rule_entry *entry = v; > @@ -1825,6 +1886,12 @@ int ima_policy_show(struct seq_file *m, void *v) > seq_puts(m, " "); > } > > + if (entry->flags & IMA_VALIDATE_HASH) { > + seq_puts(m, "appraise_hash="); > + ima_policy_show_appraise_hash(m, entry->allowed_hashes); > + seq_puts(m, " "); > + } > + > for (i = 0; i < MAX_LSM_RULES; i++) { > if (entry->lsm[i].rule) { > switch (i) { >