All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vasileios Karakasis <bkk@cslab.ece.ntua.gr>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, linux-numa@vger.kernel.org
Subject: [BUG] Invalid return address of mmap() followed by mbind() in multithreaded context
Date: Fri, 17 Jun 2011 18:21:49 +0300	[thread overview]
Message-ID: <4DFB710D.7000902@cslab.ece.ntua.gr> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 1747 bytes --]

Hi,

I am implementing a multithreaded numa aware code where each thread
mmap()'s an anonymous private region and then mbind()'s it to its local
node. The threads are performing a series of such mmap() + mbind()
operations. My program crashed with SIGSEGV and I noticed that mmap()
returned an invalid address.

I am sending you a simple program that reproduces the error. The program
creates two threads and each thread starts allocating pages and then
binds them to the local node 0. After a number of iterations the program
crashes as it tries to dereference the address returned by mmap(). The
bug doesn't come up when using a single thread, neither when using only
mmap().

I am running a 2.6.39.1 kernel on a 64-bit dual-core machine, but I
tracked this bug back down to the 2.6.34.9 version.

This bug also affects libnuma.

Regards,
-- 
V.K.


#include <assert.h>
#include <sys/mman.h>
#include <pthread.h>
#include <numaif.h>

#define NR_ITER 10240
#define PAGE_SIZE 4096

void *thread_func(void *args)
{
    unsigned char *addr;
    int err, i;
    unsigned long node = 0x1;

    for (i = 0; i < NR_ITER; i++) {
        addr = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE,
                    MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
        if (addr == (void *) -1) {
            assert(0 && "mmap failed");
        }
        *addr = 0;

        err = mbind(addr, PAGE_SIZE, MPOL_BIND, &node, sizeof(node), 0);
        if (err < 0) {
            assert(0 && "mbind failed");
        }
    }
    return (void *) 0;
}

int main(void)
{
    pthread_t thread;
    pthread_create(&thread, NULL, thread_func, NULL);
    thread_func(NULL);
    pthread_join(thread, NULL);
    return 0;
}

[-- Attachment #1.2: 0x17A67A9C.asc --]
[-- Type: application/pgp-keys, Size: 2859 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

             reply	other threads:[~2011-06-17 15:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-17 15:21 Vasileios Karakasis [this message]
2011-06-18 18:12 ` [BUG] Invalid return address of mmap() followed by mbind() in multithreaded context Andi Kleen
2011-06-18 18:12   ` Andi Kleen
2011-06-18 18:41   ` Vasileios Karakasis
2011-06-19 23:42     ` Vasileios Karakasis
2011-06-27 17:18 ` Kornilios Kourtis
2011-06-27 17:18   ` Kornilios Kourtis
2011-06-28  2:06   ` KOSAKI Motohiro
2011-06-28  2:06     ` KOSAKI Motohiro

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=4DFB710D.7000902@cslab.ece.ntua.gr \
    --to=bkk@cslab.ece.ntua.gr \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=linux-numa@vger.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.