|
From: Marcin Ś. <mar...@gm...> - 2014-09-26 20:52:01
|
Hey,
Below is a simple program which crashes under Valgrind, but runs correctly otherwise.
It's weird artificial test case (I didn't hit it with real app), but I think it's
technically valid.
strace shows:
mmap(0x100000001, 100, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x100000000
--
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int main(void)
{
int fd = open("/dev/zero", O_RDWR);
unsigned int *v = mmap((void *)0x100000001, 100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*v = 0;
return 0;
}
--
==21563== Memcheck, a memory error detector
==21563== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==21563== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
==21563== Command: ./a.out
==21563==
==21563== Invalid write of size 4
==21563== at 0x4005CE: main (in a.out)
==21563== Address 0xffffffffffffffff is not stack'd, malloc'd or (recently) free'd
==21563==
==21563==
==21563== Process terminating with default action of signal 11 (SIGSEGV): dumping core
==21563== Access not within mapped region at address 0xFFFFFFFFFFFFFFFF
==21563== at 0x4005CE: main (in a.out)
==21563== If you believe this happened as a result of a stack
==21563== overflow in your program's main thread (unlikely but
==21563== possible), you can try to increase the size of the
==21563== main thread stack using the --main-stacksize= flag.
==21563== The main thread stack size used in this run was 8388608.
==21563==
==21563== HEAP SUMMARY:
==21563== in use at exit: 0 bytes in 0 blocks
==21563== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==21563==
==21563== All heap blocks were freed -- no leaks are possible
==21563==
==21563== For counts of detected and suppressed errors, rerun with: -v
==21563== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
|
|
From: Rich C. <rc...@wi...> - 2014-09-29 23:00:55
|
Marcin
Check the return value of mmap() and if -1, print out the
value of errno.
Also, what hardware platform is this?
I'm guessing valgrind may be inforcing an alignment that system
mmap is not.
Rich
On Fri, 26 Sep 2014 22:51:47 +0200
Marcin Ślusarz <mar...@gm...> wrote:
> Hey,
>
> Below is a simple program which crashes under Valgrind, but runs correctly otherwise.
>
> It's weird artificial test case (I didn't hit it with real app), but I think it's
> technically valid.
>
> strace shows:
> mmap(0x100000001, 100, PROT_READ|PROT_WRITE, MAP_SHARED, 3, 0) = 0x100000000
>
> --
> #include <sys/mman.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <unistd.h>
>
> int main(void)
> {
> int fd = open("/dev/zero", O_RDWR);
> unsigned int *v = mmap((void *)0x100000001, 100, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
> *v = 0;
> return 0;
> }
>
> --
>
> ==21563== Memcheck, a memory error detector
> ==21563== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
> ==21563== Using Valgrind-3.10.0 and LibVEX; rerun with -h for copyright info
> ==21563== Command: ./a.out
> ==21563==
> ==21563== Invalid write of size 4
> ==21563== at 0x4005CE: main (in a.out)
> ==21563== Address 0xffffffffffffffff is not stack'd, malloc'd or (recently) free'd
> ==21563==
> ==21563==
> ==21563== Process terminating with default action of signal 11 (SIGSEGV): dumping core
> ==21563== Access not within mapped region at address 0xFFFFFFFFFFFFFFFF
> ==21563== at 0x4005CE: main (in a.out)
> ==21563== If you believe this happened as a result of a stack
> ==21563== overflow in your program's main thread (unlikely but
> ==21563== possible), you can try to increase the size of the
> ==21563== main thread stack using the --main-stacksize= flag.
> ==21563== The main thread stack size used in this run was 8388608.
> ==21563==
> ==21563== HEAP SUMMARY:
> ==21563== in use at exit: 0 bytes in 0 blocks
> ==21563== total heap usage: 0 allocs, 0 frees, 0 bytes allocated
> ==21563==
> ==21563== All heap blocks were freed -- no leaks are possible
> ==21563==
> ==21563== For counts of detected and suppressed errors, rerun with: -v
> ==21563== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
>
> ------------------------------------------------------------------------------
> Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
> Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
> Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
> Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
> http://pubads.g.doubleclick.net/gampad/clk?id=154622311&iu=/4140/ostg.clktrk
> _______________________________________________
> Valgrind-developers mailing list
> Val...@li...
> https://lists.sourceforge.net/lists/listinfo/valgrind-developers
--
Rich Coe rc...@wi...
|
|
From: Marcin Ś. <mar...@gm...> - 2014-09-30 07:34:26
|
On Mon, Sep 29, 2014 at 06:00:46PM -0500, Rich Coe wrote: > Marcin > Check the return value of mmap() and if -1, print out the > value of errno. Indeed, it returns MAP_FAILED and sets errno to 22 (EINVAL). > Also, what hardware platform is this? amd64 (Intel Core i5) sw is Linux 3.15/glibc 2.19. > I'm guessing valgrind may be inforcing an alignment that system > mmap is not. Yeah, sounds right. Marcin |
|
From: Tom H. <to...@co...> - 2014-09-30 07:53:24
|
On 30/09/14 08:34, Marcin Ślusarz wrote:
> On Mon, Sep 29, 2014 at 06:00:46PM -0500, Rich Coe wrote:
>> Marcin
>> Check the return value of mmap() and if -1, print out the
>> value of errno.
>
> Indeed, it returns MAP_FAILED and sets errno to 22 (EINVAL).
>
>> Also, what hardware platform is this?
>
> amd64 (Intel Core i5)
>
> sw is Linux 3.15/glibc 2.19.
>
>> I'm guessing valgrind may be inforcing an alignment that system
>> mmap is not.
>
> Yeah, sounds right.
This seems to be a known feature - coregrind/m_syswrap/syswrap-generic says:
if (!VG_IS_PAGE_ALIGNED(arg1)) {
/* zap any misaligned addresses. */
/* SuSV3 says misaligned addresses only cause the MAP_FIXED case
to fail. Here, we catch them all. */
return VG_(mk_SysRes_Error)( VKI_EINVAL );
}
Best to open a bug anyway.
Tom
--
Tom Hughes (to...@co...)
http://compton.nu/
|