[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] execve being called with wrong path
From: |
Brian Mayer |
Subject: |
Re: [Tinycc-devel] execve being called with wrong path |
Date: |
Wed, 9 Oct 2024 12:34:52 -0300 |
Hi Yao.
> Sorry, I didn't noticed that you had disabled static libraries. Another
> way to check is simply adding a global variable in your main.c, like
>
> #include <stdio.h>
>
> int foo;
>
> void main(void) {
> printf("hello from lin0\n");
> }
>
After adding the global variable the program didn't segfault. I'm
absolutely stunned you found it.
For completion this is the readelf output:
without int foo:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: x86-64
Version: 0x1
Entry point address: 0x600478
Start of program headers: 64 (bytes into file)
Start of section headers: 1888 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 20
Section header string table index: 19
Section Headers:
[Nr] Name Type Address Off Size
ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000
000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000400200 000200
00000d 00 A 0 0 1
[ 2] .dynsym DYNSYM 0000000000400210 000210
0000a8 18 A 3 1 8
[ 3] .dynstr STRTAB 00000000004002b8 0002b8
00003c 00 A 0 0 1
[ 4] .hash HASH 00000000004002f8 0002f8
000034 04 A 2 0 8
[ 5] .gnu.hash GNU_HASH 0000000000400330 000330
000028 00 A 2 0 8
[ 6] .rela.got RELA 0000000000400358 000358
000048 18 A 2 16 8
[ 7] .rela.plt RELA 00000000004003a0 0003a0
000048 18 A 2 16 8
[ 8] .note.gnu.property NOTE 00000000004003e8 0003e8
000090 00 A 0 0 8
[ 9] .text PROGBITS 0000000000600478 000478
000037 00 AX 0 0 8
[10] .text._start_c PROGBITS 00000000006004af 0004af
000023 00 AX 0 0 1
[11] .init PROGBITS 00000000006004d2 0004d2
000003 00 AX 0 0 1
[12] .fini PROGBITS 00000000006004d5 0004d5
000003 00 AX 0 0 1
[13] .plt PROGBITS 00000000006004d8 0004d8
000040 04 AX 0 0 8
[14] .data.ro PROGBITS 0000000000800518 000518
000011 00 WA 0 0 8
[15] .dynamic DYNAMIC 0000000000800530 000530
000140 10 WA 3 0 8
[16] .got PROGBITS 0000000000800670 000670
000048 04 WA 0 0 8
[17] .data PROGBITS 0000000000a006b8 0006b8
000000 00 WA 0 0 8
[18] .bss NOBITS 0000000000a006b8 0006b8
000000 00 WA 0 0 8
[19] .shstrtab STRTAB 0000000000000000 0006b8
0000a2 00 0 0 1
Key:
(W)rite, (A)lloc, e(X)ecute, (M)erge, (S)trings, (I)nfo
(L)ink order, (O)S, (G)roup, (T)LS, (C)ompressed, x=unknown
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000400040 0x0000000000400040
0x001c0 0x001c0 R 0x4
INTERP 0x000200 0x0000000000400200 0x0000000000400200
0x0000d 0x0000d R 0x1
[Requesting program interpreter: /lib/libc.so]
LOAD 0x000000 0x0000000000400000 0x0000000000400000
0x00478 0x00478 R 0x200000
LOAD 0x000478 0x0000000000600478 0x0000000000600478
0x000a0 0x000a0 R E 0x200000
LOAD 0x000518 0x0000000000800518 0x0000000000800518
0x001a0 0x001a0 RW 0x200000
LOAD 0x0006b8 0x0000000000a006b8 0x0000000000a006b8
0x00000 0x00000 RW 0x200000
DYNAMIC 0x000530 0x0000000000800530 0x0000000000800530
0x00140 0x00140 RW 0x8
GNU_RELRO 0x000518 0x0000000000800518 0x0000000000800518
0x001a0 0x001a0 RW 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .dynsym .dynstr .hash .gnu.hash .rela.got .rela.plt
.note.gnu.property
03 .text .text._start_c .init .fini .plt
04 .data.ro .dynamic .got .data .bss
05 .data .bss
06 .dynamic
07 .data.ro .dynamic .got .data .bss
with int foo:
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: x86-64
Version: 0x1
Entry point address: 0x600478
Start of program headers: 64 (bytes into file)
Start of section headers: 1888 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 8
Size of section headers: 64 (bytes)
Number of section headers: 20
Section header string table index: 19
Section Headers:
[Nr] Name Type Address Off Size
ES Flg Lk Inf Al
[ 0] NULL 0000000000000000 000000
000000 00 0 0 0
[ 1] .interp PROGBITS 0000000000400200 000200
00000d 00 A 0 0 1
[ 2] .dynsym DYNSYM 0000000000400210 000210
0000a8 18 A 3 1 8
[ 3] .dynstr STRTAB 00000000004002b8 0002b8
00003c 00 A 0 0 1
[ 4] .hash HASH 00000000004002f8 0002f8
000034 04 A 2 0 8
[ 5] .gnu.hash GNU_HASH 0000000000400330 000330
000028 00 A 2 0 8
[ 6] .rela.got RELA 0000000000400358 000358
000048 18 A 2 16 8
[ 7] .rela.plt RELA 00000000004003a0 0003a0
000048 18 A 2 16 8
[ 8] .note.gnu.property NOTE 00000000004003e8 0003e8
000090 00 A 0 0 8
[ 9] .text PROGBITS 0000000000600478 000478
000037 00 AX 0 0 8
[10] .text._start_c PROGBITS 00000000006004af 0004af
000023 00 AX 0 0 1
[11] .init PROGBITS 00000000006004d2 0004d2
000003 00 AX 0 0 1
[12] .fini PROGBITS 00000000006004d5 0004d5
000003 00 AX 0 0 1
[13] .plt PROGBITS 00000000006004d8 0004d8
000040 04 AX 0 0 8
[14] .data.ro PROGBITS 0000000000800518 000518
000011 00 WA 0 0 8
[15] .dynamic DYNAMIC 0000000000800530 000530
000140 10 WA 3 0 8
[16] .got PROGBITS 0000000000800670 000670
000048 04 WA 0 0 8
[17] .data PROGBITS 0000000000a006b8 0006b8
000000 00 WA 0 0 8
[18] .bss NOBITS 0000000000a006b8 0006b8
000004 00 WA 0 0 8
[19] .shstrtab STRTAB 0000000000000000 0006b8
0000a2 00 0 0 1
Key:
(W)rite, (A)lloc, e(X)ecute, (M)erge, (S)trings, (I)nfo
(L)ink order, (O)S, (G)roup, (T)LS, (C)ompressed, x=unknown
Program Headers:
Type Offset VirtAddr PhysAddr
FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000400040 0x0000000000400040
0x001c0 0x001c0 R 0x4
INTERP 0x000200 0x0000000000400200 0x0000000000400200
0x0000d 0x0000d R 0x1
[Requesting program interpreter: /lib/libc.so]
LOAD 0x000000 0x0000000000400000 0x0000000000400000
0x00478 0x00478 R 0x200000
LOAD 0x000478 0x0000000000600478 0x0000000000600478
0x000a0 0x000a0 R E 0x200000
LOAD 0x000518 0x0000000000800518 0x0000000000800518
0x001a0 0x001a0 RW 0x200000
LOAD 0x0006b8 0x0000000000a006b8 0x0000000000a006b8
0x00000 0x00004 RW 0x200000
DYNAMIC 0x000530 0x0000000000800530 0x0000000000800530
0x00140 0x00140 RW 0x8
GNU_RELRO 0x000518 0x0000000000800518 0x0000000000800518
0x001a0 0x001a0 RW 0x1
Section to Segment mapping:
Segment Sections...
00
01 .interp
02 .interp .dynsym .dynstr .hash .gnu.hash .rela.got .rela.plt
.note.gnu.property
03 .text .text._start_c .init .fini .plt
04 .data.ro .dynamic .got .data
05 .data
06 .dynamic
07 .data.ro .dynamic .got .data
Which corroborates your hipotesis.
In my case I can wait for the musl fix you sent.
Many Thanks!