Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 120811 - Openoffice uses malloc'ed (C++ "new") heap data for executable code without setting executable permissions
Summary: Openoffice uses malloc'ed (C++ "new") heap data for executable code without s...
Status: RESOLVED UPSTREAM
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: High normal
Assignee: Gentoo Office Team
URL: http://www.openoffice.org/issues/show...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-01-29 04:39 UTC by Kevin F. Quinn (RETIRED)
Modified: 2006-02-13 23:50 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
copy of call.s - for verification that it indeed does not need executable stack (linux-intel-call.s,8.87 KB, text/plain)
2006-01-29 04:42 UTC, Kevin F. Quinn (RETIRED)
Details
add GNU-stack marking to asm, and change 'new' to call to rtl_allocateMemory in cpp2uno.cxx for linux intel (linux-intel-nx.diff,1.35 KB, patch)
2006-01-29 04:53 UTC, Kevin F. Quinn (RETIRED)
Details | Diff
Updated patch application patch (!) (gentoo-2.0.1.diff,312 bytes, text/plain)
2006-01-29 04:55 UTC, Kevin F. Quinn (RETIRED)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-29 04:39:07 UTC
Some discussion first :)

bridges/source/cpp_uno/gcc3_linux_intel/cpp2uno.cxx uses 'new' to allocate memory into which it then writes code for execution.  'new' memory only has executable permission due to the inadequacy of the pre-"NX bit" intel architecture, so it works by accident more than by design.  PaX kernels highlight this as they implement NX behaviour, whereby the heap is by default non-executable.  Future kernels may make use of the NX bit in newer architectures to set heap data non-executable by default, requiring either mprotect() or mmap() to be used to obtain executable heap data.

Execshield (RedHat) systems may also be affected, if openoffice is run with the execshield variant of NX protection.

The fix is to use either mprotect() or mmap() to get executable heap memory.  The rest of openoffice does this via the rtl_allocateMemory function provided in rtl/alloc.{c,h}.  Luckily there's an example already present in the x86_64 code bridges/source/cpp_uno/gcc3_netbsd_intel/cpp2uno.cxx which makes things simpler, so the fix is to obtain the memory in the same way.

Other systems that are similarly affected are solaris_intel, solaris_sparc, freebsd_intel, linux_powerpc, linux_sparc, macos_powerpc (basically everything except netbsd_intel, linux_s390 and linux_x86-64).  Of particular note is that linux_x86-64 already uses the rtl_memoryAllocate function, so the amd64 arch should be unaffected.  That leaves arches x86, ppc and sparc that could benefit from a fix.

Also bridges/source/cpp_uno/gcc3_linux_intel/code.s has no .note.GNUstack section, which leads libgcc3_uno.so to be marked as needing executable stack, although I think code.s does not require executable stack.
Comment 1 Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-29 04:42:15 UTC
Created attachment 78415 [details]
copy of call.s - for verification that it indeed does not need executable stack

attached here for easy reading - anyone please confirm this doesn't need executable stack :)
Comment 2 Andreas Proschofsky (RETIRED) gentoo-dev 2006-01-29 04:46:15 UTC
@Kevin: Isn't this something you should report upstream? As this is a general problem and nothing Gentoo-specific I think this should be discussed in OOo Issuezilla.
Comment 3 Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-29 04:53:09 UTC
Created attachment 78418 [details, diff]
add GNU-stack marking to asm, and change 'new' to call to rtl_allocateMemory in cpp2uno.cxx for linux intel

This patches just the linux_intel (i.e. x86) code.  This is a quick patch that should work, however upstream may prefer it to look more like the x86_64 code.

Result is that the C++ to UNO bridge should work on PaX systems with just 'm', without this it needs 'psm' which is unnecessarily broad, especially since SSP isn't compatible with OOo.

I've compiled the individual objects and shared library ok with this patch, but it'll take me a while to build the whole of openoffice.
Comment 4 Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-29 04:55:13 UTC
Created attachment 78419 [details]
Updated patch application patch (!)

This replaces files/2.0.1/gentoo-2.0.1.diff since it's much simpler that way than providing a patch to a patch.
Comment 5 Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-29 05:43:40 UTC
(In reply to comment #2)
> @Kevin: Isn't this something you should report upstream?

Yes; I figured I'd post it here to make sure I'm not talking garbage before bugging upstream :)
Comment 6 Andreas Proschofsky (RETIRED) gentoo-dev 2006-01-29 10:04:14 UTC
Just for the record: I've built OOo with your patch, looks good to me.
Comment 7 Kevin F. Quinn (RETIRED) gentoo-dev 2006-01-30 15:41:38 UTC
Thanks; built successfully here as well (takes my little machine a bit longer!)

I need to work out something that actually uses the cpp2uno bridge to test what I've done, I don't know if I have anything...
Comment 8 Andreas Proschofsky (RETIRED) gentoo-dev 2006-02-01 23:04:08 UTC
@Kevin: Just a reminder to file this upstream, to get some feedback there. Otherwise I'm a little reluctant to add this to our ebuild, as I've not got that in-depth knowledge to see if it actually breaks something ;)
Comment 9 Kevin F. Quinn (RETIRED) gentoo-dev 2006-02-02 10:03:53 UTC
Filed at http://www.openoffice.org/issues/show_bug.cgi?id=61537
Comment 10 Andreas Proschofsky (RETIRED) gentoo-dev 2006-02-02 10:58:40 UTC
Kevin, I've added myself to the upstream bug, so closing this bug here, best to keep it in one place
Comment 11 Kevin F. Quinn (RETIRED) gentoo-dev 2006-02-13 23:50:00 UTC
The upstream bug I raised (http://www.openoffice.org/issues/show_bug.cgi?id=61537) has been marked a duplicate of http://www.openoffice.org/issues/show_bug.cgi?id=47132; changed the URL to reflect this.

The assignee has set the target to 2.0.3, currently planned for May 2006.