Memory mapping and READ_IMPLIES_EXEC

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory mapping and READ_IMPLIES_EXEC

Schmidt, Adriaan
Hi all,

I'm running Valgrind 3.11.0 on arm32 (linux-3.18.16).
My application executes code (a) in memory it dynamically allocates (pages are mapped with PROT_READ|PROT_WRITE), and (b) in its .data section.

In both cases, running in Valgrind (--tool=none) results in a segfault because the memory pages in question are not executable.

I figured out that in native execution, my application only works because it states in its ELF header that it needs executable stacks, and Linux' way of providing this is with the READ_IMPLIES_EXEC property in the process personality, i.e., by simply making all readable memory also executable. Valgrind is more strict, and does not implement READ_IMPLIES_EXEC.

Is this a bug, so should Valgrind show the same behavior as in native execution?

Thanks,
Adriaan


------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://sdm.link/zohomanageengine
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory mapping and READ_IMPLIES_EXEC

Tom Hughes-2
On 20/06/16 09:56, Schmidt, Adriaan wrote:

> I figured out that in native execution, my application only works because it states in its ELF header that it needs executable stacks, and Linux' way of providing this is with the READ_IMPLIES_EXEC property in the process personality, i.e., by simply making all readable memory also executable. Valgrind is more strict, and does not implement READ_IMPLIES_EXEC.
>
> Is this a bug, so should Valgrind show the same behavior as in native execution?

Yes it's a bug. In your program ;-)

Even without valgrind not all platforms will do what you say to start
with - the only thing that PT_GNU_STACK in the ELF guarantees is that
the stack will have those permissions and valgrind does do that.

The read-implies-exec behaviour you describe is, in general, only true
for those CPUs (like older 32 bit x86 and ARM) that don't actually
support a separate execute permission. In the case of ARM that appears
to mean things before ARMv6 as far as I can see.

So your problem is quite likely to fail anyway when run on newer
hardware so be glad valgrind has found your problem now ;-)

Tom

--
Tom Hughes ([hidden email])
http://compton.nu/

------------------------------------------------------------------------------
What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic
patterns at an interface-level. Reveals which users, apps, and protocols are
consuming the most bandwidth. Provides multi-vendor support for NetFlow,
J-Flow, sFlow and other flows. Make informed decisions using capacity planning
reports. http://sdm.link/zohomanageengine
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users
Reply | Threaded
Open this post in threaded view
|

Re: Memory mapping and READ_IMPLIES_EXEC

Schmidt, Adriaan
> > Is this a bug, so should Valgrind show the same behavior as in native
> execution?
>
> Yes it's a bug. In your program ;-)

Thanks Tom, I agree!
I'll forward your reply to the maintainer of my application ;-)

Adriaan


------------------------------------------------------------------------------
Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San
Francisco, CA to explore cutting-edge tech and listen to tech luminaries
present their vision of the future. This family event has something for
everyone, including kids. Get more information and register today.
http://sdm.link/attshape
_______________________________________________
Valgrind-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/valgrind-users