[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <3affa5da-469e-4a25-8c75-dfc783ed2919@redhat.com>
Date: Thu, 21 Nov 2024 16:04:32 +0100
From: David Hildenbrand <david@...hat.com>
To: Jeongjun Park <aha310510@...il.com>
Cc: akpm@...ux-foundation.org, dave@...olabs.net, willy@...radead.org,
Liam.Howlett@...cle.com, linux-mm@...ck.org, linux-kernel@...r.kernel.org,
stable@...r.kernel.org, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
Subject: Re: [PATCH] mm/huge_memory: Fix to make vma_adjust_trans_huge() use
find_vma() correctly
On 21.11.24 15:18, Jeongjun Park wrote:
> David Hildenbrand <david@...hat.com> wrote:
>>
>> On 21.11.24 14:44, David Hildenbrand wrote:
>>> On 21.11.24 13:41, Jeongjun Park wrote:
>>>> vma_adjust_trans_huge() uses find_vma() to get the VMA, but find_vma() uses
>>>> the returned pointer without any verification, even though it may return NULL.
>>>> In this case, NULL pointer dereference may occur, so to prevent this,
>>>> vma_adjust_trans_huge() should be fix to verify the return value of find_vma().
>>>>
>>>> Cc: <stable@...r.kernel.org>
>>>> Fixes: 685405020b9f ("mm/khugepaged: stop using vma linked list")
>>>
>>> If that's an issue, wouldn't it have predated that commit?
>>>
>>> struct vm_area_struct *next = vma->vm_next;
>>> unsigned long nstart = next->vm_start;
>>>
>>> Would have also assumed that there is a next VMA that can be
>>> dereferenced, no?
>>>
>>
>> And looking into the details, we only assume that there is a next VMA if
>> we are explicitly told to by the caller of vma_adjust_trans_huge() using
>> "adjust_next".
>>
>> There is only one such caller,
>> vma_merge_existing_range()->commit_merge() where we set adj_start ->
>> "adjust_next" where we seem to have a guarantee that there is a next VMA.
>
> I also thought that it would not be a problem in general cases, but I think
> that there may be a special case (for example, a race condition...?) that can
> occur in certain conditions, although I have not found it yet.
If we're working on VMAs in that way (merging!) we need the mmap lock in
write mode, so no races are possible.
>
> In addition, most functions except this one unconditionally check the return
> value of find_vma(), so I think it would be better to handle the return value
> of find_vma() consistently in this function as well, rather than taking the
> risk and leaving it alone just because it seems to be okay.
Your patch is silently hiding something that should never happen such
that we wouldn't handle our operation as intended. So no, that's even worse.
--
Cheers,
David / dhildenb
Powered by blists - more mailing lists