Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1314065pxv; Fri, 25 Jun 2021 10:01:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJVYtRR9RFw2H32TbhbA1FlnPyslgWNzSqMkg+9zeTHPnTM0Uw2FxWfxa8Da5GE+JVJmku X-Received: by 2002:a17:906:144b:: with SMTP id q11mr11850698ejc.478.1624640500883; Fri, 25 Jun 2021 10:01:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624640500; cv=none; d=google.com; s=arc-20160816; b=qzdA3vfkQPjSFolqv2629ofVpcJVxieGdWn3pVvN497cDFdZRpZlYzsU966+ImLLK1 8MnYyE97HjQufyBFCdEiJQoZ30zJTPadV4NVnXx0NEwvsrth1YPDjr5lWQ//rCKZpEWS O+cm5cwMMpVhtuF/as0S3xAC1eIWvuEoKmQwEdcF1QKONgzCPRQnIgnM8qYvKMMoT2mw uG815uxPI864TvNSlgobF7P9sYEmUNuVxnFqAaumnEHM/Kb6GhjxeqJ7ioEju4rqNiIu jTH9R0ONHqdDDdqErvIAuVRVCs7ZdxNmVvXtlpU4i7Uf4g/G9vWO0hig1NcSWojpksiG K0UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jUfx5FElksmdBNsMLGmf5LxKW1H5Nk71+2Ad1sqwjBY=; b=cwAwczRXazOD2xq75/fEYxkUDA3UIB3Z9ybfwIkhfuNlJFvAFT0m85wemsIlc+yhPt TlgCuUEZ/ZpIpj5TQNooPbTx1fvjjm4vzyEl+KHkjXD9hXDojSg+NpcR5gIi6wN1Tl6j ybeft5XrA//les3k+hSDZ/1+i1hycedPf01/0gmIwCD3iQXN5bcVHjQgO6Z0koA5pFPQ EUGX6JbkBn/deGuyEBFYvHJFc/wcH+xuJdP8oJdxN407/Pn0xPOBtlqaHlrBWQ+T9SDx tK/qcssYCEtyZhOUerPpJXdbuv5+3X9Ozk2kjgYF+i4+xEDPfGi3SeUV+harOpJCLNKU LgEQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 20si7170755edw.376.2021.06.25.10.01.17; Fri, 25 Jun 2021 10:01:40 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230296AbhFYRBn (ORCPT + 99 others); Fri, 25 Jun 2021 13:01:43 -0400 Received: from frasgout.his.huawei.com ([185.176.79.56]:3318 "EHLO frasgout.his.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230094AbhFYRBl (ORCPT ); Fri, 25 Jun 2021 13:01:41 -0400 Received: from fraeml714-chm.china.huawei.com (unknown [172.18.147.207]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4GBND91GHlz6L52F; Sat, 26 Jun 2021 00:45:45 +0800 (CST) Received: from roberto-ThinkStation-P620.huawei.com (10.204.63.22) by fraeml714-chm.china.huawei.com (10.206.15.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 25 Jun 2021 18:59:18 +0200 From: Roberto Sassu To: CC: , , , , , Roberto Sassu Subject: [RFC][PATCH 11/12] digest_lists: Interfaces - digests_count Date: Fri, 25 Jun 2021 18:56:13 +0200 Message-ID: <20210625165614.2284243-12-roberto.sassu@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210625165614.2284243-1-roberto.sassu@huawei.com> References: <20210625165614.2284243-1-roberto.sassu@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.204.63.22] X-ClientProxiedBy: lhreml751-chm.china.huawei.com (10.201.108.201) To fraeml714-chm.china.huawei.com (10.206.15.33) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch introduces the digests_count interface, which shows the current number of digests stored in the hash table by type. Signed-off-by: Roberto Sassu --- Documentation/security/digest_lists.rst | 7 +++++ security/integrity/digest_lists/fs.c | 35 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/Documentation/security/digest_lists.rst b/Documentation/security/digest_lists.rst index f3900a6e92f6..25b5665bbeaa 100644 --- a/Documentation/security/digest_lists.rst +++ b/Documentation/security/digest_lists.rst @@ -697,3 +697,10 @@ digest list (buffer) loaded ``through digest_list_add``. ``digest_query``: allows to write a query in the format ``-`` and to obtain all digest lists that include that digest. + + +``digests_count`` +~~~~~~~~~~~~~~~~~ + +``digests_count`` shows the current number of digests stored in the hash +table by type. diff --git a/security/integrity/digest_lists/fs.c b/security/integrity/digest_lists/fs.c index bdfeb8797760..37091db50df5 100644 --- a/security/integrity/digest_lists/fs.c +++ b/security/integrity/digest_lists/fs.c @@ -37,6 +37,7 @@ static struct dentry *digest_lists_dir; static struct dentry *digest_lists_loaded_dir; +static struct dentry *digests_count; static struct dentry *digest_label_dentry; static struct dentry *digest_query_dentry; static struct dentry *digest_list_add_dentry; @@ -44,6 +45,33 @@ static struct dentry *digest_list_del_dentry; char digest_query[CRYPTO_MAX_ALG_NAME + 1 + IMA_MAX_DIGEST_SIZE * 2 + 1]; char digest_label[NAME_MAX + 1]; +static char *types_str[COMPACT__LAST] = { + [COMPACT_PARSER] = "Parser", + [COMPACT_FILE] = "File", + [COMPACT_METADATA] = "Metadata", + [COMPACT_DIGEST_LIST] = "Digest list", +}; + +static ssize_t digest_lists_show_htable_len(struct file *filp, char __user *buf, + size_t count, loff_t *ppos) +{ + char tmpbuf[1024]; + ssize_t len = 0; + int i; + + for (i = COMPACT_PARSER; i < COMPACT__LAST; i++) + len += scnprintf(tmpbuf + len, sizeof(tmpbuf) - len, + "%s digests: %li\n", types_str[i], + atomic_long_read(&htable[i].len)); + + return simple_read_from_buffer(buf, count, ppos, tmpbuf, len); +} + +static const struct file_operations htable_len_ops = { + .read = digest_lists_show_htable_len, + .llseek = generic_file_llseek, +}; + static int parse_digest_list_filename(const char *digest_list_filename, u8 *digest, enum hash_algo *algo) { @@ -646,6 +674,12 @@ static int __init digest_lists_fs_init(void) if (IS_ERR(digest_lists_loaded_dir)) goto out; + digests_count = securityfs_create_file("digests_count", 0440, + digest_lists_dir, NULL, + &htable_len_ops); + if (IS_ERR(digests_count)) + goto out; + digest_list_add_dentry = securityfs_create_file("digest_list_add", 0200, digest_lists_dir, NULL, &digest_list_upload_ops); @@ -676,6 +710,7 @@ static int __init digest_lists_fs_init(void) securityfs_remove(digest_label_dentry); securityfs_remove(digest_list_del_dentry); securityfs_remove(digest_list_add_dentry); + securityfs_remove(digests_count); securityfs_remove(digest_lists_loaded_dir); securityfs_remove(digest_lists_dir); return -1; -- 2.25.1