The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Hajime Tazaki <thehajime@gmail.com>
To: akpm@linux-foundation.org, liam@infradead.org, ljs@kernel.org,
	vbabka@kernel.org, jannh@google.com, pfalcato@suse.de,
	linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, Hajime Tazaki <thehajime@gmail.com>
Subject: [PATCH] mm: nommu: add sysctl_max_map_count() check for do_mmap()
Date: Thu,  2 Jul 2026 10:28:30 +0900	[thread overview]
Message-ID: <20260702012830.667205-1-thehajime@gmail.com> (raw)

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 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.

This is detected with a LTP (Linux Test Project) test, which linked
below.

Link:
https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/syscalls/munmap/munmap04.c
Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
---
 mm/nommu.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/mm/nommu.c b/mm/nommu.c
index 5d461ddc3405..815ebefddfae 100644
--- 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);
-- 
2.43.0


             reply	other threads:[~2026-07-02  1:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  1:28 Hajime Tazaki [this message]
2026-07-05 22:10 ` [PATCH] mm: nommu: add sysctl_max_map_count() check for do_mmap() Andrew Morton
2026-07-05 22:15 ` Andrew Morton
2026-07-06  0:19   ` Hajime Tazaki
2026-07-06  0:44     ` Andrew Morton
2026-07-06  2:03       ` Hajime Tazaki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260702012830.667205-1-thehajime@gmail.com \
    --to=thehajime@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=jannh@google.com \
    --cc=liam@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=pfalcato@suse.de \
    --cc=vbabka@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox