History

audit: use fsnotify group lock helpers

audit inode marks pin the inode so there is no need to set the FSNOTIFY_GROUP_NOFS flag.

Amir Goldstein committed 4 years ago

Commit 960bdff1 parent 642054b1 file · +16 −16Browse files

Unified · Split

kernel/audit_tree.c+16−16
@@ -351,7 +351,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) · 350 unmodified lines
351 struct audit_chunk *new;351 struct audit_chunk *new;
352 int size;352 int size;
353 353
354 mutex_lock(&audit_tree_group->mark_mutex);354 fsnotify_group_lock(audit_tree_group);
355 /*355 /*
356 * mark_mutex stabilizes chunk attached to the mark so we can check356 * mark_mutex stabilizes chunk attached to the mark so we can check
357 * whether it didn't change while we've dropped hash_lock.357 * whether it didn't change while we've dropped hash_lock.
@@ -368,7 +368,7 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) · 10 unmodified lines
368 replace_mark_chunk(mark, NULL);368 replace_mark_chunk(mark, NULL);
369 spin_unlock(&hash_lock);369 spin_unlock(&hash_lock);
370 fsnotify_detach_mark(mark);370 fsnotify_detach_mark(mark);
371 mutex_unlock(&audit_tree_group->mark_mutex);371 fsnotify_group_unlock(audit_tree_group);
372 audit_mark_put_chunk(chunk);372 audit_mark_put_chunk(chunk);
373 fsnotify_free_mark(mark);373 fsnotify_free_mark(mark);
374 return;374 return;
@@ -385,12 +385,12 @@ static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) · 10 unmodified lines
385 */385 */
386 replace_chunk(new, chunk);386 replace_chunk(new, chunk);
387 spin_unlock(&hash_lock);387 spin_unlock(&hash_lock);
388 mutex_unlock(&audit_tree_group->mark_mutex);388 fsnotify_group_unlock(audit_tree_group);
389 audit_mark_put_chunk(chunk);389 audit_mark_put_chunk(chunk);
390 return;390 return;
391 391
392out_mutex:392out_mutex:
393 mutex_unlock(&audit_tree_group->mark_mutex);393 fsnotify_group_unlock(audit_tree_group);
394}394}
395 395
396/* Call with group->mark_mutex held, releases it */396/* Call with group->mark_mutex held, releases it */
@@ -400,19 +400,19 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) · 3 unmodified lines
400 struct audit_chunk *chunk = alloc_chunk(1);400 struct audit_chunk *chunk = alloc_chunk(1);
401 401
402 if (!chunk) {402 if (!chunk) {
403 mutex_unlock(&audit_tree_group->mark_mutex);403 fsnotify_group_unlock(audit_tree_group);
404 return -ENOMEM;404 return -ENOMEM;
405 }405 }
406 406
407 mark = alloc_mark();407 mark = alloc_mark();
408 if (!mark) {408 if (!mark) {
409 mutex_unlock(&audit_tree_group->mark_mutex);409 fsnotify_group_unlock(audit_tree_group);
410 kfree(chunk);410 kfree(chunk);
411 return -ENOMEM;411 return -ENOMEM;
412 }412 }
413 413
414 if (fsnotify_add_inode_mark_locked(mark, inode, 0)) {414 if (fsnotify_add_inode_mark_locked(mark, inode, 0)) {
415 mutex_unlock(&audit_tree_group->mark_mutex);415 fsnotify_group_unlock(audit_tree_group);
416 fsnotify_put_mark(mark);416 fsnotify_put_mark(mark);
417 kfree(chunk);417 kfree(chunk);
418 return -ENOSPC;418 return -ENOSPC;
@@ -422,7 +422,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) · 3 unmodified lines
422 if (tree->goner) {422 if (tree->goner) {
423 spin_unlock(&hash_lock);423 spin_unlock(&hash_lock);
424 fsnotify_detach_mark(mark);424 fsnotify_detach_mark(mark);
425 mutex_unlock(&audit_tree_group->mark_mutex);425 fsnotify_group_unlock(audit_tree_group);
426 fsnotify_free_mark(mark);426 fsnotify_free_mark(mark);
427 fsnotify_put_mark(mark);427 fsnotify_put_mark(mark);
428 kfree(chunk);428 kfree(chunk);
@@ -444,7 +444,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree) · 15 unmodified lines
444 */444 */
445 insert_hash(chunk);445 insert_hash(chunk);
446 spin_unlock(&hash_lock);446 spin_unlock(&hash_lock);
447 mutex_unlock(&audit_tree_group->mark_mutex);447 fsnotify_group_unlock(audit_tree_group);
448 /*448 /*
449 * Drop our initial reference. When mark we point to is getting freed,449 * Drop our initial reference. When mark we point to is getting freed,
450 * we get notification through ->freeing_mark callback and cleanup450 * we get notification through ->freeing_mark callback and cleanup
@@ -462,7 +462,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) · 11 unmodified lines
462 struct audit_node *p;462 struct audit_node *p;
463 int n;463 int n;
464 464
465 mutex_lock(&audit_tree_group->mark_mutex);465 fsnotify_group_lock(audit_tree_group);
466 mark = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_tree_group);466 mark = fsnotify_find_mark(&inode->i_fsnotify_marks, audit_tree_group);
467 if (!mark)467 if (!mark)
468 return create_chunk(inode, tree);468 return create_chunk(inode, tree);
@@ -478,7 +478,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) · 9 unmodified lines
478 for (n = 0; n < old->count; n++) {478 for (n = 0; n < old->count; n++) {
479 if (old->owners[n].owner == tree) {479 if (old->owners[n].owner == tree) {
480 spin_unlock(&hash_lock);480 spin_unlock(&hash_lock);
481 mutex_unlock(&audit_tree_group->mark_mutex);481 fsnotify_group_unlock(audit_tree_group);
482 fsnotify_put_mark(mark);482 fsnotify_put_mark(mark);
483 return 0;483 return 0;
484 }484 }
@@ -487,7 +487,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) · 2 unmodified lines
487 487
488 chunk = alloc_chunk(old->count + 1);488 chunk = alloc_chunk(old->count + 1);
489 if (!chunk) {489 if (!chunk) {
490 mutex_unlock(&audit_tree_group->mark_mutex);490 fsnotify_group_unlock(audit_tree_group);
491 fsnotify_put_mark(mark);491 fsnotify_put_mark(mark);
492 return -ENOMEM;492 return -ENOMEM;
493 }493 }
@@ -495,7 +495,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) · 1 unmodified line
495 spin_lock(&hash_lock);495 spin_lock(&hash_lock);
496 if (tree->goner) {496 if (tree->goner) {
497 spin_unlock(&hash_lock);497 spin_unlock(&hash_lock);
498 mutex_unlock(&audit_tree_group->mark_mutex);498 fsnotify_group_unlock(audit_tree_group);
499 fsnotify_put_mark(mark);499 fsnotify_put_mark(mark);
500 kfree(chunk);500 kfree(chunk);
501 return 0;501 return 0;
@@ -515,7 +515,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree) · 13 unmodified lines
515 */515 */
516 replace_chunk(chunk, old);516 replace_chunk(chunk, old);
517 spin_unlock(&hash_lock);517 spin_unlock(&hash_lock);
518 mutex_unlock(&audit_tree_group->mark_mutex);518 fsnotify_group_unlock(audit_tree_group);
519 fsnotify_put_mark(mark); /* pair to fsnotify_find_mark */519 fsnotify_put_mark(mark); /* pair to fsnotify_find_mark */
520 audit_mark_put_chunk(old);520 audit_mark_put_chunk(old);
521 521
@@ -1044,12 +1044,12 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *mark, · 522 unmodified lines
1044{1044{
1045 struct audit_chunk *chunk;1045 struct audit_chunk *chunk;
1046 1046
1047 mutex_lock(&mark->group->mark_mutex);1047 fsnotify_group_lock(mark->group);
1048 spin_lock(&hash_lock);1048 spin_lock(&hash_lock);
1049 chunk = mark_chunk(mark);1049 chunk = mark_chunk(mark);
1050 replace_mark_chunk(mark, NULL);1050 replace_mark_chunk(mark, NULL);
1051 spin_unlock(&hash_lock);1051 spin_unlock(&hash_lock);
1052 mutex_unlock(&mark->group->mark_mutex);1052 fsnotify_group_unlock(mark->group);
1053 if (chunk) {1053 if (chunk) {
1054 evict_chunk(chunk);1054 evict_chunk(chunk);
1055 audit_mark_put_chunk(chunk);1055 audit_mark_put_chunk(chunk);