Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1244205ybi; Fri, 14 Jun 2019 11:03:34 -0700 (PDT) X-Google-Smtp-Source: APXvYqzpAvycMuiYMx/KcDhJZAERTBNk9AVfzo38256LCMq6DeVqtAMlWubxLyrzuW+katX+xVk1 X-Received: by 2002:a17:90a:bb8a:: with SMTP id v10mr12540839pjr.78.1560535414010; Fri, 14 Jun 2019 11:03:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560535414; cv=none; d=google.com; s=arc-20160816; b=NHHNekWKUP8NRDuRAN7bDubbOrVTimqMxNh+kxkx8xlJGbotTIJTN3Jho8KhTUVhJf hiquew1fKOHqotde6DPjE59zFeJjO71x5s+8kBpLHN5+mCP4DcZPgf8v9F1mr/dRmr1y rRVKG7SRRXGZfPn5lRDgrmvjFZl1Rge23jX3eLZE8BtwH4kyGdhlpQ/MxrprlR5nm1ud rWTSzh00ltJMVuXZg0PWfXj+8nGNiRMrWqrKEifWCEqyqI4bP0tghPO3U7+rrVkH3vvj GiZY1W/se/duFUTKokHQqexeGs1uQwpcZ9bbzlDZB02texUT2rsSeem/kYSuQuZ0nBLe IjWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=FvluWQ41fLYCi2jkznZOxhES2v5/L8Z+BU+MikvHC9M=; b=RpLFYUlJciRN3QsKgsME4f3yf/Y0BUqXUHSbPCHrg07YpM1lGLffTqgq3ndXKx0fcm MRO8JFe2lWjxVlGoKsIR5jRGOo8bPRegPwUFA6/FrupiQqZ103fwooOjuCmuXhVaGUKU ZMQ3f/MUAmIcsEr1VSpBDS8w29e2xEhcwZO9AqtmTVJ0qocX1c9YgFx5EaUtB5ogY9nK H2KkULs6L5pjj67UDzoR9OoAx4gAxZNV8ke31y/Q5VuxqliUGFuKGaS1++JgDjSPD5ot eQu6J3aaHHygyFxwpHnk+RVDMBFK7Vyr/h24Rj4HUok5o/1r5VhoEcmClEFsodaqD/4P AqgQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bc7si2722507plb.108.2019.06.14.11.03.18; Fri, 14 Jun 2019 11:03:33 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727433AbfFNSDA (ORCPT + 99 others); Fri, 14 Jun 2019 14:03:00 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:33015 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726835AbfFNSDA (ORCPT ); Fri, 14 Jun 2019 14:03:00 -0400 Received: from lhreml702-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id B66DC9C8D42CB2B4B75C; Fri, 14 Jun 2019 19:02:58 +0100 (IST) Received: from roberto-HP-EliteDesk-800-G2-DM-65W.huawei.com (10.204.65.154) by smtpsuk.huawei.com (10.201.108.43) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 14 Jun 2019 19:02:49 +0100 From: Roberto Sassu To: , , CC: , , , , , , Roberto Sassu Subject: [PATCH v4 07/14] ima: restrict upload of converted digest lists Date: Fri, 14 Jun 2019 19:55:06 +0200 Message-ID: <20190614175513.27097-8-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190614175513.27097-1-roberto.sassu@huawei.com> References: <20190614175513.27097-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.204.65.154] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If digest lists cannot be directly parsed by the kernel, access to the securityfs file must be exclusively granted to the parser, to avoid that an arbitrary process makes undesired modifications before uploading converted lists to IMA. Digest lists are measured before they are converted and no new measurement is taken after conversion. This patch introduces ima_check_set_parser(), to verify whether the process opening the interface to upload digest lists is the user space parser. It checks whether the digest of the executable is found in a digest list and if the type of found digest is COMPACT_PARSER. It also introduces ima_set_parser() and ima_get_parser() to return the task_struct of the process that opened digest_list_data. This will be used to determine whether digest lists have been measured/appraised and, if not, to prevent their usage. Signed-off-by: Roberto Sassu --- security/integrity/ima/ima_digest_list.c | 54 ++++++++++++++++++++++++ security/integrity/ima/ima_digest_list.h | 14 ++++++ 2 files changed, 68 insertions(+) diff --git a/security/integrity/ima/ima_digest_list.c b/security/integrity/ima/ima_digest_list.c index 6c7dd2cfbb68..3c77a6cec29a 100644 --- a/security/integrity/ima/ima_digest_list.c +++ b/security/integrity/ima/ima_digest_list.c @@ -17,6 +17,8 @@ #include #include +#include +#include #include "ima.h" #include "ima_digest_list.h" @@ -150,3 +152,55 @@ int ima_parse_compact_list(loff_t size, void *buf) return bufp - buf; } + +/**************** + * Parser check * + ****************/ +bool ima_check_current_is_parser(void) +{ + struct integrity_iint_cache *parser_iint; + struct ima_digest *parser_digest = NULL; + struct file *parser_file; + struct mm_struct *mm; + + mm = get_task_mm(current); + if (!mm) + return false; + + parser_file = get_mm_exe_file(mm); + mmput(mm); + + if (!parser_file) + return false; + + parser_iint = integrity_iint_find(file_inode(parser_file)); + fput(parser_file); + + if (!parser_iint) + return false; + + /* flag cannot be cleared due to write protection of executables */ + if (!(parser_iint->flags & IMA_COLLECTED)) + return false; + + parser_digest = ima_lookup_digest(parser_iint->ima_hash->digest, + parser_iint->ima_hash->algo); + + return (parser_digest && parser_digest->type == COMPACT_PARSER); +} + +/* + * Current parser set and reset respectively during open() and close() of + * /sys/kernel/security/ima/digest_list_data. + */ +static struct task_struct *current_parser; + +void ima_set_parser(struct task_struct *parser) +{ + current_parser = parser; +} + +struct task_struct *ima_get_parser(void) +{ + return current_parser; +} diff --git a/security/integrity/ima/ima_digest_list.h b/security/integrity/ima/ima_digest_list.h index 13cdc3d954bd..be07a4afd7b6 100644 --- a/security/integrity/ima/ima_digest_list.h +++ b/security/integrity/ima/ima_digest_list.h @@ -26,6 +26,9 @@ extern struct ima_h_table ima_digests_htable; struct ima_digest *ima_lookup_digest(u8 *digest, enum hash_algo algo); int ima_parse_compact_list(loff_t size, void *buf); +bool ima_check_current_is_parser(void); +void ima_set_parser(struct task_struct *parser); +struct task_struct *ima_get_parser(void); #else static inline struct ima_digest *ima_lookup_digest(u8 *digest, enum hash_algo algo) @@ -36,5 +39,16 @@ static inline int ima_parse_compact_list(loff_t size, void *buf) { return -ENOTSUPP; } +static inline bool ima_check_current_is_parser(void) +{ + return false; +} +static inline void ima_set_parser(struct task_struct *parser) +{ +} +static inline struct task_struct *ima_get_parser(void) +{ + return NULL; +} #endif /*CONFIG_IMA_DIGEST_LIST*/ #endif /*LINUX_IMA_DIGEST_LIST_H*/ -- 2.17.1