Skip to contentSkip to conversation

Remove -static from Documentation/lguest/Makefile

PATCH In review S.Çağlar Onur 3 participants 8 messages Jul 19, 2007 – Jul 22, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove -static from Documentation/lguest/Makefile

Hi;

Remove -static from Documentation/lguest/Makefile, most distros only provides shared library form of zlib in their default installation. And shared linking also provides litte tiny security for hypotetical security problems will be introduced by zlib :).

Documentation/lguest/Makefile | 2 +-

 1 files changed, 1 insertions(+), 1 deletions(-)
Documentation/lguest/Makefile +1 -1
index b9b9427..2331179 100644
@@ -12,7 +12,7 @@ include $(KBUILD_OUTPUT)/.config
 LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000)
 
 CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \
-	-static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
+	-DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
 LDLIBS:=-lz
 
 all: lguest.lds lguest

Cheers

Signature · 4 lines
S.Çağlar Onur <[email protected]>
http://cekirdek.pardus.org.tr/~caglar/

Linux is like living in a teepee. No Windows, no Gates and an Apache in house!
#1 lore raw
Quoted 4 lines · S.Çağlar Onur

Hi;

Remove -static from Documentation/lguest/Makefile, most distros only provides shared library form of zlib in their default installation. And shared linking also provides litte tiny security for hypotetical security problems will be introduced by zlib :).

Unfortunately, this introduces a security hole. See, the guest can access all memory up to LGUEST_GUEST_TOP, or 0xB8000000 on my machine. Without -static, we look like this:

Quoted 1 line

cat /proc/4137/maps

b7e0b000-b7e0d000 rw-p b7e0b000 00:00 0

b7e0d000-b7f35000 r-xp 00000000 03:03 17069      /lib/tls/libc-2.3.6.so
b7f35000-b7f3a000 r--p 00127000 03:03 17069      /lib/tls/libc-2.3.6.so
b7f3a000-b7f3c000 rw-p 0012c000 03:03 17069      /lib/tls/libc-2.3.6.so

b7f3c000-b7f3f000 rw-p b7f3c000 00:00 0
b7f3f000-b7f52000 r-xp 00000000 03:03 389723 /usr/lib/libz.so.1.2.3
b7f52000-b7f53000 rw-p 00012000 03:03 389723 /usr/lib/libz.so.1.2.3
b7f5b000-b7f5d000 rw-p b7f5b000 00:00 0

b7f5d000-b7f5e000 r-xp b7f5d000 00:00 0          [vdso]
b7f5e000-b7f73000 r-xp 00000000 03:03 16351      /lib/ld-2.3.6.so
b7f73000-b7f75000 rw-p 00014000 03:03 16351      /lib/ld-2.3.6.so

b8000000-b8004000 r-xp 00000000 03:04
2485028 /home/rusty/linux-2.6.22-git13/Documentation/lguest/lguest
b8004000-b8005000 rw-p 00004000 03:04
2485028 /home/rusty/linux-2.6.22-git13/Documentation/lguest/lguest
bfecd000-bfee3000 rw-p bfecd000 00:00 0 [stack]

Whee! Guest can overwrite our libc, libz, ld.so. Also, we allocate pages for virtual devices from B8000000 down, so we might not run very far if we've blatted those libraries.

The correct solution is to allocate upwards, and then hand the top address we got to the kernel as the highest accessible guest address.

How's this?
===
Link lguest example launcher non-static

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The solution is to pre-scan the args to figure out how much memory we have, then allocate devices above that, rather than down from the top.

Documentation/lguest/Makefile +1 -2
diff -r d9973bf15010 Documentation/lguest/Makefile
@@ -11,8 +11,7 @@ include $(KBUILD_OUTPUT)/.config
 include $(KBUILD_OUTPUT)/.config
 LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000)
 
-CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \
-	-static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
+CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 -Wl,-T,lguest.lds
 LDLIBS:=-lz
 
 all: lguest.lds lguest
