From: Vasileios Karakasis <bkk@cslab.ece.ntua.gr>
To: Andi Kleen <andi@firstfloor.org>
Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-numa@vger.kernel.org
Subject: Re: [BUG] Invalid return address of mmap() followed by mbind() in multithreaded context
Date: Mon, 20 Jun 2011 02:42:26 +0300 [thread overview]
Message-ID: <4DFE8962.3060305@cslab.ece.ntua.gr> (raw)
In-Reply-To: <4DFCF13F.50401@cslab.ece.ntua.gr>
[-- Attachment #1: Type: text/plain, Size: 2405 bytes --]
I'm sending you a slightly modified version that actually makes clear
how libnuma is affected. If you compile with -DUSE_LIBNUMA, you will get
an EFAULT from mbind() and then crash.
This is the gdb output where the address passed to mbind() is invalid.
(gdb) r
Starting program: a.out
[Thread debugging using libthread_db enabled]
[New Thread 0x7ffff7633700 (LWP 17977)]
a.out: mmap-bug.c:29: thread_func: Assertion `0 && "mbind() failed"' failed.
Program received signal SIGABRT, Aborted.
0x00007ffff7667a75 in *__GI_raise (sig=<value optimized out>)
at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in ../nptl/sysdeps/unix/sysv/linux/raise.c
(gdb) f 3
#3 0x00000000004007b8 in thread_func (args=0x0) at mmap-bug.c:29
29 assert(0 && "mbind() failed");
(gdb) p addr
$1 = (unsigned char *) 0x7ffff5c27000 <Address 0x7ffff5c27000 out of bounds>
#include <assert.h>
#include <sys/mman.h>
#include <pthread.h>
#include <numa.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++) {
#ifdef USE_LIBNUMA
addr = numa_alloc_onnode(PAGE_SIZE, 0);
#else
addr = mmap(0, PAGE_SIZE, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, 0, 0);
if (addr == (void *) -1)
assert(0 && "mmap() failed");
err = mbind(addr, PAGE_SIZE, MPOL_BIND, &node, sizeof(node), 0);
if (err < 0)
assert(0 && "mbind() failed");
#endif
*addr = 0;
}
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;
}
On 06/18/2011 09:41 PM, Vasileios Karakasis wrote:
> That's right, but what I want to demonstrate is that the address
> returned by mmap() is invalid and the dereference crashes the program,
> while it shouldn't. I could equally omit this statement, in which case
> mbind() would fail with EFAULT.
>
> On 06/18/2011 09:12 PM, Andi Kleen wrote:
>>
>> mbind() can be only done before the first touch. you're not actually testing
>> numa policy.
>>
>> -andi
>
--
V.K.
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
next prev parent reply other threads:[~2011-06-19 23:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-17 15:21 [BUG] Invalid return address of mmap() followed by mbind() in multithreaded context Vasileios Karakasis
2011-06-18 18:12 ` Andi Kleen
2011-06-18 18:41 ` Vasileios Karakasis
2011-06-19 23:42 ` Vasileios Karakasis [this message]
2011-06-27 17:18 ` Kornilios Kourtis
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=4DFE8962.3060305@cslab.ece.ntua.gr \
--to=bkk@cslab.ece.ntua.gr \
--cc=andi@firstfloor.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).