From: Florian Weimer <fweimer@redhat.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>
Subject: Re: [PATCH 2/2] elf: Detect PT_LOAD segments that extend beyond EOF and refuse loading
Date: Fri, 05 Nov 2021 16:50:37 +0100 [thread overview]
Message-ID: <87cznetxde.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <CAMe9rOpmvg0U9amZ9ZGVkbunzAAXDVj+1XF1=7yTmeeaK_G22A@mail.gmail.com> (H. J. Lu's message of "Fri, 5 Nov 2021 08:03:11 -0700")
* H. J. Lu:
> On Fri, Nov 5, 2021 at 7:41 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu:
>>
>> > So dlopen should reject it. Can you identify the broken tools which
>> > generate such input files and black list them for this test?
>>
>> It's objcopy --only-keep-debug, and it behaves as expted Separated
>> debuginfo is broken by design. The program headers do not correspond to
>> the file contents, but match the original ELF file.
>
> So the current checks aren't sufficient and your patch also checks
> file size. On x86-64, where is the first failed check? Why doesn't it
> need to check file size?
Excellent question. I should have checked this as the first thing.
On x86-64, dlopen fails with “tst-debug1mod1.so: object file has no
dynamic section.” This is because the file size is 0:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
DYNAMIC 0x000df8 0x0000000000003e10 0x0000000000003e10 0x000000 0x0001d0 RW 0x8
The dynamic segment has file size zero on aarch64, as well. But
_dl_map_segments is called before the l->l_ld check in
_dl_map_object_from_fd. Due to 64 KiB page alignment, it is more likely
that we hit the memset call there to clear a partially mapped page,
hence the crash.
We I think we can move the l->l_ld check earlier and avoid the crash.
I'll send a completely different patch.
Thanks,
Florian
next prev parent reply other threads:[~2021-11-05 15:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 13:59 [PATCH 0/2] Avoid some crashes when loading separate debuginfo Florian Weimer
2021-11-05 13:59 ` [PATCH 1/2] Use sysdeps/posix/dl-fileid.h as the generic and only implementation Florian Weimer
2021-11-08 15:54 ` H.J. Lu
2021-11-05 13:59 ` [PATCH 2/2] elf: Detect PT_LOAD segments that extend beyond EOF and refuse loading Florian Weimer
2021-11-05 14:04 ` H.J. Lu
2021-11-05 14:07 ` Florian Weimer
2021-11-05 14:26 ` H.J. Lu
2021-11-05 14:31 ` Florian Weimer
2021-11-05 14:37 ` H.J. Lu
2021-11-05 14:41 ` Florian Weimer
2021-11-05 15:03 ` H.J. Lu
2021-11-05 15:50 ` Florian Weimer [this message]
2021-11-05 14:30 ` Adhemerval Zanella
2021-11-05 14:35 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87cznetxde.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=hjl.tools@gmail.com \
--cc=libc-alpha@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).