Documentation/lguest/lguest.c +36 -52

153 lines not on this page · raw message

#2 lore raw
In reply to S.Çağlar Onur
Quoted 4 lines · S.Çağlar Onur

Hi;

Remove -static from Documentation/lguest/Makefile, most distros only provides shared library form of zlib in their default installation. And shared linking also provides litte tiny security for hypotetical security problems will be introduced by zlib :).

Unfortunately, this introduces a security hole. See, the guest can access all memory up to LGUEST_GUEST_TOP, or 0xB8000000 on my machine. Without -static, we look like this:

Quoted 1 line

cat /proc/4137/maps

b7e0b000-b7e0d000 rw-p b7e0b000 00:00 0

b7e0d000-b7f35000 r-xp 00000000 03:03 17069      /lib/tls/libc-2.3.6.so
b7f35000-b7f3a000 r--p 00127000 03:03 17069      /lib/tls/libc-2.3.6.so
b7f3a000-b7f3c000 rw-p 0012c000 03:03 17069      /lib/tls/libc-2.3.6.so

b7f3c000-b7f3f000 rw-p b7f3c000 00:00 0
b7f3f000-b7f52000 r-xp 00000000 03:03 389723 /usr/lib/libz.so.1.2.3
b7f52000-b7f53000 rw-p 00012000 03:03 389723 /usr/lib/libz.so.1.2.3
b7f5b000-b7f5d000 rw-p b7f5b000 00:00 0

b7f5d000-b7f5e000 r-xp b7f5d000 00:00 0          [vdso]
b7f5e000-b7f73000 r-xp 00000000 03:03 16351      /lib/ld-2.3.6.so
b7f73000-b7f75000 rw-p 00014000 03:03 16351      /lib/ld-2.3.6.so

b8000000-b8004000 r-xp 00000000 03:04
2485028 /home/rusty/linux-2.6.22-git13/Documentation/lguest/lguest
b8004000-b8005000 rw-p 00004000 03:04
2485028 /home/rusty/linux-2.6.22-git13/Documentation/lguest/lguest
bfecd000-bfee3000 rw-p bfecd000 00:00 0 [stack]

Whee! Guest can overwrite our libc, libz, ld.so. Also, we allocate pages for virtual devices from B8000000 down, so we might not run very far if we've blatted those libraries.

The correct solution is to allocate upwards, and then hand the top address we got to the kernel as the highest accessible guest address.

How's this?
===
Link lguest example launcher non-static

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The solution is to pre-scan the args to figure out how much memory we have, then allocate devices above that, rather than down from the top.

Documentation/lguest/Makefile +1 -2
diff -r d9973bf15010 Documentation/lguest/Makefile
@@ -11,8 +11,7 @@ include $(KBUILD_OUTPUT)/.config
 include $(KBUILD_OUTPUT)/.config
 LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000)
 
-CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \
-	-static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
+CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 -Wl,-T,lguest.lds
 LDLIBS:=-lz
 
 all: lguest.lds lguest
Documentation/lguest/lguest.c +36 -52

153 lines not on this page · raw message

#3 lore raw
Quoted 11 lines · Rusty Russell

How's this?
===
Link lguest example launcher non-static

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The solution is to pre-scan the args to figure out how much memory we have, then allocate devices above that, rather than down from the top.

The technique I used in Valgrind was to have a small core program which links up high, which then uses mmap to reserve all the client (guest) address space, and then dlopens any other libraries, which are guaranteed to be loaded high.

There are a number of subtleties, of course. You need to make the initial stub static, but some versions of glibc have difficulties with having static programs use dlopen. And it means you need to use dlsym and do all your library function accesses indirectly, which may not be a problem for a relatively simple library like libz.

J

#4 lore raw
Quoted 14 lines · Jeremy Fitzhardinge
Quoted 7 lines · Rusty Russell

