Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1244456ybi; Fri, 14 Jun 2019 11:03:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPLtoa4rRV3TOBdrHPVxjuELlCEOJPbwPmjmwS51x4x6p+kACqxGtCZY8hREL6lXpENPBf X-Received: by 2002:a17:90a:2008:: with SMTP id n8mr12129729pjc.4.1560535427607; Fri, 14 Jun 2019 11:03:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560535427; cv=none; d=google.com; s=arc-20160816; b=ZKmF4qLLeryyhw9aGpTPms/DCqPgBOkoZ0jsQ0zvtYneVoFSC+5LybLDAoOE9P+X6x ULvyDfFL+p5eRH46gvTUp4KwZPi+ObKkT/4kYjhDmnmQ/vNztAVCUFQACsjxTQNWkSVC 9AoVWqXEkv7RcganZeXlI/VH65FGte4tJo2VvKmoEePhZ9vOAUWWz4GV79xkK6iuQmg0 d4DbKr5a341D01iRnoWS84LR3rQPKzLXNd9qjllcsIJail8lfxUEqynjcddw511dlwP4 f9DPQlRalCFfCpfppp2hZiSi7RkHuJhPLvUbypcnsouUtx0BfJs2vMEAWuTGbA2SM13O 6SHg== 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=hvzXN2iNSL9C7H9vfHcMcsygSbQp8evn5+f7PNrtDSs=; b=woZXumyS6yQPg/N5hvtS1uSXlOJHxTpXqeRBXJx7O/32iM16tSc7K7q5csW/Oj6n1t HN87XeSfyG4j9T55xMsN+iV7uM0gkMlQZs6w2b4eNcS0N6hUjm7uweR3Z/YmAX02g6Fc XZhHBdGG43pJSK/vCrXsKrmf4r/TsRl0/+NHbWWLNeSOTIFhJhI1NjZnbAN5LfpJsLZL HZ2OPE4Le5x3rXRloNFwDqT8pg9FXZX3Fx299U5Q9bCXrh/u0AbqU8IICPhqnufRqf+3 y9A9MQmGo1cOitUk0yVLX5zdmfjqdTGg49nZxG17b3nO8nzXnZgmmENogPQ/yvxsNdPC WBMg== 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 16si2988165pgl.570.2019.06.14.11.03.32; Fri, 14 Jun 2019 11:03:47 -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 S1727612AbfFNSBy (ORCPT + 99 others); Fri, 14 Jun 2019 14:01:54 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:33013 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727012AbfFNSBy (ORCPT ); Fri, 14 Jun 2019 14:01:54 -0400 Received: from lhreml702-cah.china.huawei.com (unknown [172.18.7.108]) by Forcepoint Email with ESMTP id C84BC33E3C655E10B946; Fri, 14 Jun 2019 19:01:52 +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:01:44 +0100 From: Roberto Sassu To: , , CC: , , , , , , Roberto Sassu Subject: [PATCH v4 05/14] ima: use ima_show_htable_value to show violations and hash table data Date: Fri, 14 Jun 2019 19:55:04 +0200 Message-ID: <20190614175513.27097-6-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 ima_show_htable_violations() and ima_show_measurements_count() both call ima_show_htable_value() to copy the value of an atomic_long_t variable to a buffer. This patch modifies the definition of ima_show_htable_value(), so that this function can be used in any file_operations structure. The atomic_long_t variable used as source is chosen depending on the opened file in the securityfs filesystem. Signed-off-by: Roberto Sassu --- security/integrity/ima/ima_fs.c | 38 +++++++++++---------------------- 1 file changed, 12 insertions(+), 26 deletions(-) diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c index c8bbc56f735e..0f503b7cd396 100644 --- a/security/integrity/ima/ima_fs.c +++ b/security/integrity/ima/ima_fs.c @@ -47,38 +47,24 @@ __setup("ima_canonical_fmt", default_canonical_fmt_setup); static int valid_policy = 1; -static ssize_t ima_show_htable_value(char __user *buf, size_t count, - loff_t *ppos, atomic_long_t *val) +static ssize_t ima_show_htable_value(struct file *filp, char __user *buf, + size_t count, loff_t *ppos) { + atomic_long_t *val = NULL; char tmpbuf[32]; /* greater than largest 'long' string value */ ssize_t len; + if (filp->f_path.dentry == violations) + val = &ima_htable.violations; + else if (filp->f_path.dentry == runtime_measurements_count) + val = &ima_htable.len; + len = scnprintf(tmpbuf, sizeof(tmpbuf), "%li\n", atomic_long_read(val)); return simple_read_from_buffer(buf, count, ppos, tmpbuf, len); } -static ssize_t ima_show_htable_violations(struct file *filp, - char __user *buf, - size_t count, loff_t *ppos) -{ - return ima_show_htable_value(buf, count, ppos, &ima_htable.violations); -} - -static const struct file_operations ima_htable_violations_ops = { - .read = ima_show_htable_violations, - .llseek = generic_file_llseek, -}; - -static ssize_t ima_show_measurements_count(struct file *filp, - char __user *buf, - size_t count, loff_t *ppos) -{ - return ima_show_htable_value(buf, count, ppos, &ima_htable.len); - -} - -static const struct file_operations ima_measurements_count_ops = { - .read = ima_show_measurements_count, +static const struct file_operations ima_htable_value_ops = { + .read = ima_show_htable_value, .llseek = generic_file_llseek, }; @@ -527,13 +513,13 @@ int __init ima_fs_init(void) runtime_measurements_count = securityfs_create_file("runtime_measurements_count", S_IRUSR | S_IRGRP, ima_dir, NULL, - &ima_measurements_count_ops); + &ima_htable_value_ops); if (IS_ERR(runtime_measurements_count)) goto out; violations = securityfs_create_file("violations", S_IRUSR | S_IRGRP, - ima_dir, NULL, &ima_htable_violations_ops); + ima_dir, NULL, &ima_htable_value_ops); if (IS_ERR(violations)) goto out; -- 2.17.1