Release 4.15 security/integrity/iint.c
/*
* Copyright (C) 2008 IBM Corporation
*
* Authors:
* Mimi Zohar <zohar@us.ibm.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, version 2 of the
* License.
*
* File: integrity_iint.c
* - implements the integrity hooks: integrity_inode_alloc,
* integrity_inode_free
* - cache integrity information associated with an inode
* using a rbtree tree.
*/
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/rbtree.h>
#include <linux/file.h>
#include <linux/uaccess.h>
#include "integrity.h"
static struct rb_root integrity_iint_tree = RB_ROOT;
static DEFINE_RWLOCK(integrity_iint_lock);
static struct kmem_cache *iint_cache __read_mostly;
/*
* __integrity_iint_find - return the iint associated with an inode
*/
static struct integrity_iint_cache *__integrity_iint_find(struct inode *inode)
{
struct integrity_iint_cache *iint;
struct rb_node *n = integrity_iint_tree.rb_node;
while (n) {
iint = rb_entry(n, struct integrity_iint_cache, rb_node);
if (inode < iint->inode)
n = n->rb_left;
else if (inode > iint->inode)
n = n->rb_right;
else
break;
}
if (!n)
return NULL;
return iint;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Paris | 82 | 94.25% | 1 | 50.00% |
Mimi Zohar | 5 | 5.75% | 1 | 50.00% |
Total | 87 | 100.00% | 2 | 100.00% |
/*
* integrity_iint_find - return the iint associated with an inode
*/
struct integrity_iint_cache *integrity_iint_find(struct inode *inode)
{
struct integrity_iint_cache *iint;
if (!IS_IMA(inode))
return NULL;
read_lock(&integrity_iint_lock);
iint = __integrity_iint_find(inode);
read_unlock(&integrity_iint_lock);
return iint;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mimi Zohar | 31 | 62.00% | 2 | 40.00% |
Eric Paris | 17 | 34.00% | 2 | 40.00% |
Dmitry Kasatkin | 2 | 4.00% | 1 | 20.00% |
Total | 50 | 100.00% | 5 | 100.00% |
static void iint_free(struct integrity_iint_cache *iint)
{
kfree(iint->ima_hash);
iint->ima_hash = NULL;
iint->version = 0;
iint->flags = 0UL;
iint->ima_file_status = INTEGRITY_UNKNOWN;
iint->ima_mmap_status = INTEGRITY_UNKNOWN;
iint->ima_bprm_status = INTEGRITY_UNKNOWN;
iint->ima_read_status = INTEGRITY_UNKNOWN;
iint->evm_status = INTEGRITY_UNKNOWN;
iint->measured_pcrs = 0;
kmem_cache_free(iint_cache, iint);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Paris | 29 | 36.71% | 1 | 12.50% |
Mimi Zohar | 25 | 31.65% | 4 | 50.00% |
Dmitry Kasatkin | 19 | 24.05% | 2 | 25.00% |
Eric Richter | 6 | 7.59% | 1 | 12.50% |
Total | 79 | 100.00% | 8 | 100.00% |
/**
* integrity_inode_get - find or allocate an iint associated with an inode
* @inode: pointer to the inode
* @return: allocated iint
*
* Caller must lock i_mutex
*/
struct integrity_iint_cache *integrity_inode_get(struct inode *inode)
{
struct rb_node **p;
struct rb_node *node, *parent = NULL;
struct integrity_iint_cache *iint, *test_iint;
iint = integrity_iint_find(inode);
if (iint)
return iint;
iint = kmem_cache_alloc(iint_cache, GFP_NOFS);
if (!iint)
return NULL;
write_lock(&integrity_iint_lock);
p = &integrity_iint_tree.rb_node;
while (*p) {
parent = *p;
test_iint = rb_entry(parent, struct integrity_iint_cache,
rb_node);
if (inode < test_iint->inode)
p = &(*p)->rb_left;
else
p = &(*p)->rb_right;
}
iint->inode = inode;
node = &iint->rb_node;
inode->i_flags |= S_IMA;
rb_link_node(node, parent, p);
rb_insert_color(node, &integrity_iint_tree);
write_unlock(&integrity_iint_lock);
return iint;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Paris | 83 | 46.63% | 2 | 28.57% |
Mimi Zohar | 53 | 29.78% | 3 | 42.86% |
Dmitry Kasatkin | 42 | 23.60% | 2 | 28.57% |
Total | 178 | 100.00% | 7 | 100.00% |
/**
* integrity_inode_free - called on security_inode_free
* @inode: pointer to the inode
*
* Free the integrity information(iint) associated with an inode.
*/
void integrity_inode_free(struct inode *inode)
{
struct integrity_iint_cache *iint;
if (!IS_IMA(inode))
return;
write_lock(&integrity_iint_lock);
iint = __integrity_iint_find(inode);
rb_erase(&iint->rb_node, &integrity_iint_tree);
write_unlock(&integrity_iint_lock);
iint_free(iint);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mimi Zohar | 38 | 64.41% | 2 | 28.57% |
Eric Paris | 19 | 32.20% | 4 | 57.14% |
Dmitry Kasatkin | 2 | 3.39% | 1 | 14.29% |
Total | 59 | 100.00% | 7 | 100.00% |
static void init_once(void *foo)
{
struct integrity_iint_cache *iint = foo;
memset(iint, 0, sizeof(*iint));
iint->version = 0;
iint->flags = 0UL;
iint->ima_file_status = INTEGRITY_UNKNOWN;
iint->ima_mmap_status = INTEGRITY_UNKNOWN;
iint->ima_bprm_status = INTEGRITY_UNKNOWN;
iint->ima_read_status = INTEGRITY_UNKNOWN;
iint->evm_status = INTEGRITY_UNKNOWN;
iint->measured_pcrs = 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mimi Zohar | 68 | 87.18% | 6 | 66.67% |
Eric Richter | 6 | 7.69% | 1 | 11.11% |
Dmitry Kasatkin | 4 | 5.13% | 2 | 22.22% |
Total | 78 | 100.00% | 9 | 100.00% |
static int __init integrity_iintcache_init(void)
{
iint_cache =
kmem_cache_create("iint_cache", sizeof(struct integrity_iint_cache),
0, SLAB_PANIC, init_once);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mimi Zohar | 25 | 80.65% | 2 | 50.00% |
Eric Paris | 6 | 19.35% | 2 | 50.00% |
Total | 31 | 100.00% | 4 | 100.00% |
security_initcall(integrity_iintcache_init);
/*
* integrity_kernel_read - read data from the file
*
* This is a function for reading file content instead of kernel_read().
* It does not perform locking checks to ensure it cannot be blocked.
* It does not perform security checks because it is irrelevant for IMA.
*
*/
int integrity_kernel_read(struct file *file, loff_t offset,
void *addr, unsigned long count)
{
mm_segment_t old_fs;
char __user *buf = (char __user *)addr;
ssize_t ret;
if (!(file->f_mode & FMODE_READ))
return -EBADF;
old_fs = get_fs();
set_fs(get_ds());
ret = __vfs_read(file, buf, count, &offset);
set_fs(old_fs);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Kasatkin | 86 | 98.85% | 2 | 66.67% |
Thiago Jung Bauermann | 1 | 1.15% | 1 | 33.33% |
Total | 87 | 100.00% | 3 | 100.00% |
/*
* integrity_load_keys - load integrity keys hook
*
* Hooks is called from init/main.c:kernel_init_freeable()
* when rootfs is ready
*/
void __init integrity_load_keys(void)
{
ima_load_x509();
evm_load_x509();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Dmitry Kasatkin | 14 | 100.00% | 2 | 100.00% |
Total | 14 | 100.00% | 2 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Mimi Zohar | 273 | 38.13% | 7 | 26.92% |
Eric Paris | 248 | 34.64% | 6 | 23.08% |
Dmitry Kasatkin | 179 | 25.00% | 10 | 38.46% |
Eric Richter | 12 | 1.68% | 1 | 3.85% |
Tejun Heo | 3 | 0.42% | 1 | 3.85% |
Thiago Jung Bauermann | 1 | 0.14% | 1 | 3.85% |
Total | 716 | 100.00% | 26 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.