How's this?
===
Link lguest example launcher non-static

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The technique I used in Valgrind was to have a small core program which links up high, which then uses mmap to reserve all the client (guest) address space, and then dlopens any other libraries, which are guaranteed to be loaded high.

Quoted 5 lines

There are a number of subtleties, of course. You need to make the initial stub static, but some versions of glibc have difficulties with having static programs use dlopen. And it means you need to use dlsym and do all your library function accesses indirectly, which may not be a problem for a relatively simple library like libz.

The other option is to simply mmap the memory and device descriptors, then tell the kernel the offset. This means no more linking tricks at all, but I'd have to check what limit this would impose on maximum guest physical memory.

And such a significant change is not 2.6.23 material, of course. Rusty.

#5 lore raw
In reply to Jeremy Fitzhardinge
Quoted 14 lines · Jeremy Fitzhardinge
Quoted 7 lines · Rusty Russell

How's this?
===
Link lguest example launcher non-static

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The technique I used in Valgrind was to have a small core program which links up high, which then uses mmap to reserve all the client (guest) address space, and then dlopens any other libraries, which are guaranteed to be loaded high.

Quoted 5 lines

There are a number of subtleties, of course. You need to make the initial stub static, but some versions of glibc have difficulties with having static programs use dlopen. And it means you need to use dlsym and do all your library function accesses indirectly, which may not be a problem for a relatively simple library like libz.

The other option is to simply mmap the memory and device descriptors, then tell the kernel the offset. This means no more linking tricks at all, but I'd have to check what limit this would impose on maximum guest physical memory.

And such a significant change is not 2.6.23 material, of course. Rusty.

#6 lore raw

PATCH 1/1 Make lguest example launcher non-static and simplify

In reply to Rusty Russell

Linus, please apply.

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The solution is to pre-scan the args to figure out how much memory we have, then allocate devices above that, rather than down from the top possible address. This also turns out to be simpler.

---
 Documentation/lguest/Makefile |    3 -
 Documentation/lguest/lguest.c |   88 ++++++++++++++++-------------------------
 2 files changed, 37 insertions(+), 54 deletions(-)

===================================================================

Documentation/lguest/Makefile +1 -2
@@ -11,8 +11,7 @@ include $(KBUILD_OUTPUT)/.config
 include $(KBUILD_OUTPUT)/.config
 LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000)
 
-CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \
-	-static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
+CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 -Wl,-T,lguest.lds
 LDLIBS:=-lz
 
 all: lguest.lds lguest

===================================================================

Documentation/lguest/lguest.c +36 -52

153 lines not on this page · raw message

#7 lore raw

PATCH 1/1 Make lguest example launcher non-static and simplify

In reply to Rusty Russell

Linus, please apply.

S.Caglar Onur points out that many distributions don't ship a static zlib. Unfortunately the launcher currently maps virtual device memory where shared libraries want to go.

The solution is to pre-scan the args to figure out how much memory we have, then allocate devices above that, rather than down from the top possible address. This also turns out to be simpler.

---
 Documentation/lguest/Makefile |    3 -
 Documentation/lguest/lguest.c |   88 ++++++++++++++++-------------------------
 2 files changed, 37 insertions(+), 54 deletions(-)

===================================================================

Documentation/lguest/Makefile +1 -2
@@ -11,8 +11,7 @@ include $(KBUILD_OUTPUT)/.config
 include $(KBUILD_OUTPUT)/.config
 LGUEST_GUEST_TOP := ($(CONFIG_PAGE_OFFSET) - 0x08000000)
 
-CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 \
-	-static -DLGUEST_GUEST_TOP="$(LGUEST_GUEST_TOP)" -Wl,-T,lguest.lds
+CFLAGS:=-Wall -Wmissing-declarations -Wmissing-prototypes -O3 -Wl,-T,lguest.lds
 LDLIBS:=-lz
 
 all: lguest.lds lguest

===================================================================

Documentation/lguest/lguest.c +36 -52

153 lines not on this page · raw message