linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Paris <eparis@redhat.com>
To: Miklos Szeredi <miklos@szeredi.hu>
Cc: viro@ZenIV.linux.org.uk, linux-kernel@vger.kernel.org, mszeredi@suse.cz
Subject: Re: [PATCH 3/3] audit: clean up refcounting in audit-tree
Date: Fri, 06 Jul 2012 13:51:04 -0400	[thread overview]
Message-ID: <1341597064.5347.3.camel@localhost> (raw)
In-Reply-To: <1340646378-5169-4-git-send-email-miklos@szeredi.hu>

On Mon, 2012-06-25 at 19:46 +0200, Miklos Szeredi wrote:
> From: Miklos Szeredi <mszeredi@suse.cz>
> 
> Drop the initial reference by fsnotify_init_mark early instead of
> audit_tree_freeing_mark() at destroy time.
> 
> In the cases we destroy the mark before we drop the initial reference we need to
> get rid of the get_mark that balances the put_mark in audit_tree_freeing_mark().
> 
> Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>

I don't love this.  The reference from fsnotify_init_mark() should live
until fsnotify_mark_destroy().  If we need to drop a reference in
audit_tree_freeing_mark() we should be taking that elsewhere....

> ---
>  kernel/audit_tree.c |   12 +++++++++---
>  1 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/kernel/audit_tree.c b/kernel/audit_tree.c
> index 31fdc48..7b95706 100644
> --- a/kernel/audit_tree.c
> +++ b/kernel/audit_tree.c
> @@ -292,6 +292,7 @@ static void untag_chunk(struct node *p)
>  	spin_unlock(&hash_lock);
>  	spin_unlock(&entry->lock);
>  	fsnotify_destroy_mark(entry);
> +	fsnotify_put_mark(&new->mark);	/* drop initial reference */
>  	goto out;
>  
>  Fallback:
> @@ -330,7 +331,6 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
>  		spin_unlock(&hash_lock);
>  		chunk->dead = 1;
>  		spin_unlock(&entry->lock);
> -		fsnotify_get_mark(entry);
>  		fsnotify_destroy_mark(entry);
>  		fsnotify_put_mark(entry);
>  		return 0;
> @@ -346,6 +346,7 @@ static int create_chunk(struct inode *inode, struct audit_tree *tree)
>  	insert_hash(chunk);
>  	spin_unlock(&hash_lock);
>  	spin_unlock(&entry->lock);
> +	fsnotify_put_mark(entry);	/* drop initial reference */
>  	return 0;
>  }
>  
> @@ -411,7 +412,6 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
>  		spin_unlock(&chunk_entry->lock);
>  		spin_unlock(&old_entry->lock);
>  
> -		fsnotify_get_mark(chunk_entry);
>  		fsnotify_destroy_mark(chunk_entry);
>  
>  		fsnotify_put_mark(chunk_entry);
> @@ -444,6 +444,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
>  	spin_unlock(&chunk_entry->lock);
>  	spin_unlock(&old_entry->lock);
>  	fsnotify_destroy_mark(old_entry);
> +	fsnotify_put_mark(chunk_entry);	/* drop initial reference */
>  	fsnotify_put_mark(old_entry); /* pair to fsnotify_find mark_entry */
>  	return 0;
>  }
> @@ -915,7 +916,12 @@ static void audit_tree_freeing_mark(struct fsnotify_mark *entry, struct fsnotify
>  	struct audit_chunk *chunk = container_of(entry, struct audit_chunk, mark);
>  
>  	evict_chunk(chunk);
> -	fsnotify_put_mark(entry);
> +
> +	/*
> +	 * We are guaranteed to have at least one reference to the mark from
> +	 * either the inode or the caller of fsnotify_destroy_mark().
> +	 */
> +	BUG_ON(atomic_read(&entry->refcnt) < 1);
>  }
>  
>  static bool audit_tree_send_event(struct fsnotify_group *group, struct inode *inode,



  reply	other threads:[~2012-07-06 18:12 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-25 17:46 [PATCH 0/3] audit-tree fixes Miklos Szeredi
2012-06-25 17:46 ` [PATCH 1/3] audit: don't free_chunk() after fsnotify_add_mark() Miklos Szeredi
2012-07-06 17:43   ` Eric Paris
2012-06-25 17:46 ` [PATCH 2/3] audit: fix refcounting in audit-tree Miklos Szeredi
2012-07-06 17:52   ` Eric Paris
2012-07-11 22:24     ` Miklos Szeredi
2012-06-25 17:46 ` [PATCH 3/3] audit: clean up " Miklos Szeredi
2012-07-06 17:51   ` Eric Paris [this message]
2012-07-11 22:25     ` Miklos Szeredi
2012-07-03 11:15 ` [PATCH 0/3] audit-tree fixes Miklos Szeredi
  -- strict thread matches above, loose matches on Subject: below --
2012-08-15 13:49 [PATCH 0/3] audit-tree fixes (resend) Miklos Szeredi
2012-08-15 13:49 ` [PATCH 3/3] audit: clean up refcounting in audit-tree Miklos Szeredi
2012-08-21 19:03 [PATCH 0/3] audit-tree fixes Miklos Szeredi
2012-08-21 19:03 ` [PATCH 3/3] audit: clean up refcounting in audit-tree Miklos Szeredi
2012-08-21 19:37   ` Linus Torvalds

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341597064.5347.3.camel@localhost \
    --to=eparis@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=mszeredi@suse.cz \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).