mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michal Hocko <mhocko@kernel.org>
To: Piotr Kwapulinski <kwapulinski.piotr@gmail.com>
Cc: akpm@linux-foundation.org, cmetcalf@ezchip.com, mszeredi@suse.cz,
	viro@zeniv.linux.org.uk, dave@stgolabs.net,
	kirill.shutemov@linux.intel.com, n-horiguchi@ah.jp.nec.com,
	aarcange@redhat.com, iamjoonsoo.kim@lge.com, jack@suse.cz,
	xiexiuqi@huawei.com, vbabka@suse.cz, Vineet.Gupta1@synopsys.com,
	oleg@redhat.com, riel@redhat.com, gang.chen.5i5j@gmail.com,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	Cyril Hrubis <chrubis@suse.cz>
Subject: Re: [PATCH] mm: fix incorrect behavior when process virtual address space limit is exceeded
Date: Tue, 17 Nov 2015 01:33:24 +0100	[thread overview]
Message-ID: <20151117003324.GA1078@dhcp22.suse.cz> (raw)
In-Reply-To: <20151116205210.GB27526@dhcp22.suse.cz>

On Mon 16-11-15 21:52:10, Michal Hocko wrote:
> [CCing Cyril]
> 
> On Mon 16-11-15 18:36:19, Piotr Kwapulinski wrote:
> > When a new virtual memory area is added to the process's virtual address
> > space and this vma causes the process's virtual address space limit
> > (RLIMIT_AS) to be exceeded then kernel behaves incorrectly. Incorrect
> > behavior is a result of a kernel bug. The kernel in most cases
> > unnecessarily scans the entire process's virtual address space trying to
> > find the overlapping vma with the virtual memory region being added.
> > The kernel incorrectly compares the MAP_FIXED flag with vm_flags variable
> > in mmap_region function. The vm_flags variable should not be compared
> > with MAP_FIXED flag. The MAP_FIXED flag has got the same numerical value
> > as VM_MAYREAD flag (0x10). As a result the following test
> > from mmap_region:
> > 
> > if (!(vm_flags & MAP_FIXED))
> > is in fact:
> > if (!(vm_flags & VM_MAYREAD))
> 
> It seems this has been broken since it was introduced e8420a8ece80
> ("mm/mmap: check for RLIMIT_AS before unmapping"). The patch has fixed
> the case where unmap happened before the we tested may_expand_vm and
> failed which was sufficient for the LTP test case but it apparently
> never tried to consider the overlapping ranges to eventually allow to
> create the mapping.
> 
> > The VM_MAYREAD flag is almost always set in vm_flags while MAP_FIXED
> > flag is not so common. The result of the above condition is somewhat
> > reverted.
> > This patch fixes this bug. It causes that the kernel tries to find the
> > overlapping vma only when the requested virtual memory region has got
> > the fixed starting virtual address (MAP_FIXED flag set).
> > For tile architecture Calling mmap_region with the MAP_FIXED flag only is
> > sufficient. However the MAP_ANONYMOUS and MAP_PRIVATE flags are passed for
> > the completeness of the solution.
> 
> I found the changelog rather hard to grasp. But the fix is correct. The
> user visible effect is that RLIMIT_AS might hit for a MAP_FIXED
> mapping even though it wouldn't enlarge the used address space.

And I was obviously blind and read the condition incorrectly. Sigh...
There is no real issue in fact. We do call count_vma_pages_range even
for !MAP_FIXED case but that is merely a pointless find_vma call but
nothing really earth shattering. So nothing for the stable tree and also
quite exaggerated to be called a bug.

I am sorry about the confusion.
-- 
Michal Hocko
SUSE Labs

  reply	other threads:[~2015-11-17  0:33 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-16 17:36 Piotr Kwapulinski
2015-11-16 20:52 ` Michal Hocko
2015-11-17  0:33   ` Michal Hocko [this message]
2015-11-18 14:32   ` Cyril Hrubis
2015-11-17 16:19 ` Oleg Nesterov
2015-11-17 16:33   ` Oleg Nesterov
2015-11-17 17:26   ` [PATCH] mm/mmap.c: remove incorrect MAP_FIXED flag comparison from mmap_region Piotr Kwapulinski
2015-11-18  0:52     ` Andrew Morton
2015-11-18 16:29       ` Piotr Kwapulinski
2015-11-20 16:38         ` [PATCH v2 1/2] mm: fix incorrect behavior when process virtual address space limit is exceeded Piotr Kwapulinski
2015-11-20 16:42         ` [PATCH v2 2/2] mm/mmap.c: remove incorrect MAP_FIXED flag comparison from mmap_region Piotr Kwapulinski
2015-11-23  8:19           ` Michal Hocko
2015-11-23 17:36             ` [PATCH v3] " Piotr Kwapulinski
2015-11-23 22:14               ` Andrew Morton
2015-11-24 16:12                 ` Piotr Kwapulinski
2015-11-27  5:27               ` Naoya Horiguchi
2015-11-17 17:38   ` [PATCH] mm: fix incorrect behavior when process virtual address space limit is exceeded Chris Metcalf
2015-11-17 19:03     ` Oleg Nesterov

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=20151117003324.GA1078@dhcp22.suse.cz \
    --to=mhocko@kernel.org \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrubis@suse.cz \
    --cc=cmetcalf@ezchip.com \
    --cc=dave@stgolabs.net \
    --cc=gang.chen.5i5j@gmail.com \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=jack@suse.cz \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=kwapulinski.piotr@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mszeredi@suse.cz \
    --cc=n-horiguchi@ah.jp.nec.com \
    --cc=oleg@redhat.com \
    --cc=riel@redhat.com \
    --cc=vbabka@suse.cz \
    --cc=viro@zeniv.linux.org.uk \
    --cc=xiexiuqi@huawei.com \
    /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

all inboxes | Powered by JetHome®