2013-09-16 12:42:10

by Jianguo Wu

[permalink] [raw]
Subject: [PATCH] mm/ksm: return NULL when doesn't get mergeable page

In get_mergeable_page() local variable page is not initialized,
it may hold a garbage value, when find_mergeable_vma() return NULL,
get_mergeable_page() may return a garbage value to the caller.

So initialize page as NULL.

Signed-off-by: Jianguo Wu <[email protected]>
---
mm/ksm.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index b6afe0c..87efbae 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -460,7 +460,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
struct mm_struct *mm = rmap_item->mm;
unsigned long addr = rmap_item->address;
struct vm_area_struct *vma;
- struct page *page;
+ struct page *page = NULL;

down_read(&mm->mmap_sem);
vma = find_mergeable_vma(mm, addr);
--
1.7.1


2013-09-19 08:33:43

by Petr Holasek

[permalink] [raw]
Subject: Re: [PATCH] mm/ksm: return NULL when doesn't get mergeable page

On Mon, 16 Sep 2013, Jianguo Wu wrote:
> In get_mergeable_page() local variable page is not initialized,
> it may hold a garbage value, when find_mergeable_vma() return NULL,
> get_mergeable_page() may return a garbage value to the caller.
>
> So initialize page as NULL.
>
> Signed-off-by: Jianguo Wu <[email protected]>
> ---
> mm/ksm.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index b6afe0c..87efbae 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
> @@ -460,7 +460,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
> struct mm_struct *mm = rmap_item->mm;
> unsigned long addr = rmap_item->address;
> struct vm_area_struct *vma;
> - struct page *page;
> + struct page *page = NULL;
>
> down_read(&mm->mmap_sem);
> vma = find_mergeable_vma(mm, addr);
> --
> 1.7.1
>

When find_mergeable_vma returned NULL, NULL is assigned to page in "out"
statement.

2013-09-22 00:55:12

by Jianguo Wu

[permalink] [raw]
Subject: Re: [PATCH] mm/ksm: return NULL when doesn't get mergeable page

On 2013/9/19 16:33, Petr Holasek wrote:

> On Mon, 16 Sep 2013, Jianguo Wu wrote:
>> In get_mergeable_page() local variable page is not initialized,
>> it may hold a garbage value, when find_mergeable_vma() return NULL,
>> get_mergeable_page() may return a garbage value to the caller.
>>
>> So initialize page as NULL.
>>
>> Signed-off-by: Jianguo Wu <[email protected]>
>> ---
>> mm/ksm.c | 2 +-
>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/mm/ksm.c b/mm/ksm.c
>> index b6afe0c..87efbae 100644
>> --- a/mm/ksm.c
>> +++ b/mm/ksm.c
>> @@ -460,7 +460,7 @@ static struct page *get_mergeable_page(struct rmap_item *rmap_item)
>> struct mm_struct *mm = rmap_item->mm;
>> unsigned long addr = rmap_item->address;
>> struct vm_area_struct *vma;
>> - struct page *page;
>> + struct page *page = NULL;
>>
>> down_read(&mm->mmap_sem);
>> vma = find_mergeable_vma(mm, addr);
>> --
>> 1.7.1
>>
>
> When find_mergeable_vma returned NULL, NULL is assigned to page in "out"
> statement.
>

Oh, yes, thanks, Petr.

>