Skip to content
Permalink
Browse files
security/integrity/ima: converts stats to seqnum_ops
Sequence Number api provides interfaces for unsigned atomic up counters
leveraging atomic_t and atomic64_t ops underneath. Convert it to use
seqnum_ops.

atomic_t variables used for ima_htable.violations and number of stored
measurements and ios_threshold are atomic counters. Convert them to
seqnum_ops.

Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
  • Loading branch information
shuahkh authored and intel-lab-lkp committed Nov 13, 2020
1 parent 44fb112 commit b86077d3629fe6d16070d95b8331344258dcaed2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
@@ -21,6 +21,7 @@
#include <linux/tpm.h>
#include <linux/audit.h>
#include <crypto/hash_info.h>
#include <linux/seqnum_ops.h>

#include "../integrity.h"

@@ -174,8 +175,8 @@ int ima_lsm_policy_change(struct notifier_block *nb, unsigned long event,
extern spinlock_t ima_queue_lock;

struct ima_h_table {
atomic_long_t len; /* number of stored measurements in the list */
atomic_long_t violations;
struct seqnum64 len; /* number of stored measurements in the list */
struct seqnum64 violations;
struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
};
extern struct ima_h_table ima_htable;
@@ -14,6 +14,7 @@
#include <linux/xattr.h>
#include <linux/evm.h>
#include <linux/iversion.h>
#include <linux/seqnum_ops.h>

#include "ima.h"

@@ -144,7 +145,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
int result;

/* can overflow, only indicator */
atomic_long_inc(&ima_htable.violations);
seqnum64_inc_return(&ima_htable.violations);

result = ima_alloc_init_template(&event_data, &entry, NULL);
if (result < 0) {
@@ -21,6 +21,7 @@
#include <linux/rcupdate.h>
#include <linux/parser.h>
#include <linux/vmalloc.h>
#include <linux/seqnum_ops.h>

#include "ima.h"

@@ -39,12 +40,12 @@ __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)
loff_t *ppos, struct seqnum64 *val)
{
char tmpbuf[32]; /* greater than largest 'long' string value */
ssize_t len;

len = scnprintf(tmpbuf, sizeof(tmpbuf), "%li\n", atomic_long_read(val));
len = scnprintf(tmpbuf, sizeof(tmpbuf), "%llu\n", seqnum64_fetch(val));
return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
}

@@ -17,6 +17,7 @@

#include <linux/rculist.h>
#include <linux/slab.h>
#include <linux/seqnum_ops.h>
#include "ima.h"

#define AUDIT_CAUSE_LEN_MAX 32
@@ -33,8 +34,8 @@ static unsigned long binary_runtime_size = ULONG_MAX;

/* key: inode (before secure-hashing a file) */
struct ima_h_table ima_htable = {
.len = ATOMIC_LONG_INIT(0),
.violations = ATOMIC_LONG_INIT(0),
.len = SEQNUM_INIT(0),
.violations = SEQNUM_INIT(0),
.queue[0 ... IMA_MEASURE_HTABLE_SIZE - 1] = HLIST_HEAD_INIT
};

@@ -106,7 +107,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry,
INIT_LIST_HEAD(&qe->later);
list_add_tail_rcu(&qe->later, &ima_measurements);

atomic_long_inc(&ima_htable.len);
seqnum64_inc_return(&ima_htable.len);
if (update_htable) {
key = ima_hash_key(entry->digests[ima_hash_algo_idx].digest);
hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);

0 comments on commit b86077d

Please sign in to comment.