@@ -342,25 +342,29 @@ static void untag_chunk(struct node *p)
342342 spin_lock (& hash_lock );
343343}
344344
345+ /* Call with group->mark_mutex held, releases it */
345346static int create_chunk (struct inode * inode , struct audit_tree * tree )
346347{
347348 struct fsnotify_mark * entry ;
348349 struct audit_chunk * chunk = alloc_chunk (1 );
349- if (!chunk )
350+
351+ if (!chunk ) {
352+ mutex_unlock (& audit_tree_group -> mark_mutex );
350353 return - ENOMEM ;
354+ }
351355
352356 entry = & chunk -> mark ;
353- if (fsnotify_add_inode_mark (entry , inode , 0 )) {
357+ if (fsnotify_add_inode_mark_locked (entry , inode , 0 )) {
358+ mutex_unlock (& audit_tree_group -> mark_mutex );
354359 fsnotify_put_mark (entry );
355360 return - ENOSPC ;
356361 }
357362
358- mutex_lock (& entry -> group -> mark_mutex );
359363 spin_lock (& hash_lock );
360364 if (tree -> goner ) {
361365 spin_unlock (& hash_lock );
362366 chunk -> dead = 1 ;
363- mutex_unlock (& entry -> group -> mark_mutex );
367+ mutex_unlock (& audit_tree_group -> mark_mutex );
364368 fsnotify_destroy_mark (entry , audit_tree_group );
365369 fsnotify_put_mark (entry );
366370 return 0 ;
@@ -375,7 +379,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
375379 }
376380 insert_hash (chunk );
377381 spin_unlock (& hash_lock );
378- mutex_unlock (& entry -> group -> mark_mutex );
382+ mutex_unlock (& audit_tree_group -> mark_mutex );
379383 fsnotify_put_mark (entry ); /* drop initial reference */
380384 return 0 ;
381385}
@@ -389,6 +393,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
389393 struct node * p ;
390394 int n ;
391395
396+ mutex_lock (& audit_tree_group -> mark_mutex );
392397 old_entry = fsnotify_find_mark (& inode -> i_fsnotify_marks ,
393398 audit_tree_group );
394399 if (!old_entry )
@@ -401,6 +406,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
401406 for (n = 0 ; n < old -> count ; n ++ ) {
402407 if (old -> owners [n ].owner == tree ) {
403408 spin_unlock (& hash_lock );
409+ mutex_unlock (& audit_tree_group -> mark_mutex );
404410 fsnotify_put_mark (old_entry );
405411 return 0 ;
406412 }
@@ -409,28 +415,28 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
409415
410416 chunk = alloc_chunk (old -> count + 1 );
411417 if (!chunk ) {
418+ mutex_unlock (& audit_tree_group -> mark_mutex );
412419 fsnotify_put_mark (old_entry );
413420 return - ENOMEM ;
414421 }
415422
416423 chunk_entry = & chunk -> mark ;
417424
418- mutex_lock (& old_entry -> group -> mark_mutex );
419425 /*
420426 * mark_mutex protects mark from getting detached and thus also from
421427 * mark->connector->obj getting NULL.
422428 */
423429 if (!(old_entry -> flags & FSNOTIFY_MARK_FLAG_ATTACHED )) {
424430 /* old_entry is being shot, lets just lie */
425- mutex_unlock (& old_entry -> group -> mark_mutex );
431+ mutex_unlock (& audit_tree_group -> mark_mutex );
426432 fsnotify_put_mark (old_entry );
427433 fsnotify_put_mark (& chunk -> mark );
428434 return - ENOENT ;
429435 }
430436
431437 if (fsnotify_add_mark_locked (chunk_entry , old_entry -> connector -> obj ,
432438 FSNOTIFY_OBJ_TYPE_INODE , 1 )) {
433- mutex_unlock (& old_entry -> group -> mark_mutex );
439+ mutex_unlock (& audit_tree_group -> mark_mutex );
434440 fsnotify_put_mark (chunk_entry );
435441 fsnotify_put_mark (old_entry );
436442 return - ENOSPC ;
@@ -440,7 +446,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
440446 if (tree -> goner ) {
441447 spin_unlock (& hash_lock );
442448 chunk -> dead = 1 ;
443- mutex_unlock (& old_entry -> group -> mark_mutex );
449+ mutex_unlock (& audit_tree_group -> mark_mutex );
444450
445451 fsnotify_destroy_mark (chunk_entry , audit_tree_group );
446452
@@ -471,7 +477,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
471477 list_add (& tree -> same_root , & chunk -> trees );
472478 }
473479 spin_unlock (& hash_lock );
474- mutex_unlock (& old_entry -> group -> mark_mutex );
480+ mutex_unlock (& audit_tree_group -> mark_mutex );
475481 fsnotify_destroy_mark (old_entry , audit_tree_group );
476482 fsnotify_put_mark (chunk_entry ); /* drop initial reference */
477483 fsnotify_put_mark (old_entry ); /* pair to fsnotify_find mark_entry */
0 commit comments