Re: [PATCH v5 04/11] mm/vmalloc: reject an unaligned range in __vunmap_range_noflush()

From: Hao Ge

Date: Mon Nov 23 2026 - 03:24:37 EST


Hi Suren and Dev

On 2026/11/21 06:13, Suren Baghdasaryan wrote:
> On Tue, Nov 17, 2026 at 6:05 AM Dev Jain <dev.jain@xxxxxxx> wrote:
>>
>>
>>
>> On 16/11/26 12:43 pm, Hao Ge wrote:
>>> The PTE loop stops only at addr == end. An unaligned end is never
>>> reached, so the loop keeps clearing past the range. An unaligned
>>> start clears the page below the range first. Both are caller bugs,
>>> and the damage is hard to attribute afterwards.
>>>
>>> vmap only installs page aligned mappings, so an unaligned unmap
>>> request is never a legitimate teardown. Warn and bail out at the
>>> entry of __vunmap_range_noflush(), before any PTE is cleared.
>>>
>>> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
>>> Closes: https://lore.kernel.org/all/sashiko-outbox-178439@xxxxxxxxxx/
>>> Signed-off-by: Hao Ge <hao.ge@xxxxxxxxx>
>>> ---
>>> mm/vmalloc.c | 3 +++
>>> 1 file changed, 3 insertions(+)
>>>
>>> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
>>> index a168f6f20f4f..e2b63cb1592b 100644
>>> --- a/mm/vmalloc.c
>>> +++ b/mm/vmalloc.c
>>> @@ -523,6 +523,9 @@ void __vunmap_range_noflush(unsigned long start, unsigned long end,
>>> pgtbl_mod_mask mask = 0;
>>>
>>> BUG_ON(addr >= end);
>>
>> Nit: It is usually a practice to change the existing BUG_ON's to
>> WARN_ON's too, if you are changing around that part.

Ack.

>>
>>
>>> + if (WARN_ON_ONCE(!PAGE_ALIGNED(addr) || !PAGE_ALIGNED(end)))
>>> + return;
>
> nit: It's also better not to combine multiple conditions into one
> warning so that the generated report clearly shows which condition
> (code line) caused the warning. IOW:

Ack on applying the same to the previous patch in the series, "mm/vmalloc:
reject an unaligned range in vmap_page_range()", as well, it is done the
same way there now.

Thanks
Best Regards
Hao

>
> if (WARN_ON_ONCE(!PAGE_ALIGNED(addr))
> return;
>
> if (WARN_ON_ONCE(!PAGE_ALIGNED(end))
> return;
>
>
>>
>> Reviewed-by: Dev Jain <dev.jain@xxxxxxx>
>
> Reviewed-by: Suren Baghdasaryan <surenb@xxxxxxxxxx>
>
>>
>>> +
>>> pgd = pgd_offset_k(addr);
>>> do {
>>> next = pgd_addr_end(addr, end);
>>