forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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;
....@@ -101,6 +98,14 @@
10198 struct rb_node *node, *parent = NULL;
10299 struct integrity_iint_cache *iint, *test_iint;
103100
101
+ /*
102
+ * The integrity's "iint_cache" is initialized at security_init(),
103
+ * unless it is not included in the ordered list of LSMs enabled
104
+ * on the boot command line.
105
+ */
106
+ if (!iint_cache)
107
+ panic("%s: lsm=integrity required.\n", __func__);
108
+
104109 iint = integrity_iint_find(inode);
105110 if (iint)
106111 return iint;
....@@ -174,7 +179,10 @@
174179 0, SLAB_PANIC, init_once);
175180 return 0;
176181 }
177
-security_initcall(integrity_iintcache_init);
182
+DEFINE_LSM(integrity) = {
183
+ .name = "integrity",
184
+ .init = integrity_iintcache_init,
185
+};
178186
179187
180188 /*
....@@ -188,19 +196,7 @@
188196 int integrity_kernel_read(struct file *file, loff_t offset,
189197 void *addr, unsigned long count)
190198 {
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;
199
+ return __kernel_read(file, addr, count, &offset);
204200 }
205201
206202 /*