linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: zhong jiang <zhongjiang@huawei.com>
To: Elena Reshetova <elena.reshetova@intel.com>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	peterz@infradead.org, gregkh@linuxfoundation.org,
	viro@zeniv.linux.org.uk, catalin.marinas@arm.com,
	mingo@redhat.com, akpm@linux-foundation.org, arnd@arndb.de,
	luto@kernel.org, Hans Liljestrand <ishkamiel@gmail.com>,
	Kees Cook <keescook@chromium.org>,
	David Windsor <dwindsor@gmail.com>
Subject: Re: [PATCH 2/5] mm: convert anon_vma.refcount from atomic_t to refcount_t
Date: Sat, 22 Apr 2017 18:44:13 +0800	[thread overview]
Message-ID: <58FB33FD.3010909@huawei.com> (raw)
In-Reply-To: <1487587754-10610-3-git-send-email-elena.reshetova@intel.com>

Hi, Elean

Do the issue had really occured,  use-after-free. but why the patch
 is not received.   or is is possible for the situation.

Thanks
zhongjiang
On 2017/2/20 18:49, Elena Reshetova wrote:
> refcount_t type and corresponding API should be
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
>
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
> Signed-off-by: Hans Liljestrand <ishkamiel@gmail.com>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: David Windsor <dwindsor@gmail.com>
> ---
>  include/linux/rmap.h |  7 ++++---
>  mm/rmap.c            | 14 +++++++-------
>  2 files changed, 11 insertions(+), 10 deletions(-)
>
> diff --git a/include/linux/rmap.h b/include/linux/rmap.h
> index 8c89e90..a8f4a97 100644
> --- a/include/linux/rmap.h
> +++ b/include/linux/rmap.h
> @@ -10,6 +10,7 @@
>  #include <linux/rwsem.h>
>  #include <linux/memcontrol.h>
>  #include <linux/highmem.h>
> +#include <linux/refcount.h>
>  
>  /*
>   * The anon_vma heads a list of private "related" vmas, to scan if
> @@ -35,7 +36,7 @@ struct anon_vma {
>  	 * the reference is responsible for clearing up the
>  	 * anon_vma if they are the last user on release
>  	 */
> -	atomic_t refcount;
> +	refcount_t refcount;
>  
>  	/*
>  	 * Count of child anon_vmas and VMAs which points to this anon_vma.
> @@ -102,14 +103,14 @@ enum ttu_flags {
>  #ifdef CONFIG_MMU
>  static inline void get_anon_vma(struct anon_vma *anon_vma)
>  {
> -	atomic_inc(&anon_vma->refcount);
> +	refcount_inc(&anon_vma->refcount);
>  }
>  
>  void __put_anon_vma(struct anon_vma *anon_vma);
>  
>  static inline void put_anon_vma(struct anon_vma *anon_vma)
>  {
> -	if (atomic_dec_and_test(&anon_vma->refcount))
> +	if (refcount_dec_and_test(&anon_vma->refcount))
>  		__put_anon_vma(anon_vma);
>  }
>  
> diff --git a/mm/rmap.c b/mm/rmap.c
> index 8774791..3321c86 100644
> --- a/mm/rmap.c
> +++ b/mm/rmap.c
> @@ -77,7 +77,7 @@ static inline struct anon_vma *anon_vma_alloc(void)
>  
>  	anon_vma = kmem_cache_alloc(anon_vma_cachep, GFP_KERNEL);
>  	if (anon_vma) {
> -		atomic_set(&anon_vma->refcount, 1);
> +		refcount_set(&anon_vma->refcount, 1);
>  		anon_vma->degree = 1;	/* Reference for first vma */
>  		anon_vma->parent = anon_vma;
>  		/*
> @@ -92,7 +92,7 @@ static inline struct anon_vma *anon_vma_alloc(void)
>  
>  static inline void anon_vma_free(struct anon_vma *anon_vma)
>  {
> -	VM_BUG_ON(atomic_read(&anon_vma->refcount));
> +	VM_BUG_ON(refcount_read(&anon_vma->refcount));
>  
>  	/*
>  	 * Synchronize against page_lock_anon_vma_read() such that
> @@ -421,7 +421,7 @@ static void anon_vma_ctor(void *data)
>  	struct anon_vma *anon_vma = data;
>  
>  	init_rwsem(&anon_vma->rwsem);
> -	atomic_set(&anon_vma->refcount, 0);
> +	refcount_set(&anon_vma->refcount, 0);
>  	anon_vma->rb_root = RB_ROOT;
>  }
>  
> @@ -470,7 +470,7 @@ struct anon_vma *page_get_anon_vma(struct page *page)
>  		goto out;
>  
>  	anon_vma = (struct anon_vma *) (anon_mapping - PAGE_MAPPING_ANON);
> -	if (!atomic_inc_not_zero(&anon_vma->refcount)) {
> +	if (!refcount_inc_not_zero(&anon_vma->refcount)) {
>  		anon_vma = NULL;
>  		goto out;
>  	}
> @@ -529,7 +529,7 @@ struct anon_vma *page_lock_anon_vma_read(struct page *page)
>  	}
>  
>  	/* trylock failed, we got to sleep */
> -	if (!atomic_inc_not_zero(&anon_vma->refcount)) {
> +	if (!refcount_inc_not_zero(&anon_vma->refcount)) {
>  		anon_vma = NULL;
>  		goto out;
>  	}
> @@ -544,7 +544,7 @@ struct anon_vma *page_lock_anon_vma_read(struct page *page)
>  	rcu_read_unlock();
>  	anon_vma_lock_read(anon_vma);
>  
> -	if (atomic_dec_and_test(&anon_vma->refcount)) {
> +	if (refcount_dec_and_test(&anon_vma->refcount)) {
>  		/*
>  		 * Oops, we held the last refcount, release the lock
>  		 * and bail -- can't simply use put_anon_vma() because
> @@ -1577,7 +1577,7 @@ void __put_anon_vma(struct anon_vma *anon_vma)
>  	struct anon_vma *root = anon_vma->root;
>  
>  	anon_vma_free(anon_vma);
> -	if (root != anon_vma && atomic_dec_and_test(&root->refcount))
> +	if (root != anon_vma && refcount_dec_and_test(&root->refcount))
>  		anon_vma_free(root);
>  }
>  

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2017-04-22 10:51 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-20 10:49 [PATCH 0/5] mm subsystem refcounter conversions Elena Reshetova
2017-02-20 10:49 ` [PATCH 1/5] mm: convert bdi_writeback_congested.refcnt from atomic_t to refcount_t Elena Reshetova
2017-02-20 11:33   ` kbuild test robot
2017-02-20 10:49 ` [PATCH 2/5] mm: convert anon_vma.refcount " Elena Reshetova
2017-04-22 10:44   ` zhong jiang [this message]
2017-04-24 10:20     ` Reshetova, Elena
2017-02-20 10:49 ` [PATCH 3/5] mm: convert kmemleak_object.use_count " Elena Reshetova
2017-02-20 10:49 ` [PATCH 4/5] mm: convert mm_struct.mm_users " Elena Reshetova
2017-02-20 11:46   ` kbuild test robot
2017-02-20 10:49 ` [PATCH 5/5] mm: convert mm_struct.mm_count " Elena Reshetova
2017-02-20 13:16   ` kbuild test robot
  -- strict thread matches above, loose matches on Subject: below --
2017-02-21  9:58 [PATCH 0/5] mm subsystem refcounter conversions Elena Reshetova
2017-02-21  9:58 ` [PATCH 2/5] mm: convert anon_vma.refcount from atomic_t to refcount_t Elena Reshetova
2017-06-27 11:48 [PATCH 0/5] v2 mm subsystem refcounter conversions Elena Reshetova
2017-06-27 11:48 ` [PATCH 2/5] mm: convert anon_vma.refcount from atomic_t to refcount_t Elena Reshetova

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=58FB33FD.3010909@huawei.com \
    --to=zhongjiang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=catalin.marinas@arm.com \
    --cc=dwindsor@gmail.com \
    --cc=elena.reshetova@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=ishkamiel@gmail.com \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --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).