From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 089F53858407; Tue, 9 Jan 2024 18:52:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 089F53858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1704826367; bh=BY75NGpGxVXkgk0eV30GXuE3HkhOzO7LZj074K4V0iE=; h=From:To:Subject:Date:From; b=GiJ+SeiAV0gEefJzCYqgUrPeqR6ULosBfRQy34hN79fJS9E1gN+Rg/O5XYBJqQO/Y d/sUBlx9ylm1ELJMo47JMd/lXX4TJwKH7+9JwZxN/w4upaZWn2wb68khyslvFRKvqP 48zpugBVVMFz6Es9OAhTBm3pm3HFm41EVGO3wlXo= From: "bruening at google dot com" To: elfutils-devel@sourceware.org Subject: [Bug libelf/31225] New: Crash when using elf_memory() on a compressed section; fixed with s/ELF_C_READ/ELF_C_READ_MMAP/ Date: Tue, 09 Jan 2024 18:52:46 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: elfutils X-Bugzilla-Component: libelf X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bruening at google dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31225 Bug ID: 31225 Summary: Crash when using elf_memory() on a compressed section; fixed with s/ELF_C_READ/ELF_C_READ_MMAP/ Product: elfutils Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: libelf Assignee: unassigned at sourceware dot org Reporter: bruening at google dot com CC: elfutils-devel at sourceware dot org Target Milestone: --- When setting up libelf with elf_memory() we observe repeatable crashes on a= ny compressed debug section. The problem seems to be from elf_memory() using = the ELF_C_READ command, which is not really supported: elf32_getshdr.c looks for ELF_C_READ_MMAP instead and makes a copy of read-only data in that case. Changing elf_memory() to pass ELF_C_READ_MMAP solves the problem: -------------------------------------------------------------- diff --git a/libelf/elf_memory.c b/libelf/elf_memory.c index a47f1d24..13d77cb7 100644 --- a/libelf/elf_memory.c +++ b/libelf/elf_memory.c @@ -46,5 +46,5 @@ elf_memory (char *image, size_t size) return NULL; } - return __libelf_read_mmaped_file (-1, image, 0, size, ELF_C_READ, NULL); + return __libelf_read_mmaped_file (-1, image, 0, size, ELF_C_READ_MMAP, NULL); } -------------------------------------------------------------- There seem to not be any tests of elf_memory() either so maybe there are few users and that is why no one else has hit this. More details on the crash which is hit examining ld-linux-x86-64.so.2 which= has compressed sections on this machine: -------------------------------------------------------------- Program received signal SIGSEGV, Segmentation fault.=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 0x0000555555584764 in elf_compress (scn=3Dscn@entry=3D0x5555555fa6a8, type=3Dtype@entry=3D0, flags=3Dflags@entry=3D0) at elf_compress.c:732 732 shdr->sh_size =3D scn->zdata_size;=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 (gdb) bt=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 #0 0x0000555555584764 in elf_compress (scn=3Dscn@entry=3D0x5555555fa6a8, type=3Dtype@entry=3D0, flags=3Dflags@entry=3D0) at elf_compress.c:732 #1 0x0000555555575cba in check_section (result=3Dresult@entry=3D0x5555555f= 8440, shstrndx=3Dshstrndx@entry=3D31, scn=3Dscn@entry=3D0x5555555fa6a8, inscngrp=3Dinscngrp@entry=3Dfalse) at dwarf_begin_elf.c:238=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20 #2 0x0000555555576480 in global_read (shstrndx=3D, elf=3D, result=3D0x5555555f8440) at dwarf_begin_elf.c:452 #3 dwarf_begin_elf (elf=3D0x5555555f94c0, cmd=3DDWARF_C_READ, scngrp=3D0x0= ) at dwarf_begin_elf.c:603 (gdb) list=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 727 shdr->sh_flags &=3D ~SHF_COMPRESSED;=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20 728 }=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 729 else=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 730 {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 731 Elf64_Shdr *shdr =3D elf64_getshdr (scn);=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 732 shdr->sh_size =3D scn->zdata_size;=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 733 shdr->sh_addralign =3D scn->zdata_align;=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 734 shdr->sh_flags &=3D ~SHF_COMPRESSED;=20=20=20=20=20=20=20= =20=20=20=20=20=20 735 }=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 736=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20 (gdb) p shdr=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 $1 =3D (Elf64_Shdr *) 0x7ffdf79bdc88=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20 (gdb) p *shdr=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 $2 =3D {=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20 sh_name =3D 214,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_type =3D 1,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_flags =3D 2048,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_addr =3D 0,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_offset =3D 640,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_size =3D 1151,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_link =3D 0,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_info =3D 0,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_addralign =3D 8,=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 sh_entsize =3D 0=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 }=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20 (gdb) memquery shdr=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20 7ffdf7939000-7ffdf79be000 r--p 00000000 fe:01 21499176=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20 /usr/lib/debug/.build-id/ac/cffc5784c4a469d09348e3f7ec53a74096fbd3.debug -------------------------------------------------------------- They do seem to be compressed: -------------------------------------------------------------- $ readelf -S /usr/lib/debug/.build-id/ac/cffc5784c4a469d09348e3f7ec53a74096fbd3.debug [21] .debug_aranges PROGBITS 0000000000000000 00000280 000000000000047f 0000000000000000 C 0 0 8 [22] .debug_info PROGBITS 0000000000000000 00000700 0000000000054087 0000000000000000 C 0 0 8 [23] .debug_abbrev PROGBITS 0000000000000000 00054788 000000000000451e 0000000000000000 C 0 0 8 [24] .debug_line PROGBITS 0000000000000000 00058ca8 000000000000fdbe 0000000000000000 C 0 0 8 [25] .debug_str PROGBITS 0000000000000000 00068a68 00000000000037e6 0000000000000001 MSC 0 0 8 [26] .debug_line_str PROGBITS 0000000000000000 0006c250 00000000000006fc 0000000000000001 MSC 0 0 8 [27] .debug_loclists PROGBITS 0000000000000000 0006c950 000000000000f5f2 0000000000000000 C 0 0 8 [28] .debug_rnglists PROGBITS 0000000000000000 0007bf48 00000000000026b6 0000000000000000 C 0 0 8 Key to Flags: W (write), A (alloc), X (execute), M (merge), S (strings), I (info), L (link order), O (extra OS processing required), G (group), T (TLS), C (compressed), x (unknown), o (OS specific), E (exclude), R (retain), D (mbind), l (large), p (processor specific) -------------------------------------------------------------- Is this fix we found the permanent solution? I don't know this source code: not sure why ELF_C_READ exists? Should it be removed? If not, should elf32_getshdr.c and other code consider ELF_C_READ? Do you want me to subm= it this patch plus attempt to add a test, or someone on your end will take this over? --=20 You are receiving this mail because: You are on the CC list for the bug.=