Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1657293 > unrolled thread

[PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications

Started byBhupesh Sharma <bhsharma@redhat.com>
First post2017-06-05 08:10 +0200
Last post2017-06-07 12:40 +0200
Articles 4 — 4 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications Bhupesh Sharma <bhsharma@redhat.com> - 2017-06-05 08:10 +0200
    Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to  1TB for 64-bit applications Daniel Micay <danielmicay@gmail.com> - 2017-06-05 14:30 +0200
      Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications Michael Ellerman <mpe@ellerman.id.au> - 2017-06-07 11:30 +0200
        Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to  1TB for 64-bit applications Bhupesh SHARMA <bhupesh.linux@gmail.com> - 2017-06-07 12:40 +0200

#1657293 — [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications

FromBhupesh Sharma <bhsharma@redhat.com>
Date2017-06-05 08:10 +0200
Subject[PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications
Message-ID<tOTnc-7Ed-9@gated-at.bofh.it>
Since 7e60d1b427c51cf2525e5d736a71780978cfb828, the ELF_ET_DYN_BASE
for powerpc applications has been set to 512MB.

Recently there have been several reports of applications SEGV'ing
and newer version of glibc also SEGV'ing (while testing) when using the following
test method:

    LD_LIBRARY_PATH=/XXX/lib /XXX/lib/ld-2.24.so <binary>

For reproducing the above, consider the following test application which
uses a larger bss:

    1.
    # cat large-bss-test-app.c
 
    	#include <stdio.h>
    	#include <unistd.h>
    	#define VECSIZE (1024 * 1024 * 100)
    
    	float p[VECSIZE], v1[VECSIZE], v2[VECSIZE];
    
    	void vec_mult(long int N) {
    		long int i;
    		for (i = 0; i < N; i++)
    			p[i] = v1[i] * v2[i];
    	}
    
    	int main() {
        		char command[1024];
    		sprintf(command,"cat /proc/%d/maps",getpid());
    		system(command);
    
       		vec_mult(VECSIZE/100);
       		printf ("Done\n");
    		return 0;
    	}
    
    2. Compile it using gcc (I am using gcc-6.3.1):
    # gcc -g -o large-bss-test-app large-bss-test-app.c
    
    3. Running the compiled application with ld.so directly is enough to trigger the SEGV
       on ppc64le/ppc64:
    # /lib64/ld-2.24.so ./large-bss-test-app 
    Segmentation fault (core dumped)
    
    4. Notice it's random depending on the layout changes, so it passes on some occassions as well:
    # /lib64/ld-2.24.so ./large-bss-test-app
    10000000-10010000 r-xp 00000000 fd:00 2883597                            /root/large-bss-test-app
    10010000-10020000 r--p 00000000 fd:00 2883597                            /root/large-bss-test-app
    10020000-10030000 rw-p 00010000 fd:00 2883597                            /root/large-bss-test-app
    10030000-5b030000 rw-p 00000000 00:00 0
    5e950000-5e990000 r-xp 00000000 fd:00 1180301                            /usr/lib64/ld-2.24.so
    5e990000-5e9a0000 r--p 00030000 fd:00 1180301                            /usr/lib64/ld-2.24.so
    5e9a0000-5e9b0000 rw-p 00040000 fd:00 1180301                            /usr/lib64/ld-2.24.so
    3fffa3680000-3fffa3860000 r-xp 00000000 fd:00 1180308                    /usr/lib64/libc-2.24.so
    3fffa3860000-3fffa3870000 r--p 001d0000 fd:00 1180308                    /usr/lib64/libc-2.24.so
    3fffa3870000-3fffa3880000 rw-p 001e0000 fd:00 1180308                    /usr/lib64/libc-2.24.so
    3fffa3890000-3fffa38b0000 r-xp 00000000 00:00 0                          [vdso]
    3fffc6740000-3fffc6770000 rw-p 00000000 00:00 0                          [stack]
    Done

One way to fix this is to move ELF_ET_DYN_BASE from 0x20000000 (512MB) to 0x10000000000 (1TB),
atleast for 64-bit applications. This allows hopefully enough space for most of the
applications without causing them to trample upon the ld.so, leading to a SEGV.

ELF_ET_DYN_BASE is still kept as 0x20000000 (512MB) for 32-bit applications to preserve their
compatibility.

After this change, the layout for the 'large-bss-test-app' changes as shown below:
    # /lib64/ld-2.24.so ./large-bss-test-app
    10000000-10010000 r-xp 00000000 fd:00 2107527                            /root/large-bss-test-app
    10010000-10020000 r--p 00000000 fd:00 2107527                            /root/large-bss-test-app
    10020000-10030000 rw-p 00010000 fd:00 2107527                            /root/large-bss-test-app
    10030000-5b030000 rw-p 00000000 00:00 0
    100283b0000-100283f0000 r-xp 00000000 fd:00 1835645                      /usr/lib64/ld-2.24.so
    100283f0000-10028400000 r--p 00030000 fd:00 1835645                      /usr/lib64/ld-2.24.so
    10028400000-10028410000 rw-p 00040000 fd:00 1835645                      /usr/lib64/ld-2.24.so
    7fff8a470000-7fff8a650000 r-xp 00000000 fd:00 1835652                    /usr/lib64/libc-2.24.so
    7fff8a650000-7fff8a660000 r--p 001d0000 fd:00 1835652                    /usr/lib64/libc-2.24.so
    7fff8a660000-7fff8a670000 rw-p 001e0000 fd:00 1835652                    /usr/lib64/libc-2.24.so
    7fff8a680000-7fff8a6a0000 r-xp 00000000 00:00 0                          [vdso]
    7fffc6d90000-7fffc6dc0000 rw-p 00000000 00:00 0                          [stack]
    Done

Cc: Anton Blanchard <anton@samba.org>
Cc: Daniel Cashman <dcashman@android.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Michael Ellerman <mpe@ellerman.id.au> 
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Bhupesh Sharma <bhsharma@redhat.com>
---
 arch/powerpc/include/asm/elf.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
index 09bde6e..683230c 100644
--- a/arch/powerpc/include/asm/elf.h
+++ b/arch/powerpc/include/asm/elf.h
@@ -28,7 +28,9 @@
    the loader.  We need to make sure that it is out of the way of the program
    that it will "exec", and that there is sufficient room for the brk.  */
 
-#define ELF_ET_DYN_BASE	0x20000000
+/* Keep this as 512MB for 32-bit applications and 1TB for 64-bit ones */
+#define ELF_ET_DYN_BASE	(test_thread_flag(TIF_32BIT) ? \
+			 0x20000000 : 0x10000000000)
 
 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
 
-- 
2.7.4

[toc] | [next] | [standalone]


#1657549 — Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications

FromDaniel Micay <danielmicay@gmail.com>
Date2017-06-05 14:30 +0200
SubjectRe: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications
Message-ID<tOZiV-2Qj-17@gated-at.bofh.it>
In reply to#1657293
Rather than doing this, the base should just be split for an ELF
interpreter like PaX. It makes sense for a standalone executable to be
as low in the address space as possible. Doing that ASAP fixes issues
like this and opens up the possibility of fixing stack mapping ASLR
entropy on various architectures. It should be a pretty small change.

[toc] | [prev] | [next] | [standalone]


#1659587 — Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications

FromMichael Ellerman <mpe@ellerman.id.au>
Date2017-06-07 11:30 +0200
SubjectRe: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications
Message-ID<tPFrQ-4M0-19@gated-at.bofh.it>
In reply to#1657549
Daniel Micay <danielmicay@gmail.com> writes:

> Rather than doing this, the base should just be split for an ELF
> interpreter like PaX.

I don't quite parse that, I think you mean PaX uses a different base for
an ELF interpreter vs a regular ET_DYN?

That would be cool. How do you know that it's an ELF interpreter you're
loading? Is it just something that's PIE but doesn't request an
interpreter?

Is the PaX code somewhere I can look at?

> It makes sense for a standalone executable to be as low in the address
> space as possible.

More or less. There are performance reasons why 1T could be good for us,
but I want to see some performance numbers to justify that change. And
it does mean you have a bit less address space to play with.

cheers

[toc] | [prev] | [next] | [standalone]


#1659662 — Re: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications

FromBhupesh SHARMA <bhupesh.linux@gmail.com>
Date2017-06-07 12:40 +0200
SubjectRe: [kernel-hardening] [PATCH] powerpc: Increase ELF_ET_DYN_BASE to 1TB for 64-bit applications
Message-ID<tPGxA-5qX-13@gated-at.bofh.it>
In reply to#1659587
On Wed, Jun 7, 2017 at 2:59 PM, Michael Ellerman <mpe@ellerman.id.au> wrote:
> Daniel Micay <danielmicay@gmail.com> writes:
>
>> Rather than doing this, the base should just be split for an ELF
>> interpreter like PaX.
>
> I don't quite parse that, I think you mean PaX uses a different base for
> an ELF interpreter vs a regular ET_DYN?

I am also not very conversant with PaX. AFAIU, we can use the
following methods to print the shared object dependencies instead of
ldd:

1. One can load the binary directly with LD_TRACE_LOADED_OBJECTS=1.

So, instead of:

# /lib64/ld-2.24.so ./large-bss-test-app
Segmentation fault (core dumped)

One can do:
# LD_TRACE_LOADED_OBJECTS=1 ./large-bss-test-app
        linux-vdso64.so.1 (0x00007fffa67a0000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fffa6590000)
        /lib64/ld64.so.2 (0x00007fffa67c0000)

2. There are other utils like pax-utils etc that we can use.

But, we generally cannot force a user to not use ldd to determine the
shared object dependencies, especially when all the documentation
points to it and it works well on the other archs like x86 and arm64.

> That would be cool. How do you know that it's an ELF interpreter you're
> loading? Is it just something that's PIE but doesn't request an
> interpreter?
>
> Is the PaX code somewhere I can look at?
>
>> It makes sense for a standalone executable to be as low in the address
>> space as possible.
>
> More or less. There are performance reasons why 1T could be good for us,
> but I want to see some performance numbers to justify that change. And
> it does mean you have a bit less address space to play with.

Do you have any specific performance test(s) in mind which I can run
to see how the 1TB impacts them? I am trying to run ltp after this
change and will be able to share the results shortly, but I am not
sure it provides the right data to validate such a change.

Regards,
Bhupesh

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web