hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/integrity/iint.c
....@@ -1,13 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2008 IBM Corporation
34 *
45 * Authors:
56 * Mimi Zohar <zohar@us.ibm.com>
6
- *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License as
9
- * published by the Free Software Foundation, version 2 of the
10
- * License.
117 *
128 * File: integrity_iint.c
139 * - implements the integrity hooks: integrity_inode_alloc,
....@@ -16,12 +12,13 @@
1612 * using a rbtree tree.
1713 */
1814 #include <linux/slab.h>
19
-#include <linux/module.h>
15
+#include <linux/init.h>
2016 #include <linux/spinlock.h>
2117 #include <linux/rbtree.h>
2218 #include <linux/file.h>
2319 #include <linux/uaccess.h>
2420 #include <linux/security.h>
21
+#include <linux/lsm_hooks.h>
2522 #include "integrity.h"
2623
2724 static struct rb_root integrity_iint_tree = RB_ROOT;
....@@ -46,12 +43,10 @@
4643 else if (inode > iint->inode)
4744 n = n->rb_right;
4845 else
49
- break;
46
+ return iint;
5047 }
51
- if (!n)
52
- return NULL;
5348
54
- return iint;
49
+ return NULL;
5550 }
5651
5752 /*
....@@ -101,6 +96,14 @@
10196 struct rb_node *node, *parent = NULL;
10297 struct integrity_iint_cache *iint, *test_iint;
10398
99
+ /*
100
+ * The integrity's "iint_cache" is initialized at security_init(),
101
+ * unless it is not included in the ordered list of LSMs enabled
102
+ * on the boot command line.
103
+ */
104
+ if (!iint_cache)
105
+ panic("%s: lsm=integrity required.\n", __func__);
106
+
104107 iint = integrity_iint_find(inode);
105108 if (iint)
106109 return iint;
....@@ -116,10 +119,15 @@
116119 parent = *p;
117120 test_iint = rb_entry(parent, struct integrity_iint_cache,
118121 rb_node);
119
- if (inode < test_iint->inode)
122
+ if (inode < test_iint->inode) {
120123 p = &(*p)->rb_left;
121
- else
124
+ } else if (inode > test_iint->inode) {
122125 p = &(*p)->rb_right;
126
+ } else {
127
+ write_unlock(&integrity_iint_lock);
128
+ kmem_cache_free(iint_cache, iint);
129
+ return test_iint;
130
+ }
123131 }
124132
125133 iint->inode = inode;
....@@ -174,7 +182,10 @@
174182 0, SLAB_PANIC, init_once);
175183 return 0;
176184 }
177
-security_initcall(integrity_iintcache_init);
185
+DEFINE_LSM(integrity) = {
186
+ .name = "integrity",
187
+ .init = integrity_iintcache_init,
188
+};
178189
179190
180191 /*
....@@ -188,19 +199,7 @@
188199 int integrity_kernel_read(struct file *file, loff_t offset,
189200 void *addr, unsigned long count)
190201 {
191
- mm_segment_t old_fs;
192
- char __user *buf = (char __user *)addr;
193
- ssize_t ret;
194
-
195
- if (!(file->f_mode & FMODE_READ))
196
- return -EBADF;
197
-
198
- old_fs = get_fs();
199
- set_fs(get_ds());
200
- ret = __vfs_read(file, buf, count, &offset);
201
- set_fs(old_fs);
202
-
203
- return ret;
202
+ return __kernel_read(file, addr, count, &offset);
204203 }
205204
206205 /*