mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Maksim Yevmenkin <maksim.yevmenkin@gmail.com>
To: Randy Dunlap <randy.dunlap@oracle.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Lee Schermerhorn <Lee.Schermerhorn@hp.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Nick Piggin <npiggin@suse.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@suse.de>,
	will@crowder-design.com, Rik van Riel <riel@redhat.com>,
	KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
	KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Subject: Re: [PATCH] Fix OOPS in mmap_region() when merging adjacent VM_LOCKED  file segments
Date: Thu, 29 Jan 2009 15:31:04 -0800	[thread overview]
Message-ID: <bb4a86c70901291531k55f52b2vf42eec4c020a7980@mail.gmail.com> (raw)
In-Reply-To: <4982324B.3050706@oracle.com>

On Thu, Jan 29, 2009 at 2:48 PM, Randy Dunlap <randy.dunlap@oracle.com> wrote:
> Maksim Yevmenkin wrote:
>> On Thu, Jan 29, 2009 at 12:48 PM, Linus Torvalds
>> <torvalds@linux-foundation.org> wrote:
>>> On Thu, 29 Jan 2009, Linus Torvalds wrote:
>>>> THIS PATCH IS TOTALLY UNTESTED!
>>> Well, it boots. FWIW. I've not really tested anything interesting with it,
>>> but any potential breakage is at least not catastrophic and immediate.
>>>
>>>> diff --git a/mm/mmap.c b/mm/mmap.c
>>>> index 8d95902..3f78ead 100644
>>>> --- a/mm/mmap.c
>>>> +++ b/mm/mmap.c
>>>> @@ -769,6 +769,10 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
>>>>       if (vm_flags & VM_SPECIAL)
>>>>               return NULL;
>>>>
>>>> +     /* Anonymous shared mappings are unsharable */
>>>> +     if ((vm_flags & VM_SHARED) && !file)
>>>> +             return NULL;
>>>> +
>>> .. and I think this part of it is actually unnecessary, because what
>>> happens is that a shared anon mapping is turned into a shmem mapping when
>>> it is inserted, and that actually ends up allocating a file for it. So the
>>> vma->vm_file for anon mappings will not match a NULL file pointer
>>> _anyway_, so there's no way it would end up merging.
>>>
>>> So my patch can be further simplified, I think, to just the following.
>>> Even more total lines removed.
>>>
>>> I still want somebody else to look at and think about it, though.
>>
>> Just to confirm. This patch also appear to fix the immediate issue for us.
>
> Is there a (small) test program available?

Yes, it was in the original (first) email. Here it is again

/*
 * Program to provoke kernel NULL pointer de-reference during
 * mmap(...MAP_LOCKED...) in Linux 2.6.28.
 *
 * 1. Create a 32KB test file in /tmp (avoids mlock limit on all recent
 *    Linuxes).
 * 2. mmap it with MAP_LOCKED from top to bottom.  (Provokes the oops,
 *    since vmas can be merged in this case.)
 * 3. Clean up.
 *
 * Compile:
 *
 *	gcc maplock-bug.c -o maplog-bug
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>

#define	SIZE	(32*1024)	/* Will get rounded down to page size if nec. */

static char tmp[] = "./maplock-bug.XXXXXX";
static char junkbuf[SIZE];

int
main(void)
{
    int fd;
    int ps = getpagesize();
    size_t sz = (SIZE / ps) * ps;
    void **addrs;
    off_t off;
    int i;

    if ((addrs = malloc((sz / ps) * sizeof (*addrs))) == 0) {
	perror("malloc");
	exit(1);
    }

    if ((fd = mkstemp(tmp)) < 0) {
	perror("mkstemp");
	exit(1);
    }

    if (write(fd, junkbuf, sz) != sz) {
	perror("write");
	exit(1);
    }

    if (close(fd) < 0) {
	perror("close");
	exit(1);
    }

    if ((fd = open(tmp, O_RDONLY)) < 0) {
	perror("open");
	exit(1);
    }

    for (off = sz - ps, i = 0; off >= 0; off -= ps, i++) {
	if ((addrs[i] =
	     mmap(0, ps, PROT_READ, MAP_SHARED|MAP_LOCKED,
		  fd, off)) == MAP_FAILED) {
	    perror("mmap");
	    exit(1);
	}

	printf("Mapped offset 0x%jx at %p\n",
	       (uintmax_t)off, addrs[i]);
    }

    if (close(fd) < 0) {
	perror("close");
	exit(1);
    }

    for (i = 0; i < sz / ps; i++) {
	if (munmap(addrs[i], ps) < 0) {
	    perror("munmap");
	    exit(1);
	}
	printf("Unmapped %p\n", addrs[i]);
    }

    if (unlink(tmp) < 0) {
	perror("unlink");
	exit(1);
    }

    printf("Done\n");
}

