Summary: | valgrind reports invalid read/write errors on memory allocated using mmap + mprotect | ||
---|---|---|---|
Product: | [Developer tools] valgrind | Reporter: | Zoltan Varga <vargaz> |
Component: | memcheck | Assignee: | Julian Seward <jseward> |
Status: | RESOLVED DUPLICATE | ||
Severity: | normal | CC: | tom |
Priority: | NOR | ||
Version: | 3.5.0 | ||
Target Milestone: | --- | ||
Platform: | Debian unstable | ||
OS: | Linux | ||
Latest Commit: | Version Fixed In: | ||
Sentry Crash Report: |
This is on debian unstable on amd64. *** This bug has been marked as a duplicate of bug 205541 *** |
Testcase: <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <sys/mman.h> #include <stdio.h> void main () { void *ptr = mmap (NULL, getpagesize () * 16, PROT_NONE, MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); printf ("D: %p\n", ptr); mprotect (ptr, getpagesize (), PROT_READ|PROT_WRITE); *(int*)ptr = 18; printf ("%d\n", *(int*)ptr); } >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Actual results: valgrind ./a.out ==25441== Memcheck, a memory error detector ==25441== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al. ==25441== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info ==25441== Command: ./a.out ==25441== D: 0x4020000 ==25441== Invalid write of size 4 ==25441== at 0x400620: main (in /raid/home/zovarga/a.out) ==25441== Address 0x4020000 is not stack'd, malloc'd or (recently) free'd ==25441== ==25441== Invalid read of size 4 ==25441== at 0x40062A: main (in /raid/home/zovarga/a.out) ==25441== Address 0x4020000 is not stack'd, malloc'd or (recently) free'd ==25441== 18