linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Hildenbrand <david@redhat.com>
To: Navid Emamdoost <navid.emamdoost@gmail.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-mm@kvack.org, linux-kernel@vger.kernel.org
Cc: emamd001@umn.edu
Subject: Re: [PATCH] mm/gup: Fix memory leaks in __gup_benchmark_ioctl
Date: Mon, 25 Nov 2019 10:25:12 +0100	[thread overview]
Message-ID: <1886e547-38ab-f4e9-02bf-42848653a46d@redhat.com> (raw)
In-Reply-To: <20191122224117.2372-1-navid.emamdoost@gmail.com>

On 22.11.19 23:41, Navid Emamdoost wrote:
> In the implementation of __gup_benchmark_ioctl() memory is leaked if the
> passed cmd is invalid. Release pages before returning -1.
> 
> Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods")



> Signed-off-by: Navid Emamdoost <navid.emamdoost@gmail.com>
> ---
>  mm/gup_benchmark.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c
> index 7dd602d7f8db..33ede5727523 100644
> --- a/mm/gup_benchmark.c
> +++ b/mm/gup_benchmark.c
> @@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
>  		struct gup_benchmark *gup)
>  {
>  	ktime_t start_time, end_time;
> -	unsigned long i, nr_pages, addr, next;
> +	unsigned long i, j, nr_pages, addr, next;
>  	int nr;
>  	struct page **pages;
>  
> @@ -63,6 +63,12 @@ static int __gup_benchmark_ioctl(unsigned int cmd,
>  					    NULL);
>  			break;
>  		default:
> +			for (j = 0; j < i; j++) {
> +				if (!pages[j])
> +					break;
> +				put_page(pages[j]);
> +			}

We didn't pin any pages, why should we release them?

IMHO, all that's needed is the ...

> +			kvfree(pages);

.. here


>  			return -1;
>  		}
>  

Not sure how often CONFIG_GUP_BENCHMARK is really enabled. Maybe we should

Cc: stable@vger.kernel.org # v4.20+


With only the kvfree(pages)

Reviewed-by: David Hildenbrand <david@redhat.com>

-- 

Thanks,

David / dhildenb



      reply	other threads:[~2019-11-25  9:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22 22:41 Navid Emamdoost
2019-11-25  9:25 ` David Hildenbrand [this message]

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=1886e547-38ab-f4e9-02bf-42848653a46d@redhat.com \
    --to=david@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=emamd001@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=navid.emamdoost@gmail.com \
    /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