[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <a6c69b04-6857-4021-8b7c-85398778deab@linux.dev>
Date: Tue, 17 Jun 2025 16:18:24 +0800
From: Lance Yang <lance.yang@...ux.dev>
To: David Hildenbrand <david@...hat.com>
Cc: 21cnbao@...il.com, Liam.Howlett@...cle.com, vbabka@...e.cz,
jannh@...gle.com, lorenzo.stoakes@...cle.com, linux-kernel@...r.kernel.org,
linux-mm@...ck.org, akpm@...ux-foundation.org,
Lance Yang <ioworker0@...il.com>
Subject: Re: [PATCH 1/1] mm/madvise: initialize prev pointer in
madvise_walk_vmas
On 2025/6/17 15:54, David Hildenbrand wrote:
> On 17.06.25 04:05, Lance Yang wrote:
>> From: Lance Yang <lance.yang@...ux.dev>
>>
>> The prev pointer was uninitialized, which could lead to undefined
>> behavior
>> where its address is taken and passed to the visit() callback without
>> being
>> assigned a value.
>
> So, we are passing the pointer value to visit(), which is not undefined
> behavior.
>
> The issue would be if anybody takes a look at the value stored at that
> pointer. Because, already passing an uninitialized value to a (non-
> inlined) function is undefined behavior according to C.
Yes, that is precisely is what I am concerned about ;)
>
> In madvise_update_vma()->vma_modify_flags_name() we do exactly that,
> correct?
>
> vma = vma_modify_flags_name(&vmi, *prev, ...
>
> We should use Fixes: then.
Exactly, I missed that. Will add the "Fixes" tag and send out a new version.
>
>
> Acked-by: David Hildenbrand <david@...hat.com>
Thanks!
Lance
>
>>
>> Initializing it to NULL makes the code safer and prevents potential bugs
>> if a future callback function attempts to read from it.
>>
>> Signed-off-by: Lance Yang <lance.yang@...ux.dev>
>> ---
>> mm/madvise.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/madvise.c b/mm/madvise.c
>> index 267d8e4adf31..c87325000303 100644
>> --- a/mm/madvise.c
>> +++ b/mm/madvise.c
>> @@ -1536,10 +1536,10 @@ int madvise_walk_vmas(struct mm_struct *mm,
>> unsigned long start,
>> struct vm_area_struct **prev, unsigned long start,
>> unsigned long end, void *arg))
>> {
>> + struct vm_area_struct *prev = NULL;
>> struct vm_area_struct *vma;
>> - struct vm_area_struct *prev;
>> - unsigned long tmp;
>> int unmapped_error = 0;
>> + unsigned long tmp;
>> int error;
>> /*
>
>
Powered by blists - more mailing lists