audit_tree.c (57b54d74dd5c559bd35f2affaf11d8828aaf5733) audit_tree.c (36f10f55ff1d2867bfc48ed898a9cc0dc6b49dd2)
1// SPDX-License-Identifier: GPL-2.0
2#include "audit.h"
3#include <linux/fsnotify_backend.h>
4#include <linux/namei.h>
5#include <linux/mount.h>
6#include <linux/kthread.h>
7#include <linux/refcount.h>
8#include <linux/slab.h>

--- 154 unchanged lines hidden (view full) ---

163
164enum {HASH_SIZE = 128};
165static struct list_head chunk_hash_heads[HASH_SIZE];
166static __cacheline_aligned_in_smp DEFINE_SPINLOCK(hash_lock);
167
168/* Function to return search key in our hash from inode. */
169static unsigned long inode_to_key(const struct inode *inode)
170{
1// SPDX-License-Identifier: GPL-2.0
2#include "audit.h"
3#include <linux/fsnotify_backend.h>
4#include <linux/namei.h>
5#include <linux/mount.h>
6#include <linux/kthread.h>
7#include <linux/refcount.h>
8#include <linux/slab.h>

--- 154 unchanged lines hidden (view full) ---

163
164enum {HASH_SIZE = 128};
165static struct list_head chunk_hash_heads[HASH_SIZE];
166static __cacheline_aligned_in_smp DEFINE_SPINLOCK(hash_lock);
167
168/* Function to return search key in our hash from inode. */
169static unsigned long inode_to_key(const struct inode *inode)
170{
171 return (unsigned long)inode;
171 /* Use address pointed to by connector->obj as the key */
172 return (unsigned long)&inode->i_fsnotify_marks;
172}
173
174/*
175 * Function to return search key in our hash from chunk. Key 0 is special and
176 * should never be present in the hash.
177 */
178static unsigned long chunk_to_key(struct audit_chunk *chunk)
179{
180 /*
181 * We have a reference to the mark so it should be attached to a
182 * connector.
183 */
184 if (WARN_ON_ONCE(!chunk->mark.connector))
185 return 0;
173}
174
175/*
176 * Function to return search key in our hash from chunk. Key 0 is special and
177 * should never be present in the hash.
178 */
179static unsigned long chunk_to_key(struct audit_chunk *chunk)
180{
181 /*
182 * We have a reference to the mark so it should be attached to a
183 * connector.
184 */
185 if (WARN_ON_ONCE(!chunk->mark.connector))
186 return 0;
186 return (unsigned long)chunk->mark.connector->inode;
187 return (unsigned long)chunk->mark.connector->obj;
187}
188
189static inline struct list_head *chunk_hash(unsigned long key)
190{
191 unsigned long n = key / L1_CACHE_BYTES;
192 return chunk_hash_heads + n % HASH_SIZE;
193}
194

--- 58 unchanged lines hidden (view full) ---

253
254 if (size)
255 new = alloc_chunk(size);
256
257 mutex_lock(&entry->group->mark_mutex);
258 spin_lock(&entry->lock);
259 /*
260 * mark_mutex protects mark from getting detached and thus also from
188}
189
190static inline struct list_head *chunk_hash(unsigned long key)
191{
192 unsigned long n = key / L1_CACHE_BYTES;
193 return chunk_hash_heads + n % HASH_SIZE;
194}
195

--- 58 unchanged lines hidden (view full) ---

254
255 if (size)
256 new = alloc_chunk(size);
257
258 mutex_lock(&entry->group->mark_mutex);
259 spin_lock(&entry->lock);
260 /*
261 * mark_mutex protects mark from getting detached and thus also from
261 * mark->connector->inode getting NULL.
262 * mark->connector->obj getting NULL.
262 */
263 if (chunk->dead || !(entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) {
264 spin_unlock(&entry->lock);
265 mutex_unlock(&entry->group->mark_mutex);
266 if (new)
267 fsnotify_put_mark(&new->mark);
268 goto out;
269 }

--- 13 unchanged lines hidden (view full) ---

283 mutex_unlock(&entry->group->mark_mutex);
284 fsnotify_destroy_mark(entry, audit_tree_group);
285 goto out;
286 }
287
288 if (!new)
289 goto Fallback;
290
263 */
264 if (chunk->dead || !(entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) {
265 spin_unlock(&entry->lock);
266 mutex_unlock(&entry->group->mark_mutex);
267 if (new)
268 fsnotify_put_mark(&new->mark);
269 goto out;
270 }

--- 13 unchanged lines hidden (view full) ---

284 mutex_unlock(&entry->group->mark_mutex);
285 fsnotify_destroy_mark(entry, audit_tree_group);
286 goto out;
287 }
288
289 if (!new)
290 goto Fallback;
291
291 if (fsnotify_add_inode_mark_locked(&new->mark, entry->connector->inode,
292 1)) {
292 if (fsnotify_add_mark_locked(&new->mark, entry->connector->obj,
293 FSNOTIFY_OBJ_TYPE_INODE, 1)) {
293 fsnotify_put_mark(&new->mark);
294 goto Fallback;
295 }
296
297 chunk->dead = 1;
298 spin_lock(&hash_lock);
299 list_replace_init(&chunk->trees, &new->trees);
300 if (owner->root == chunk) {

--- 117 unchanged lines hidden (view full) ---

418 }
419
420 chunk_entry = &chunk->mark;
421
422 mutex_lock(&old_entry->group->mark_mutex);
423 spin_lock(&old_entry->lock);
424 /*
425 * mark_mutex protects mark from getting detached and thus also from
294 fsnotify_put_mark(&new->mark);
295 goto Fallback;
296 }
297
298 chunk->dead = 1;
299 spin_lock(&hash_lock);
300 list_replace_init(&chunk->trees, &new->trees);
301 if (owner->root == chunk) {

--- 117 unchanged lines hidden (view full) ---

419 }
420
421 chunk_entry = &chunk->mark;
422
423 mutex_lock(&old_entry->group->mark_mutex);
424 spin_lock(&old_entry->lock);
425 /*
426 * mark_mutex protects mark from getting detached and thus also from
426 * mark->connector->inode getting NULL.
427 * mark->connector->obj getting NULL.
427 */
428 if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) {
429 /* old_entry is being shot, lets just lie */
430 spin_unlock(&old_entry->lock);
431 mutex_unlock(&old_entry->group->mark_mutex);
432 fsnotify_put_mark(old_entry);
433 fsnotify_put_mark(&chunk->mark);
434 return -ENOENT;
435 }
436
428 */
429 if (!(old_entry->flags & FSNOTIFY_MARK_FLAG_ATTACHED)) {
430 /* old_entry is being shot, lets just lie */
431 spin_unlock(&old_entry->lock);
432 mutex_unlock(&old_entry->group->mark_mutex);
433 fsnotify_put_mark(old_entry);
434 fsnotify_put_mark(&chunk->mark);
435 return -ENOENT;
436 }
437
437 if (fsnotify_add_inode_mark_locked(chunk_entry,
438 old_entry->connector->inode, 1)) {
438 if (fsnotify_add_mark_locked(chunk_entry, old_entry->connector->obj,
439 FSNOTIFY_OBJ_TYPE_INODE, 1)) {
439 spin_unlock(&old_entry->lock);
440 mutex_unlock(&old_entry->group->mark_mutex);
441 fsnotify_put_mark(chunk_entry);
442 fsnotify_put_mark(old_entry);
443 return -ENOSPC;
444 }
445
446 /* even though we hold old_entry->lock, this is safe since chunk_entry->lock could NEVER have been grabbed before */

--- 585 unchanged lines hidden ---
440 spin_unlock(&old_entry->lock);
441 mutex_unlock(&old_entry->group->mark_mutex);
442 fsnotify_put_mark(chunk_entry);
443 fsnotify_put_mark(old_entry);
444 return -ENOSPC;
445 }
446
447 /* even though we hold old_entry->lock, this is safe since chunk_entry->lock could NEVER have been grabbed before */

--- 585 unchanged lines hidden ---