Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 2 | #include "audit.h" |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 3 | #include <linux/fsnotify_backend.h> |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 4 | #include <linux/namei.h> |
| 5 | #include <linux/mount.h> |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 6 | #include <linux/kthread.h> |
Elena Reshetova | 9d2378f | 2017-05-02 10:16:04 -0400 | [diff] [blame] | 7 | #include <linux/refcount.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 9 | |
| 10 | struct audit_tree; |
| 11 | struct audit_chunk; |
| 12 | |
| 13 | struct audit_tree { |
Elena Reshetova | 9d2378f | 2017-05-02 10:16:04 -0400 | [diff] [blame] | 14 | refcount_t count; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 15 | int goner; |
| 16 | struct audit_chunk *root; |
| 17 | struct list_head chunks; |
| 18 | struct list_head rules; |
| 19 | struct list_head list; |
| 20 | struct list_head same_root; |
| 21 | struct rcu_head head; |
| 22 | char pathname[]; |
| 23 | }; |
| 24 | |
| 25 | struct audit_chunk { |
| 26 | struct list_head hash; |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 27 | unsigned long key; |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 28 | struct fsnotify_mark mark; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 29 | struct list_head trees; /* with root here */ |
| 30 | int dead; |
| 31 | int count; |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 32 | atomic_long_t refs; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 33 | struct rcu_head head; |
| 34 | struct node { |
| 35 | struct list_head list; |
| 36 | struct audit_tree *owner; |
| 37 | unsigned index; /* index; upper bit indicates 'will prune' */ |
| 38 | } owners[]; |
| 39 | }; |
| 40 | |
| 41 | static LIST_HEAD(tree_list); |
| 42 | static LIST_HEAD(prune_list); |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 43 | static struct task_struct *prune_thread; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * One struct chunk is attached to each inode of interest. |
| 47 | * We replace struct chunk on tagging/untagging. |
| 48 | * Rules have pointer to struct audit_tree. |
| 49 | * Rules have struct list_head rlist forming a list of rules over |
| 50 | * the same tree. |
| 51 | * References to struct chunk are collected at audit_inode{,_child}() |
| 52 | * time and used in AUDIT_TREE rule matching. |
| 53 | * These references are dropped at the same time we are calling |
| 54 | * audit_free_names(), etc. |
| 55 | * |
| 56 | * Cyclic lists galore: |
| 57 | * tree.chunks anchors chunk.owners[].list hash_lock |
| 58 | * tree.rules anchors rule.rlist audit_filter_mutex |
| 59 | * chunk.trees anchors tree.same_root hash_lock |
| 60 | * chunk.hash is a hash with middle bits of watch.inode as |
| 61 | * a hash function. RCU, hash_lock |
| 62 | * |
| 63 | * tree is refcounted; one reference for "some rules on rules_list refer to |
| 64 | * it", one for each chunk with pointer to it. |
| 65 | * |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 66 | * chunk is refcounted by embedded fsnotify_mark + .refs (non-zero refcount |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 67 | * of watch contributes 1 to .refs). |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 68 | * |
| 69 | * node.index allows to get from node.list to containing chunk. |
| 70 | * MSB of that sucker is stolen to mark taggings that we might have to |
| 71 | * revert - several operations have very unpleasant cleanup logics and |
| 72 | * that makes a difference. Some. |
| 73 | */ |
| 74 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 75 | static struct fsnotify_group *audit_tree_group; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 76 | |
| 77 | static struct audit_tree *alloc_tree(const char *s) |
| 78 | { |
| 79 | struct audit_tree *tree; |
| 80 | |
| 81 | tree = kmalloc(sizeof(struct audit_tree) + strlen(s) + 1, GFP_KERNEL); |
| 82 | if (tree) { |
Elena Reshetova | 9d2378f | 2017-05-02 10:16:04 -0400 | [diff] [blame] | 83 | refcount_set(&tree->count, 1); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 84 | tree->goner = 0; |
| 85 | INIT_LIST_HEAD(&tree->chunks); |
| 86 | INIT_LIST_HEAD(&tree->rules); |
| 87 | INIT_LIST_HEAD(&tree->list); |
| 88 | INIT_LIST_HEAD(&tree->same_root); |
| 89 | tree->root = NULL; |
| 90 | strcpy(tree->pathname, s); |
| 91 | } |
| 92 | return tree; |
| 93 | } |
| 94 | |
| 95 | static inline void get_tree(struct audit_tree *tree) |
| 96 | { |
Elena Reshetova | 9d2378f | 2017-05-02 10:16:04 -0400 | [diff] [blame] | 97 | refcount_inc(&tree->count); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 98 | } |
| 99 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 100 | static inline void put_tree(struct audit_tree *tree) |
| 101 | { |
Elena Reshetova | 9d2378f | 2017-05-02 10:16:04 -0400 | [diff] [blame] | 102 | if (refcount_dec_and_test(&tree->count)) |
Lai Jiangshan | 3b097c4 | 2011-03-15 18:03:53 +0800 | [diff] [blame] | 103 | kfree_rcu(tree, head); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /* to avoid bringing the entire thing in audit.h */ |
| 107 | const char *audit_tree_path(struct audit_tree *tree) |
| 108 | { |
| 109 | return tree->pathname; |
| 110 | } |
| 111 | |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 112 | static void free_chunk(struct audit_chunk *chunk) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 113 | { |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 114 | int i; |
| 115 | |
| 116 | for (i = 0; i < chunk->count; i++) { |
| 117 | if (chunk->owners[i].owner) |
| 118 | put_tree(chunk->owners[i].owner); |
| 119 | } |
| 120 | kfree(chunk); |
| 121 | } |
| 122 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 123 | void audit_put_chunk(struct audit_chunk *chunk) |
| 124 | { |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 125 | if (atomic_long_dec_and_test(&chunk->refs)) |
| 126 | free_chunk(chunk); |
| 127 | } |
| 128 | |
| 129 | static void __put_chunk(struct rcu_head *rcu) |
| 130 | { |
| 131 | struct audit_chunk *chunk = container_of(rcu, struct audit_chunk, head); |
| 132 | audit_put_chunk(chunk); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 135 | static void audit_tree_destroy_watch(struct fsnotify_mark *entry) |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 136 | { |
| 137 | struct audit_chunk *chunk = container_of(entry, struct audit_chunk, mark); |
| 138 | call_rcu(&chunk->head, __put_chunk); |
| 139 | } |
| 140 | |
| 141 | static struct audit_chunk *alloc_chunk(int count) |
| 142 | { |
| 143 | struct audit_chunk *chunk; |
| 144 | size_t size; |
| 145 | int i; |
| 146 | |
| 147 | size = offsetof(struct audit_chunk, owners) + count * sizeof(struct node); |
| 148 | chunk = kzalloc(size, GFP_KERNEL); |
| 149 | if (!chunk) |
| 150 | return NULL; |
| 151 | |
| 152 | INIT_LIST_HEAD(&chunk->hash); |
| 153 | INIT_LIST_HEAD(&chunk->trees); |
| 154 | chunk->count = count; |
| 155 | atomic_long_set(&chunk->refs, 1); |
| 156 | for (i = 0; i < count; i++) { |
| 157 | INIT_LIST_HEAD(&chunk->owners[i].list); |
| 158 | chunk->owners[i].index = i; |
| 159 | } |
Jan Kara | 054c636 | 2016-12-21 18:06:12 +0100 | [diff] [blame] | 160 | fsnotify_init_mark(&chunk->mark, audit_tree_group); |
Miklos Szeredi | 799b601 | 2014-11-04 11:27:12 +0100 | [diff] [blame] | 161 | chunk->mark.mask = FS_IN_IGNORED; |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 162 | return chunk; |
| 163 | } |
| 164 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 165 | enum {HASH_SIZE = 128}; |
| 166 | static struct list_head chunk_hash_heads[HASH_SIZE]; |
| 167 | static __cacheline_aligned_in_smp DEFINE_SPINLOCK(hash_lock); |
| 168 | |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 169 | /* Function to return search key in our hash from inode. */ |
| 170 | static unsigned long inode_to_key(const struct inode *inode) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 171 | { |
Amir Goldstein | 36f10f5 | 2018-06-23 17:54:49 +0300 | [diff] [blame] | 172 | /* Use address pointed to by connector->obj as the key */ |
| 173 | return (unsigned long)&inode->i_fsnotify_marks; |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 176 | static inline struct list_head *chunk_hash(unsigned long key) |
| 177 | { |
| 178 | unsigned long n = key / L1_CACHE_BYTES; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 179 | return chunk_hash_heads + n % HASH_SIZE; |
| 180 | } |
| 181 | |
Jan Kara | 9f16d2e | 2018-10-17 12:14:52 +0200 | [diff] [blame] | 182 | /* hash_lock & entry->group->mark_mutex is held by caller */ |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 183 | static void insert_hash(struct audit_chunk *chunk) |
| 184 | { |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 185 | struct list_head *list; |
| 186 | |
Jan Kara | 43471d1 | 2017-04-03 16:47:58 +0200 | [diff] [blame] | 187 | if (!(chunk->mark.flags & FSNOTIFY_MARK_FLAG_ATTACHED)) |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 188 | return; |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 189 | WARN_ON_ONCE(!chunk->key); |
| 190 | list = chunk_hash(chunk->key); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 191 | list_add_rcu(&chunk->hash, list); |
| 192 | } |
| 193 | |
| 194 | /* called under rcu_read_lock */ |
| 195 | struct audit_chunk *audit_tree_lookup(const struct inode *inode) |
| 196 | { |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 197 | unsigned long key = inode_to_key(inode); |
| 198 | struct list_head *list = chunk_hash(key); |
Paul E. McKenney | 6793a05 | 2008-05-14 17:10:12 -0700 | [diff] [blame] | 199 | struct audit_chunk *p; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 200 | |
Paul E. McKenney | 6793a05 | 2008-05-14 17:10:12 -0700 | [diff] [blame] | 201 | list_for_each_entry_rcu(p, list, hash) { |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 202 | if (p->key == key) { |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 203 | atomic_long_inc(&p->refs); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 204 | return p; |
| 205 | } |
| 206 | } |
| 207 | return NULL; |
| 208 | } |
| 209 | |
Yaowei Bai | 6f1b5d7 | 2015-11-04 08:23:51 -0500 | [diff] [blame] | 210 | bool audit_tree_match(struct audit_chunk *chunk, struct audit_tree *tree) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 211 | { |
| 212 | int n; |
| 213 | for (n = 0; n < chunk->count; n++) |
| 214 | if (chunk->owners[n].owner == tree) |
Yaowei Bai | 6f1b5d7 | 2015-11-04 08:23:51 -0500 | [diff] [blame] | 215 | return true; |
| 216 | return false; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /* tagging and untagging inodes with trees */ |
| 220 | |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 221 | static struct audit_chunk *find_chunk(struct node *p) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 222 | { |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 223 | int index = p->index & ~(1U<<31); |
| 224 | p -= index; |
| 225 | return container_of(p, struct audit_chunk, owners[0]); |
| 226 | } |
| 227 | |
| 228 | static void untag_chunk(struct node *p) |
| 229 | { |
| 230 | struct audit_chunk *chunk = find_chunk(p); |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 231 | struct fsnotify_mark *entry = &chunk->mark; |
Al Viro | f7a998a | 2010-10-30 02:18:32 -0400 | [diff] [blame] | 232 | struct audit_chunk *new = NULL; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 233 | struct audit_tree *owner; |
| 234 | int size = chunk->count - 1; |
| 235 | int i, j; |
| 236 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 237 | fsnotify_get_mark(entry); |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 238 | |
| 239 | spin_unlock(&hash_lock); |
| 240 | |
Al Viro | f7a998a | 2010-10-30 02:18:32 -0400 | [diff] [blame] | 241 | if (size) |
| 242 | new = alloc_chunk(size); |
| 243 | |
Jan Kara | be29d20 | 2016-12-14 14:40:05 +0100 | [diff] [blame] | 244 | mutex_lock(&entry->group->mark_mutex); |
Jan Kara | 6b3f05d | 2016-12-21 12:15:30 +0100 | [diff] [blame] | 245 | /* |
| 246 | * mark_mutex protects mark from getting detached and thus also from |
Amir Goldstein | 36f10f5 | 2018-06-23 17:54:49 +0300 | [diff] [blame] | 247 | * mark->connector->obj getting NULL. |
Jan Kara | 6b3f05d | 2016-12-21 12:15:30 +0100 | [diff] [blame] | 248 | */ |
Jan Kara | 43471d1 | 2017-04-03 16:47:58 +0200 | [diff] [blame] | 249 | if (chunk->dead || !(entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { |
Jan Kara | be29d20 | 2016-12-14 14:40:05 +0100 | [diff] [blame] | 250 | mutex_unlock(&entry->group->mark_mutex); |
Al Viro | f7a998a | 2010-10-30 02:18:32 -0400 | [diff] [blame] | 251 | if (new) |
Jan Kara | 7b129323 | 2016-12-21 18:32:48 +0100 | [diff] [blame] | 252 | fsnotify_put_mark(&new->mark); |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 253 | goto out; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | owner = p->owner; |
| 257 | |
| 258 | if (!size) { |
| 259 | chunk->dead = 1; |
| 260 | spin_lock(&hash_lock); |
| 261 | list_del_init(&chunk->trees); |
| 262 | if (owner->root == chunk) |
| 263 | owner->root = NULL; |
| 264 | list_del_init(&p->list); |
| 265 | list_del_rcu(&chunk->hash); |
| 266 | spin_unlock(&hash_lock); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 267 | fsnotify_detach_mark(entry); |
Jan Kara | be29d20 | 2016-12-14 14:40:05 +0100 | [diff] [blame] | 268 | mutex_unlock(&entry->group->mark_mutex); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 269 | fsnotify_free_mark(entry); |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 270 | goto out; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 271 | } |
| 272 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 273 | if (!new) |
| 274 | goto Fallback; |
Al Viro | f7a998a | 2010-10-30 02:18:32 -0400 | [diff] [blame] | 275 | |
Amir Goldstein | 36f10f5 | 2018-06-23 17:54:49 +0300 | [diff] [blame] | 276 | if (fsnotify_add_mark_locked(&new->mark, entry->connector->obj, |
| 277 | FSNOTIFY_OBJ_TYPE_INODE, 1)) { |
Miklos Szeredi | 0fe33aa | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 278 | fsnotify_put_mark(&new->mark); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 279 | goto Fallback; |
| 280 | } |
| 281 | |
| 282 | chunk->dead = 1; |
| 283 | spin_lock(&hash_lock); |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 284 | new->key = chunk->key; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 285 | list_replace_init(&chunk->trees, &new->trees); |
| 286 | if (owner->root == chunk) { |
| 287 | list_del_init(&owner->same_root); |
| 288 | owner->root = NULL; |
| 289 | } |
| 290 | |
Al Viro | 6f5d511 | 2009-12-19 15:59:45 +0000 | [diff] [blame] | 291 | for (i = j = 0; j <= size; i++, j++) { |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 292 | struct audit_tree *s; |
| 293 | if (&chunk->owners[j] == p) { |
| 294 | list_del_init(&p->list); |
| 295 | i--; |
| 296 | continue; |
| 297 | } |
| 298 | s = chunk->owners[j].owner; |
| 299 | new->owners[i].owner = s; |
| 300 | new->owners[i].index = chunk->owners[j].index - j + i; |
| 301 | if (!s) /* result of earlier fallback */ |
| 302 | continue; |
| 303 | get_tree(s); |
Al Viro | 6f5d511 | 2009-12-19 15:59:45 +0000 | [diff] [blame] | 304 | list_replace_init(&chunk->owners[j].list, &new->owners[i].list); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | list_replace_rcu(&chunk->hash, &new->hash); |
| 308 | list_for_each_entry(owner, &new->trees, same_root) |
| 309 | owner->root = new; |
| 310 | spin_unlock(&hash_lock); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 311 | fsnotify_detach_mark(entry); |
Jan Kara | be29d20 | 2016-12-14 14:40:05 +0100 | [diff] [blame] | 312 | mutex_unlock(&entry->group->mark_mutex); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 313 | fsnotify_free_mark(entry); |
Miklos Szeredi | b3e8692 | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 314 | fsnotify_put_mark(&new->mark); /* drop initial reference */ |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 315 | goto out; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 316 | |
| 317 | Fallback: |
| 318 | // do the best we can |
| 319 | spin_lock(&hash_lock); |
| 320 | if (owner->root == chunk) { |
| 321 | list_del_init(&owner->same_root); |
| 322 | owner->root = NULL; |
| 323 | } |
| 324 | list_del_init(&p->list); |
| 325 | p->owner = NULL; |
| 326 | put_tree(owner); |
| 327 | spin_unlock(&hash_lock); |
Jan Kara | be29d20 | 2016-12-14 14:40:05 +0100 | [diff] [blame] | 328 | mutex_unlock(&entry->group->mark_mutex); |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 329 | out: |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 330 | fsnotify_put_mark(entry); |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 331 | spin_lock(&hash_lock); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 334 | /* Call with group->mark_mutex held, releases it */ |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 335 | static int create_chunk(struct inode *inode, struct audit_tree *tree) |
| 336 | { |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 337 | struct fsnotify_mark *entry; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 338 | struct audit_chunk *chunk = alloc_chunk(1); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 339 | |
| 340 | if (!chunk) { |
| 341 | mutex_unlock(&audit_tree_group->mark_mutex); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 342 | return -ENOMEM; |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 343 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 344 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 345 | entry = &chunk->mark; |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 346 | if (fsnotify_add_inode_mark_locked(entry, inode, 0)) { |
| 347 | mutex_unlock(&audit_tree_group->mark_mutex); |
Miklos Szeredi | 0fe33aa | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 348 | fsnotify_put_mark(entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 349 | return -ENOSPC; |
| 350 | } |
| 351 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 352 | spin_lock(&hash_lock); |
| 353 | if (tree->goner) { |
| 354 | spin_unlock(&hash_lock); |
| 355 | chunk->dead = 1; |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 356 | fsnotify_detach_mark(entry); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 357 | mutex_unlock(&audit_tree_group->mark_mutex); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 358 | fsnotify_free_mark(entry); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 359 | fsnotify_put_mark(entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | chunk->owners[0].index = (1U << 31); |
| 363 | chunk->owners[0].owner = tree; |
| 364 | get_tree(tree); |
| 365 | list_add(&chunk->owners[0].list, &tree->chunks); |
| 366 | if (!tree->root) { |
| 367 | tree->root = chunk; |
| 368 | list_add(&tree->same_root, &chunk->trees); |
| 369 | } |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 370 | chunk->key = inode_to_key(inode); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 371 | insert_hash(chunk); |
| 372 | spin_unlock(&hash_lock); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 373 | mutex_unlock(&audit_tree_group->mark_mutex); |
Miklos Szeredi | b3e8692 | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 374 | fsnotify_put_mark(entry); /* drop initial reference */ |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | /* the first tagged inode becomes root of tree */ |
| 379 | static int tag_chunk(struct inode *inode, struct audit_tree *tree) |
| 380 | { |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 381 | struct fsnotify_mark *old_entry, *chunk_entry; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 382 | struct audit_tree *owner; |
| 383 | struct audit_chunk *chunk, *old; |
| 384 | struct node *p; |
| 385 | int n; |
| 386 | |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 387 | mutex_lock(&audit_tree_group->mark_mutex); |
Jan Kara | b1362ed | 2016-12-21 16:28:45 +0100 | [diff] [blame] | 388 | old_entry = fsnotify_find_mark(&inode->i_fsnotify_marks, |
| 389 | audit_tree_group); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 390 | if (!old_entry) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 391 | return create_chunk(inode, tree); |
| 392 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 393 | old = container_of(old_entry, struct audit_chunk, mark); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 394 | |
| 395 | /* are we already there? */ |
| 396 | spin_lock(&hash_lock); |
| 397 | for (n = 0; n < old->count; n++) { |
| 398 | if (old->owners[n].owner == tree) { |
| 399 | spin_unlock(&hash_lock); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 400 | mutex_unlock(&audit_tree_group->mark_mutex); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 401 | fsnotify_put_mark(old_entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 402 | return 0; |
| 403 | } |
| 404 | } |
| 405 | spin_unlock(&hash_lock); |
| 406 | |
| 407 | chunk = alloc_chunk(old->count + 1); |
Al Viro | b4c30aa | 2009-12-19 16:03:30 +0000 | [diff] [blame] | 408 | if (!chunk) { |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 409 | mutex_unlock(&audit_tree_group->mark_mutex); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 410 | fsnotify_put_mark(old_entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 411 | return -ENOMEM; |
Al Viro | b4c30aa | 2009-12-19 16:03:30 +0000 | [diff] [blame] | 412 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 413 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 414 | chunk_entry = &chunk->mark; |
| 415 | |
Jan Kara | 6b3f05d | 2016-12-21 12:15:30 +0100 | [diff] [blame] | 416 | /* |
| 417 | * mark_mutex protects mark from getting detached and thus also from |
Amir Goldstein | 36f10f5 | 2018-06-23 17:54:49 +0300 | [diff] [blame] | 418 | * mark->connector->obj getting NULL. |
Jan Kara | 6b3f05d | 2016-12-21 12:15:30 +0100 | [diff] [blame] | 419 | */ |
Jan Kara | 43471d1 | 2017-04-03 16:47:58 +0200 | [diff] [blame] | 420 | if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) { |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 421 | /* old_entry is being shot, lets just lie */ |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 422 | mutex_unlock(&audit_tree_group->mark_mutex); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 423 | fsnotify_put_mark(old_entry); |
Jan Kara | 7b129323 | 2016-12-21 18:32:48 +0100 | [diff] [blame] | 424 | fsnotify_put_mark(&chunk->mark); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 425 | return -ENOENT; |
| 426 | } |
| 427 | |
Amir Goldstein | 36f10f5 | 2018-06-23 17:54:49 +0300 | [diff] [blame] | 428 | if (fsnotify_add_mark_locked(chunk_entry, old_entry->connector->obj, |
| 429 | FSNOTIFY_OBJ_TYPE_INODE, 1)) { |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 430 | mutex_unlock(&audit_tree_group->mark_mutex); |
Miklos Szeredi | 0fe33aa | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 431 | fsnotify_put_mark(chunk_entry); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 432 | fsnotify_put_mark(old_entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 433 | return -ENOSPC; |
| 434 | } |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 435 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 436 | spin_lock(&hash_lock); |
| 437 | if (tree->goner) { |
| 438 | spin_unlock(&hash_lock); |
| 439 | chunk->dead = 1; |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 440 | fsnotify_detach_mark(chunk_entry); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 441 | mutex_unlock(&audit_tree_group->mark_mutex); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 442 | fsnotify_free_mark(chunk_entry); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 443 | fsnotify_put_mark(chunk_entry); |
| 444 | fsnotify_put_mark(old_entry); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 445 | return 0; |
| 446 | } |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 447 | chunk->key = old->key; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 448 | list_replace_init(&old->trees, &chunk->trees); |
| 449 | for (n = 0, p = chunk->owners; n < old->count; n++, p++) { |
| 450 | struct audit_tree *s = old->owners[n].owner; |
| 451 | p->owner = s; |
| 452 | p->index = old->owners[n].index; |
| 453 | if (!s) /* result of fallback in untag */ |
| 454 | continue; |
| 455 | get_tree(s); |
| 456 | list_replace_init(&old->owners[n].list, &p->list); |
| 457 | } |
| 458 | p->index = (chunk->count - 1) | (1U<<31); |
| 459 | p->owner = tree; |
| 460 | get_tree(tree); |
| 461 | list_add(&p->list, &tree->chunks); |
| 462 | list_replace_rcu(&old->hash, &chunk->hash); |
| 463 | list_for_each_entry(owner, &chunk->trees, same_root) |
| 464 | owner->root = chunk; |
| 465 | old->dead = 1; |
| 466 | if (!tree->root) { |
| 467 | tree->root = chunk; |
| 468 | list_add(&tree->same_root, &chunk->trees); |
| 469 | } |
| 470 | spin_unlock(&hash_lock); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 471 | fsnotify_detach_mark(old_entry); |
Jan Kara | a5789b0 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 472 | mutex_unlock(&audit_tree_group->mark_mutex); |
Jan Kara | b1e4603 | 2018-11-12 09:54:48 -0500 | [diff] [blame] | 473 | fsnotify_free_mark(old_entry); |
Miklos Szeredi | b3e8692 | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 474 | fsnotify_put_mark(chunk_entry); /* drop initial reference */ |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 475 | fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */ |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
Richard Guy Briggs | 2991dd2 | 2014-10-02 22:05:24 -0400 | [diff] [blame] | 479 | static void audit_tree_log_remove_rule(struct audit_krule *rule) |
Kees Cook | 0644ec0 | 2013-01-11 14:32:07 -0800 | [diff] [blame] | 480 | { |
| 481 | struct audit_buffer *ab; |
| 482 | |
Richard Guy Briggs | 65a8766 | 2018-06-14 16:20:05 -0400 | [diff] [blame] | 483 | if (!audit_enabled) |
| 484 | return; |
Kees Cook | 0644ec0 | 2013-01-11 14:32:07 -0800 | [diff] [blame] | 485 | ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE); |
| 486 | if (unlikely(!ab)) |
| 487 | return; |
Steve Grubb | c1e8f06 | 2016-11-16 16:14:33 -0500 | [diff] [blame] | 488 | audit_log_format(ab, "op=remove_rule"); |
Kees Cook | 0644ec0 | 2013-01-11 14:32:07 -0800 | [diff] [blame] | 489 | audit_log_format(ab, " dir="); |
| 490 | audit_log_untrustedstring(ab, rule->tree->pathname); |
| 491 | audit_log_key(ab, rule->filterkey); |
| 492 | audit_log_format(ab, " list=%d res=1", rule->listnr); |
| 493 | audit_log_end(ab); |
| 494 | } |
| 495 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 496 | static void kill_rules(struct audit_tree *tree) |
| 497 | { |
| 498 | struct audit_krule *rule, *next; |
| 499 | struct audit_entry *entry; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 500 | |
| 501 | list_for_each_entry_safe(rule, next, &tree->rules, rlist) { |
| 502 | entry = container_of(rule, struct audit_entry, rule); |
| 503 | |
| 504 | list_del_init(&rule->rlist); |
| 505 | if (rule->tree) { |
| 506 | /* not a half-baked one */ |
Richard Guy Briggs | 2991dd2 | 2014-10-02 22:05:24 -0400 | [diff] [blame] | 507 | audit_tree_log_remove_rule(rule); |
Richard Guy Briggs | 34d99af5 | 2015-08-05 16:29:37 -0400 | [diff] [blame] | 508 | if (entry->rule.exe) |
| 509 | audit_remove_mark(entry->rule.exe); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 510 | rule->tree = NULL; |
| 511 | list_del_rcu(&entry->list); |
Al Viro | e45aa21 | 2008-12-15 01:17:50 -0500 | [diff] [blame] | 512 | list_del(&entry->rule.list); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 513 | call_rcu(&entry->rcu, audit_free_rule_rcu); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | /* |
| 519 | * finish killing struct audit_tree |
| 520 | */ |
| 521 | static void prune_one(struct audit_tree *victim) |
| 522 | { |
| 523 | spin_lock(&hash_lock); |
| 524 | while (!list_empty(&victim->chunks)) { |
| 525 | struct node *p; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 526 | |
| 527 | p = list_entry(victim->chunks.next, struct node, list); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 528 | |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 529 | untag_chunk(p); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 530 | } |
| 531 | spin_unlock(&hash_lock); |
| 532 | put_tree(victim); |
| 533 | } |
| 534 | |
| 535 | /* trim the uncommitted chunks from tree */ |
| 536 | |
| 537 | static void trim_marked(struct audit_tree *tree) |
| 538 | { |
| 539 | struct list_head *p, *q; |
| 540 | spin_lock(&hash_lock); |
| 541 | if (tree->goner) { |
| 542 | spin_unlock(&hash_lock); |
| 543 | return; |
| 544 | } |
| 545 | /* reorder */ |
| 546 | for (p = tree->chunks.next; p != &tree->chunks; p = q) { |
| 547 | struct node *node = list_entry(p, struct node, list); |
| 548 | q = p->next; |
| 549 | if (node->index & (1U<<31)) { |
| 550 | list_del_init(p); |
| 551 | list_add(p, &tree->chunks); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | while (!list_empty(&tree->chunks)) { |
| 556 | struct node *node; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 557 | |
| 558 | node = list_entry(tree->chunks.next, struct node, list); |
| 559 | |
| 560 | /* have we run out of marked? */ |
| 561 | if (!(node->index & (1U<<31))) |
| 562 | break; |
| 563 | |
Al Viro | 8f7b0ba | 2008-11-15 01:15:43 +0000 | [diff] [blame] | 564 | untag_chunk(node); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 565 | } |
| 566 | if (!tree->root && !tree->goner) { |
| 567 | tree->goner = 1; |
| 568 | spin_unlock(&hash_lock); |
| 569 | mutex_lock(&audit_filter_mutex); |
| 570 | kill_rules(tree); |
| 571 | list_del_init(&tree->list); |
| 572 | mutex_unlock(&audit_filter_mutex); |
| 573 | prune_one(tree); |
| 574 | } else { |
| 575 | spin_unlock(&hash_lock); |
| 576 | } |
| 577 | } |
| 578 | |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 579 | static void audit_schedule_prune(void); |
| 580 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 581 | /* called with audit_filter_mutex */ |
| 582 | int audit_remove_tree_rule(struct audit_krule *rule) |
| 583 | { |
| 584 | struct audit_tree *tree; |
| 585 | tree = rule->tree; |
| 586 | if (tree) { |
| 587 | spin_lock(&hash_lock); |
| 588 | list_del_init(&rule->rlist); |
| 589 | if (list_empty(&tree->rules) && !tree->goner) { |
| 590 | tree->root = NULL; |
| 591 | list_del_init(&tree->same_root); |
| 592 | tree->goner = 1; |
| 593 | list_move(&tree->list, &prune_list); |
| 594 | rule->tree = NULL; |
| 595 | spin_unlock(&hash_lock); |
| 596 | audit_schedule_prune(); |
| 597 | return 1; |
| 598 | } |
| 599 | rule->tree = NULL; |
| 600 | spin_unlock(&hash_lock); |
| 601 | return 1; |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 606 | static int compare_root(struct vfsmount *mnt, void *arg) |
| 607 | { |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 608 | return inode_to_key(d_backing_inode(mnt->mnt_root)) == |
| 609 | (unsigned long)arg; |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 610 | } |
| 611 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 612 | void audit_trim_trees(void) |
| 613 | { |
| 614 | struct list_head cursor; |
| 615 | |
| 616 | mutex_lock(&audit_filter_mutex); |
| 617 | list_add(&cursor, &tree_list); |
| 618 | while (cursor.next != &tree_list) { |
| 619 | struct audit_tree *tree; |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 620 | struct path path; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 621 | struct vfsmount *root_mnt; |
| 622 | struct node *node; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 623 | int err; |
| 624 | |
| 625 | tree = container_of(cursor.next, struct audit_tree, list); |
| 626 | get_tree(tree); |
| 627 | list_del(&cursor); |
| 628 | list_add(&cursor, &tree->list); |
| 629 | mutex_unlock(&audit_filter_mutex); |
| 630 | |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 631 | err = kern_path(tree->pathname, 0, &path); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 632 | if (err) |
| 633 | goto skip_it; |
| 634 | |
Al Viro | 589ff87 | 2009-04-18 03:28:19 -0400 | [diff] [blame] | 635 | root_mnt = collect_mounts(&path); |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 636 | path_put(&path); |
David Howells | be34d1a | 2012-06-25 12:55:18 +0100 | [diff] [blame] | 637 | if (IS_ERR(root_mnt)) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 638 | goto skip_it; |
| 639 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 640 | spin_lock(&hash_lock); |
| 641 | list_for_each_entry(node, &tree->chunks, list) { |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 642 | struct audit_chunk *chunk = find_chunk(node); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 643 | /* this could be NULL if the watch is dying else where... */ |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 644 | node->index |= 1U<<31; |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 645 | if (iterate_mounts(compare_root, |
Jan Kara | 8d20d6e | 2018-11-12 09:54:48 -0500 | [diff] [blame^] | 646 | (void *)(chunk->key), |
Jan Kara | f410ff6 | 2016-12-16 10:13:37 +0100 | [diff] [blame] | 647 | root_mnt)) |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 648 | node->index &= ~(1U<<31); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 649 | } |
| 650 | spin_unlock(&hash_lock); |
| 651 | trim_marked(tree); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 652 | drop_collected_mounts(root_mnt); |
| 653 | skip_it: |
Chen Gang | 12b2f11 | 2013-04-29 15:05:19 -0700 | [diff] [blame] | 654 | put_tree(tree); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 655 | mutex_lock(&audit_filter_mutex); |
| 656 | } |
| 657 | list_del(&cursor); |
| 658 | mutex_unlock(&audit_filter_mutex); |
| 659 | } |
| 660 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 661 | int audit_make_tree(struct audit_krule *rule, char *pathname, u32 op) |
| 662 | { |
| 663 | |
| 664 | if (pathname[0] != '/' || |
| 665 | rule->listnr != AUDIT_FILTER_EXIT || |
Al Viro | 5af75d8 | 2008-12-16 05:59:26 -0500 | [diff] [blame] | 666 | op != Audit_equal || |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 667 | rule->inode_f || rule->watch || rule->tree) |
| 668 | return -EINVAL; |
| 669 | rule->tree = alloc_tree(pathname); |
| 670 | if (!rule->tree) |
| 671 | return -ENOMEM; |
| 672 | return 0; |
| 673 | } |
| 674 | |
| 675 | void audit_put_tree(struct audit_tree *tree) |
| 676 | { |
| 677 | put_tree(tree); |
| 678 | } |
| 679 | |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 680 | static int tag_mount(struct vfsmount *mnt, void *arg) |
| 681 | { |
David Howells | 3b36215 | 2015-03-17 22:26:21 +0000 | [diff] [blame] | 682 | return tag_chunk(d_backing_inode(mnt->mnt_root), arg); |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 683 | } |
| 684 | |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 685 | /* |
| 686 | * That gets run when evict_chunk() ends up needing to kill audit_tree. |
| 687 | * Runs from a separate thread. |
| 688 | */ |
| 689 | static int prune_tree_thread(void *unused) |
| 690 | { |
| 691 | for (;;) { |
Jiri Slaby | 0bf676d | 2016-03-31 10:49:28 +0200 | [diff] [blame] | 692 | if (list_empty(&prune_list)) { |
| 693 | set_current_state(TASK_INTERRUPTIBLE); |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 694 | schedule(); |
Jiri Slaby | 0bf676d | 2016-03-31 10:49:28 +0200 | [diff] [blame] | 695 | } |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 696 | |
Paul Moore | ce42363 | 2018-02-20 09:52:38 -0500 | [diff] [blame] | 697 | audit_ctl_lock(); |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 698 | mutex_lock(&audit_filter_mutex); |
| 699 | |
| 700 | while (!list_empty(&prune_list)) { |
| 701 | struct audit_tree *victim; |
| 702 | |
| 703 | victim = list_entry(prune_list.next, |
| 704 | struct audit_tree, list); |
| 705 | list_del_init(&victim->list); |
| 706 | |
| 707 | mutex_unlock(&audit_filter_mutex); |
| 708 | |
| 709 | prune_one(victim); |
| 710 | |
| 711 | mutex_lock(&audit_filter_mutex); |
| 712 | } |
| 713 | |
| 714 | mutex_unlock(&audit_filter_mutex); |
Paul Moore | ce42363 | 2018-02-20 09:52:38 -0500 | [diff] [blame] | 715 | audit_ctl_unlock(); |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 716 | } |
| 717 | return 0; |
| 718 | } |
| 719 | |
| 720 | static int audit_launch_prune(void) |
| 721 | { |
| 722 | if (prune_thread) |
| 723 | return 0; |
Jiri Slaby | 0bf676d | 2016-03-31 10:49:28 +0200 | [diff] [blame] | 724 | prune_thread = kthread_run(prune_tree_thread, NULL, |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 725 | "audit_prune_tree"); |
| 726 | if (IS_ERR(prune_thread)) { |
| 727 | pr_err("cannot start thread audit_prune_tree"); |
| 728 | prune_thread = NULL; |
| 729 | return -ENOMEM; |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 730 | } |
Jiri Slaby | 0bf676d | 2016-03-31 10:49:28 +0200 | [diff] [blame] | 731 | return 0; |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 732 | } |
| 733 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 734 | /* called with audit_filter_mutex */ |
| 735 | int audit_add_tree_rule(struct audit_krule *rule) |
| 736 | { |
| 737 | struct audit_tree *seed = rule->tree, *tree; |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 738 | struct path path; |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 739 | struct vfsmount *mnt; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 740 | int err; |
| 741 | |
Chen Gang | 736f320 | 2013-06-12 14:05:07 -0700 | [diff] [blame] | 742 | rule->tree = NULL; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 743 | list_for_each_entry(tree, &tree_list, list) { |
| 744 | if (!strcmp(seed->pathname, tree->pathname)) { |
| 745 | put_tree(seed); |
| 746 | rule->tree = tree; |
| 747 | list_add(&rule->rlist, &tree->rules); |
| 748 | return 0; |
| 749 | } |
| 750 | } |
| 751 | tree = seed; |
| 752 | list_add(&tree->list, &tree_list); |
| 753 | list_add(&rule->rlist, &tree->rules); |
| 754 | /* do not set rule->tree yet */ |
| 755 | mutex_unlock(&audit_filter_mutex); |
| 756 | |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 757 | if (unlikely(!prune_thread)) { |
| 758 | err = audit_launch_prune(); |
| 759 | if (err) |
| 760 | goto Err; |
| 761 | } |
| 762 | |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 763 | err = kern_path(tree->pathname, 0, &path); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 764 | if (err) |
| 765 | goto Err; |
Al Viro | 589ff87 | 2009-04-18 03:28:19 -0400 | [diff] [blame] | 766 | mnt = collect_mounts(&path); |
Al Viro | 98bc993 | 2008-08-02 01:06:21 -0400 | [diff] [blame] | 767 | path_put(&path); |
David Howells | be34d1a | 2012-06-25 12:55:18 +0100 | [diff] [blame] | 768 | if (IS_ERR(mnt)) { |
| 769 | err = PTR_ERR(mnt); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 770 | goto Err; |
| 771 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 772 | |
| 773 | get_tree(tree); |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 774 | err = iterate_mounts(tag_mount, tree, mnt); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 775 | drop_collected_mounts(mnt); |
| 776 | |
| 777 | if (!err) { |
| 778 | struct node *node; |
| 779 | spin_lock(&hash_lock); |
| 780 | list_for_each_entry(node, &tree->chunks, list) |
| 781 | node->index &= ~(1U<<31); |
| 782 | spin_unlock(&hash_lock); |
| 783 | } else { |
| 784 | trim_marked(tree); |
| 785 | goto Err; |
| 786 | } |
| 787 | |
| 788 | mutex_lock(&audit_filter_mutex); |
| 789 | if (list_empty(&rule->rlist)) { |
| 790 | put_tree(tree); |
| 791 | return -ENOENT; |
| 792 | } |
| 793 | rule->tree = tree; |
| 794 | put_tree(tree); |
| 795 | |
| 796 | return 0; |
| 797 | Err: |
| 798 | mutex_lock(&audit_filter_mutex); |
| 799 | list_del_init(&tree->list); |
| 800 | list_del_init(&tree->rules); |
| 801 | put_tree(tree); |
| 802 | return err; |
| 803 | } |
| 804 | |
| 805 | int audit_tag_tree(char *old, char *new) |
| 806 | { |
| 807 | struct list_head cursor, barrier; |
| 808 | int failed = 0; |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 809 | struct path path1, path2; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 810 | struct vfsmount *tagged; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 811 | int err; |
| 812 | |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 813 | err = kern_path(new, 0, &path2); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 814 | if (err) |
| 815 | return err; |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 816 | tagged = collect_mounts(&path2); |
| 817 | path_put(&path2); |
David Howells | be34d1a | 2012-06-25 12:55:18 +0100 | [diff] [blame] | 818 | if (IS_ERR(tagged)) |
| 819 | return PTR_ERR(tagged); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 820 | |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 821 | err = kern_path(old, 0, &path1); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 822 | if (err) { |
| 823 | drop_collected_mounts(tagged); |
| 824 | return err; |
| 825 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 826 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 827 | mutex_lock(&audit_filter_mutex); |
| 828 | list_add(&barrier, &tree_list); |
| 829 | list_add(&cursor, &barrier); |
| 830 | |
| 831 | while (cursor.next != &tree_list) { |
| 832 | struct audit_tree *tree; |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 833 | int good_one = 0; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 834 | |
| 835 | tree = container_of(cursor.next, struct audit_tree, list); |
| 836 | get_tree(tree); |
| 837 | list_del(&cursor); |
| 838 | list_add(&cursor, &tree->list); |
| 839 | mutex_unlock(&audit_filter_mutex); |
| 840 | |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 841 | err = kern_path(tree->pathname, 0, &path2); |
| 842 | if (!err) { |
| 843 | good_one = path_is_under(&path1, &path2); |
| 844 | path_put(&path2); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 845 | } |
| 846 | |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 847 | if (!good_one) { |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 848 | put_tree(tree); |
| 849 | mutex_lock(&audit_filter_mutex); |
| 850 | continue; |
| 851 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 852 | |
Al Viro | 1f70713 | 2010-01-30 22:51:25 -0500 | [diff] [blame] | 853 | failed = iterate_mounts(tag_mount, tree, tagged); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 854 | if (failed) { |
| 855 | put_tree(tree); |
| 856 | mutex_lock(&audit_filter_mutex); |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | mutex_lock(&audit_filter_mutex); |
| 861 | spin_lock(&hash_lock); |
| 862 | if (!tree->goner) { |
| 863 | list_del(&tree->list); |
| 864 | list_add(&tree->list, &tree_list); |
| 865 | } |
| 866 | spin_unlock(&hash_lock); |
| 867 | put_tree(tree); |
| 868 | } |
| 869 | |
| 870 | while (barrier.prev != &tree_list) { |
| 871 | struct audit_tree *tree; |
| 872 | |
| 873 | tree = container_of(barrier.prev, struct audit_tree, list); |
| 874 | get_tree(tree); |
| 875 | list_del(&tree->list); |
| 876 | list_add(&tree->list, &barrier); |
| 877 | mutex_unlock(&audit_filter_mutex); |
| 878 | |
| 879 | if (!failed) { |
| 880 | struct node *node; |
| 881 | spin_lock(&hash_lock); |
| 882 | list_for_each_entry(node, &tree->chunks, list) |
| 883 | node->index &= ~(1U<<31); |
| 884 | spin_unlock(&hash_lock); |
| 885 | } else { |
| 886 | trim_marked(tree); |
| 887 | } |
| 888 | |
| 889 | put_tree(tree); |
| 890 | mutex_lock(&audit_filter_mutex); |
| 891 | } |
| 892 | list_del(&barrier); |
| 893 | list_del(&cursor); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 894 | mutex_unlock(&audit_filter_mutex); |
Al Viro | 2096f75 | 2010-01-30 13:16:21 -0500 | [diff] [blame] | 895 | path_put(&path1); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 896 | drop_collected_mounts(tagged); |
| 897 | return failed; |
| 898 | } |
| 899 | |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 900 | |
| 901 | static void audit_schedule_prune(void) |
| 902 | { |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 903 | wake_up_process(prune_thread); |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | /* |
| 907 | * ... and that one is done if evict_chunk() decides to delay until the end |
| 908 | * of syscall. Runs synchronously. |
| 909 | */ |
| 910 | void audit_kill_trees(struct list_head *list) |
| 911 | { |
Paul Moore | ce42363 | 2018-02-20 09:52:38 -0500 | [diff] [blame] | 912 | audit_ctl_lock(); |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 913 | mutex_lock(&audit_filter_mutex); |
| 914 | |
| 915 | while (!list_empty(list)) { |
| 916 | struct audit_tree *victim; |
| 917 | |
| 918 | victim = list_entry(list->next, struct audit_tree, list); |
| 919 | kill_rules(victim); |
| 920 | list_del_init(&victim->list); |
| 921 | |
| 922 | mutex_unlock(&audit_filter_mutex); |
| 923 | |
| 924 | prune_one(victim); |
| 925 | |
| 926 | mutex_lock(&audit_filter_mutex); |
| 927 | } |
| 928 | |
| 929 | mutex_unlock(&audit_filter_mutex); |
Paul Moore | ce42363 | 2018-02-20 09:52:38 -0500 | [diff] [blame] | 930 | audit_ctl_unlock(); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* |
| 934 | * Here comes the stuff asynchronous to auditctl operations |
| 935 | */ |
| 936 | |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 937 | static void evict_chunk(struct audit_chunk *chunk) |
| 938 | { |
| 939 | struct audit_tree *owner; |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 940 | struct list_head *postponed = audit_killed_trees(); |
| 941 | int need_prune = 0; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 942 | int n; |
| 943 | |
| 944 | if (chunk->dead) |
| 945 | return; |
| 946 | |
| 947 | chunk->dead = 1; |
| 948 | mutex_lock(&audit_filter_mutex); |
| 949 | spin_lock(&hash_lock); |
| 950 | while (!list_empty(&chunk->trees)) { |
| 951 | owner = list_entry(chunk->trees.next, |
| 952 | struct audit_tree, same_root); |
| 953 | owner->goner = 1; |
| 954 | owner->root = NULL; |
| 955 | list_del_init(&owner->same_root); |
| 956 | spin_unlock(&hash_lock); |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 957 | if (!postponed) { |
| 958 | kill_rules(owner); |
| 959 | list_move(&owner->list, &prune_list); |
| 960 | need_prune = 1; |
| 961 | } else { |
| 962 | list_move(&owner->list, postponed); |
| 963 | } |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 964 | spin_lock(&hash_lock); |
| 965 | } |
| 966 | list_del_rcu(&chunk->hash); |
| 967 | for (n = 0; n < chunk->count; n++) |
| 968 | list_del_init(&chunk->owners[n].list); |
| 969 | spin_unlock(&hash_lock); |
Imre Palik | f1aaf26 | 2015-02-23 15:37:59 -0500 | [diff] [blame] | 970 | mutex_unlock(&audit_filter_mutex); |
Al Viro | 916d757 | 2009-06-24 00:02:38 -0400 | [diff] [blame] | 971 | if (need_prune) |
| 972 | audit_schedule_prune(); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 973 | } |
| 974 | |
Eric Paris | 3a9b16b | 2010-07-28 10:18:38 -0400 | [diff] [blame] | 975 | static int audit_tree_handle_event(struct fsnotify_group *group, |
Jan Kara | 7053aee | 2014-01-21 15:48:14 -0800 | [diff] [blame] | 976 | struct inode *to_tell, |
Al Viro | 3cd5eca | 2016-11-20 20:19:09 -0500 | [diff] [blame] | 977 | u32 mask, const void *data, int data_type, |
Jan Kara | 9385a84 | 2016-11-10 17:51:50 +0100 | [diff] [blame] | 978 | const unsigned char *file_name, u32 cookie, |
| 979 | struct fsnotify_iter_info *iter_info) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 980 | { |
Jan Kara | 83c4c4b | 2014-01-21 15:48:15 -0800 | [diff] [blame] | 981 | return 0; |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 982 | } |
| 983 | |
Eric Paris | e61ce86 | 2009-12-17 21:24:24 -0500 | [diff] [blame] | 984 | static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify_group *group) |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 985 | { |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 986 | struct audit_chunk *chunk = container_of(entry, struct audit_chunk, mark); |
| 987 | |
| 988 | evict_chunk(chunk); |
Miklos Szeredi | b3e8692 | 2012-08-15 12:55:22 +0200 | [diff] [blame] | 989 | |
| 990 | /* |
| 991 | * We are guaranteed to have at least one reference to the mark from |
| 992 | * either the inode or the caller of fsnotify_destroy_mark(). |
| 993 | */ |
Elena Reshetova | ab97f873 | 2017-10-20 13:26:02 +0300 | [diff] [blame] | 994 | BUG_ON(refcount_read(&entry->refcnt) < 1); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 995 | } |
| 996 | |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 997 | static const struct fsnotify_ops audit_tree_ops = { |
| 998 | .handle_event = audit_tree_handle_event, |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 999 | .freeing_mark = audit_tree_freeing_mark, |
Jan Kara | 054c636 | 2016-12-21 18:06:12 +0100 | [diff] [blame] | 1000 | .free_mark = audit_tree_destroy_watch, |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1001 | }; |
| 1002 | |
| 1003 | static int __init audit_tree_init(void) |
| 1004 | { |
| 1005 | int i; |
| 1006 | |
Eric Paris | 0d2e2a1 | 2009-12-17 21:24:22 -0500 | [diff] [blame] | 1007 | audit_tree_group = fsnotify_alloc_group(&audit_tree_ops); |
Eric Paris | 28a3a7e | 2009-12-17 20:12:05 -0500 | [diff] [blame] | 1008 | if (IS_ERR(audit_tree_group)) |
| 1009 | audit_panic("cannot initialize fsnotify group for rectree watches"); |
Al Viro | 74c3cbe | 2007-07-22 08:04:18 -0400 | [diff] [blame] | 1010 | |
| 1011 | for (i = 0; i < HASH_SIZE; i++) |
| 1012 | INIT_LIST_HEAD(&chunk_hash_heads[i]); |
| 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | __initcall(audit_tree_init); |