Thanks,
max

  reply	other threads:[~2009-01-29 23:31 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <bb4a86c70901281151w4300605r3882461cd6e9774a@mail.gmail.com>
     [not found] ` <alpine.LFD.2.00.0901281316450.3123@localhost.localdomain>
2009-01-29 20:03   ` Lee Schermerhorn
2009-01-29 20:33     ` Linus Torvalds
2009-01-29 20:48       ` Linus Torvalds
2009-01-29 22:32         ` Hugh Dickins
2009-01-29 23:02           ` Linus Torvalds
2009-01-30  4:43             ` Lee Schermerhorn
2009-01-30  4:49               ` Linus Torvalds
2009-01-29 22:47         ` Maksim Yevmenkin
2009-01-29 22:48           ` Randy Dunlap
2009-01-29 23:31             ` Maksim Yevmenkin [this message]
2009-01-30  2:08           ` Linus Torvalds
2009-01-30  5:56             ` Greg KH
2009-01-30 16:36               ` Linus Torvalds
2009-01-30 17:40                 ` Hugh Dickins
2009-01-30 18:14                   ` Linus Torvalds
2009-01-30 18:30                     ` Hugh Dickins
2009-01-30 19:53                     ` Lee Schermerhorn
2009-01-30 20:31                       ` Linus Torvalds
2009-01-30 21:12                         ` Hugh Dickins
2009-01-30 21:25                           ` Linus Torvalds
2009-01-30 21:36                           ` Lee Schermerhorn
2009-01-30 22:27                             ` Linus Torvalds
2009-01-31 12:35                               ` Hugh Dickins
2009-01-31 18:34                                 ` Linus Torvalds
2009-02-02 11:59                                   ` KOSAKI Motohiro
2009-02-02 12:54                                     ` Hugh Dickins
2009-02-02 14:10                                       ` KOSAKI Motohiro
2009-02-02 18:58                                         ` Mel Gorman
2009-02-02 19:23                                           ` Linus Torvalds
2009-02-02 21:50                                             ` Mel Gorman
2009-02-02 22:12                                               ` Linus Torvalds
2009-02-02 22:35                                                 ` Mel Gorman
2009-02-02 18:33                                       ` Mel Gorman
2009-02-03 16:13                                 ` Lee Schermerhorn
2009-02-03 16:40                                   ` Linus Torvalds
2009-02-03 17:10                                   ` Hugh Dickins
2009-02-03 21:50                                     ` Lee Schermerhorn
2009-01-30 21:37                           ` Linus Torvalds
2009-01-31 12:16                             ` Hugh Dickins
2009-01-30 20:33                       ` Hugh Dickins
2009-01-30 20:53                       ` Randy Dunlap
2009-01-30 20:59                         ` Lee Schermerhorn
2009-01-30 21:11                           ` Will Crowder
2009-01-30 23:44                   ` Greg KH
2009-01-30  8:34         ` Peter Zijlstra
2009-01-30 16:45           ` Linus Torvalds
2009-01-30 16:49             ` Randy Dunlap

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=bb4a86c70901291531k55f52b2vf42eec4c020a7980@mail.gmail.com \
    --to=maksim.yevmenkin@gmail.com \
    --cc=Lee.Schermerhorn@hp.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@suse.de \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=npiggin@suse.de \
    --cc=randy.dunlap@oracle.com \
    --cc=riel@redhat.com \
    --cc=torvalds@linux-foundation.org \
    --cc=will@crowder-design.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

Powered by JetHome