Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <b8d3e5fa-afb1-67ba-d2a4-3102761d7ccc@mirbsd.de>
Date: Mon, 3 Mar 2025 11:47:35 +0100 (CET)
From: Thorsten Glaser <tg@...bsd.de>
To: musl@...ts.openwall.com
cc: Dmitry Vyukov <dvyukov@...gle.com>
Subject: Re: Support for -static-pie relocations

On Sat, 1 Mar 2025, Rich Felker wrote:

>I don't think we've hit that on x86_64, and it was long ago fixed on
>the archs we did hit it on, so I don't think that's what's going on.

I use static-pie for mksh/musl builds on Debian, so I can report
what works for me and what doesn’t.

Using musl 1.2.5 on: amd64, arm64, armel, armhf, i386, loong64,
m68k, mips64el, ppc64el, riscv64, s390x, sh4

(For mips64el I’m still patching the specs file as elaborated in
the earlier thread on this list or Debian #1050429.)

Test program:

	#include <stdio.h>
	int main(void) {
		printf("main = 0x%lX\n", (unsigned long)main);
		return (0);
	}

Test compilation:

	musl-gcc -fPIE -static -static-pie -fno-lto -Wl,-z,text \
	    -o t.exe t.c && test -x t.exe

For some reason, all three of -fPIE -static -static-pie are needed
(I put -fPIE into CFLAGS and -static -static-pie -Wl,-z,text into
LDFLAGS if the test succeeds).

Then, the following is tested:

	x1=$(./t.exe)
	x2=$(./t.exe)
	x3=$(./t.exe)
	x4=$(./t.exe)
	if test x"$x1" = x"$x2" && test x"$x2" = x"$x3" && \
	   test x"$x3" = x"$x4"; then
		x5=0
	elif test -z "$x1"; then
		x5=0
	else
		x5=1
	fi
	x6=$(env LC_ALL=C file t.exe)
	case $x6 in
	(*', static-pie linked'*)
		x7=1 ;;
	(*'pie executable'*)
		echo >&2 "W: file(1) does not report static-pie, guessing"
		x7=1 ;;
	(*executable*)
		x7=0 ;;
	(*)
		x7=2 ;;
	esac

(Basically, whether a test program can be built, run, reports
different locations for main in each run, and whether file(1)
says it is indeed static-pie.)

Afterwards, the results:

• amd64: works
• arm64: works
• armel: works
• armhf: works
• i386: works
• loong64: works
• m68k: fails, see below
• mips64el: works
• ppc64el: works
• riscv64: musl static-pie blacklisted due to #1068350
• s390x: musl static-pie blacklisted due to #1068350
• sh4: fails to ASLR, see below

‣ m68k:

| qemu: uncaught target signal 11 (Segmentation fault) - core dumped
| Segmentation fault

Compilation seemed to succeed though:

| t.exe: ELF 32-bit MSB pie executable, Motorola m68k, 68020, version 1 (SYSV), static-pie linked, with debug_info, not stripped

‣ sh4:

| main = 0x40000674
| main = 0x40000674
| main = 0x40000674
| main = 0x40000674

| t.exe: ELF 32-bit LSB pie executable, Renesas SH, version 1 (SYSV), static-pie linked, with debug_info, not stripped

‣ riscv64, s390x

The last messages on the bugreport were also sent to this list,
<Pine.BSM.4.64L.2404061513110.25918@...c.mirbsd.org> being the
last one with a question I posed nobody seems to have had an idea
how to answer.

Good however is: all architectures marked as “works” above have
all tests passing, so things seem to work.

bye,
//mirabilos
-- 
11:56⎜«liwakura:#!/bin/mksh» also, i wanted to add mksh to my own distro │
i was disappointed that there is no makefile │ but somehow the Build.sh is
the least painful built system i've ever seen │ honours CC, {CPP,C,LD}FLAGS
properly │ looks cleary like done by someone who knows what they are doing

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.