From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43EB935E940 for ; Sun, 5 Jul 2026 22:10:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783289419; cv=none; b=b835JKZ5Jtg9eashgJ+f/SbyX7yn8/mFSiZ5JwkCS4xXQ3eUc3SPQOYwsyPmhgJBY8uVToLidm7igB33iRRoi9geG0yVUjT49Gs6cBqEeQ9rcQirA+bsDzO7y+o4oZrLka7IWg1PSBp0TPbr0uJZRstvjEBoRXU9xBTIo7zPRu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783289419; c=relaxed/simple; bh=suzTFwrOIxSjw2knuhUjeGbExGLtXfK2q07cfzYuEqQ=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=g8fs5YwXz+sOknx/11W9mrAnyEu0pC1SwMqAArSpk+QwfPiK0I2JMBrfuHnlZt/Du6/zFA4sSpe/msabir995t9JQqR62QvhYHfr/YeLwUQVhuC4dagd7xBIG1Q46ifcFEuzyL+4YRc0sagNcDeSse4REfUKkQp5lV40s/ulGCY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=ykhVL8NC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="ykhVL8NC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB8A91F000E9; Sun, 5 Jul 2026 22:10:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1783289418; bh=7MtM3xYRcPk6bh6LwwTUvA72moN3dLn1E91W34Wze1Q=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=ykhVL8NC7ByyCydpaQ8r7N3xU4M6Bfsyy5iiI1KqefXcAdTRQvdX1PqkTp2crVSO0 U9Anilwp261479Llfh2JRYgSKY3DoUfmK6QkcI+oxTW1UdjGBz37cjaHnGixsyY3cN 1BNWeutJJHigYUYT8cyw3IHMvkUwSeJwJLHpTDns= Date: Sun, 5 Jul 2026 15:10:17 -0700 From: Andrew Morton To: Hajime Tazaki Cc: liam@infradead.org, ljs@kernel.org, vbabka@kernel.org, jannh@google.com, pfalcato@suse.de, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: nommu: add sysctl_max_map_count() check for do_mmap() Message-Id: <20260705151017.289ed34630b503cdc1def407@linux-foundation.org> In-Reply-To: <20260702012830.667205-1-thehajime@gmail.com> References: <20260702012830.667205-1-thehajime@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 2 Jul 2026 10:28:30 +0900 Hajime Tazaki 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.