Re: [PATCH] mm: nommu: add sysctl_max_map_count() check for do_mmap()
From: Andrew Morton
Date: Sun Jul 05 2026 - 18:10:25 EST
On Thu, 2 Jul 2026 10:28:30 +0900 Hajime Tazaki <thehajime@xxxxxxxxx> wrote:
> The sysctl variable vm.max_map_count (sysctl_max_map_count) is not
> expose under !MMU case but used it wit the default vaule
> DEFAULT_MAX_MAP_COUNT as a limit of count.
This sounds like an oversight. I see no reason why nommu users cannot
alter max_map_count.
> This is currently used when
> a vma entry is split into two chunks (split_vma()) but not used when
> allocated (do_mmap()). As a result, even if users request a large
> number of allocate memory, it will keep allocating until OOM happens.
>
> This commit introduces a check at the begining of do_mmap in nommu.c to
> prevent this situation.
>
> ...
>
> --- a/mm/nommu.c
> +++ b/mm/nommu.c
> @@ -1035,6 +1035,9 @@ unsigned long do_mmap(struct file *file,
> if (ret < 0)
> return ret;
>
> + if (current->mm->map_count >= get_sysctl_max_map_count())
> + return -ENOMEM;
> +
> /* we ignore the address hint */
> addr = 0;
> len = PAGE_ALIGN(len);
Seems sensible, thanks. That's what the !NOMMU code does.