Skip to content

Commit 49a4ee7

Browse files
jankarapcmoore
authored andcommitted
audit: Guarantee forward progress of chunk untagging
When removing chunk from a tree, we do shrink the chunk. This can fail for various reasons (due to races, ENOMEM, etc.) and in some cases we just bail from untag_chunk() relying on someone else to cleanup. Although this currently works, later we will need to add new failure situation which would break. Also this simplifies the code and will allow us to make locking around untag_chunk() less awkward. Signed-off-by: Jan Kara <jack@suse.cz> Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent 5f51613 commit 49a4ee7

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

‎kernel/audit_tree.c‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,28 @@ static void replace_chunk(struct audit_chunk *new, struct audit_chunk *old,
309309
list_replace_rcu(&old->hash, &new->hash);
310310
}
311311

312+
static void remove_chunk_node(struct audit_chunk *chunk, struct node *p)
313+
{
314+
struct audit_tree *owner = p->owner;
315+
316+
if (owner->root == chunk) {
317+
list_del_init(&owner->same_root);
318+
owner->root = NULL;
319+
}
320+
list_del_init(&p->list);
321+
p->owner = NULL;
322+
put_tree(owner);
323+
}
324+
312325
static void untag_chunk(struct node *p)
313326
{
314327
struct audit_chunk *chunk = find_chunk(p);
315328
struct fsnotify_mark *entry = chunk->mark;
316329
struct audit_chunk *new = NULL;
317-
struct audit_tree *owner;
318330
int size = chunk->count - 1;
319331

332+
remove_chunk_node(chunk, p);
320333
fsnotify_get_mark(entry);
321-
322334
spin_unlock(&hash_lock);
323335

324336
if (size)
@@ -336,15 +348,10 @@ static void untag_chunk(struct node *p)
336348
goto out;
337349
}
338350

339-
owner = p->owner;
340-
341351
if (!size) {
342352
chunk->dead = 1;
343353
spin_lock(&hash_lock);
344354
list_del_init(&chunk->trees);
345-
if (owner->root == chunk)
346-
owner->root = NULL;
347-
list_del_init(&p->list);
348355
list_del_rcu(&chunk->hash);
349356
spin_unlock(&hash_lock);
350357
fsnotify_detach_mark(entry);
@@ -354,21 +361,16 @@ static void untag_chunk(struct node *p)
354361
}
355362

356363
if (!new)
357-
goto Fallback;
364+
goto out_mutex;
358365

359366
if (fsnotify_add_mark_locked(new->mark, entry->connector->obj,
360367
FSNOTIFY_OBJ_TYPE_INODE, 1)) {
361368
fsnotify_put_mark(new->mark);
362-
goto Fallback;
369+
goto out_mutex;
363370
}
364371

365372
chunk->dead = 1;
366373
spin_lock(&hash_lock);
367-
if (owner->root == chunk) {
368-
list_del_init(&owner->same_root);
369-
owner->root = NULL;
370-
}
371-
list_del_init(&p->list);
372374
/*
373375
* This has to go last when updating chunk as once replace_chunk() is
374376
* called, new RCU readers can see the new chunk.
@@ -381,17 +383,7 @@ static void untag_chunk(struct node *p)
381383
fsnotify_put_mark(new->mark); /* drop initial reference */
382384
goto out;
383385

384-
Fallback:
385-
// do the best we can
386-
spin_lock(&hash_lock);
387-
if (owner->root == chunk) {
388-
list_del_init(&owner->same_root);
389-
owner->root = NULL;
390-
}
391-
list_del_init(&p->list);
392-
p->owner = NULL;
393-
put_tree(owner);
394-
spin_unlock(&hash_lock);
386+
out_mutex:
395387
mutex_unlock(&entry->group->mark_mutex);
396388
out:
397389
fsnotify_put_mark(entry);

0 commit comments

Comments
 (0)