This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/2] elf: Use nocancel pread64() instead of lseek()+read()
- From: Carlos O'Donell <carlos at redhat dot com>
- To: Leandro Pereira <Leandro dot Pereira at microsoft dot com>, "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Date: Thu, 3 Oct 2019 09:59:37 -0400
- Subject: Re: [PATCH 2/2] elf: Use nocancel pread64() instead of lseek()+read()
- References: <MWHPR2101MB073287753F9E8D211AF49DD3E8DA0@MWHPR2101MB0732.namprd21.prod.outlook.com>
On 8/5/19 5:56 PM, Leandro Pereira wrote:
> Transforms this, when linking in a shared object:
>
> openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
> read(3, "\177ELF\2\1\1\3"..., 832) = 832
> lseek(3, 792, SEEK_SET) = 792
> read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68
> fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0
> lseek(3, 792, SEEK_SET) = 792
> read(3, "\4\0\0\0\24\0\0\0"..., 68) = 68
> lseek(3, 864, SEEK_SET) = 864
> read(3, "\4\0\0\0\20\0\0\0"..., 32) = 32
>
> Into this:
>
> openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
> read(3, "\177ELF\2\1\1\3"..., 832) = 832
> pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68
> fstat(3, {st_mode=S_IFREG|0755, st_size=6699224, ...}) = 0
> pread(3, "\4\0\0\0\24\0\0\0"..., 68, 792) = 68
> pread(3, "\4\0\0\0\20\0\0\0"..., 32, 864) = 32
>
> 2019-08-05 Leandro Pereira <leandro.pereira@microsoft.com>
>
> * elf/dl-load.c: Use __pread64_nocancel() instead of __lseek()+
> __read_nocancel().
> * sysdeps/x86/dl-prop.h: Likewise.
OK for master. I'll push after testing with bmg. No regressions on x86_64.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
> ---
> elf/dl-load.c | 9 +++------
> sysdeps/x86/dl-prop.h | 3 +--
> 2 files changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/elf/dl-load.c b/elf/dl-load.c
> index 5abeb867f1..462c425a13 100644
> --- a/elf/dl-load.c
> +++ b/elf/dl-load.c
> @@ -1005,8 +1005,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
> else
> {
OK. I reviewed that all uses of fd did not depend on the SEEK_SET being set to
a given position.
> phdr = alloca (maplength);
> - __lseek (fd, header->e_phoff, SEEK_SET);
> - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength) != maplength)
> + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, header->e_phoff) != maplength)
This line is too long, but I'll wrap it before commit, likewise for 2 other lines.
> {
> errstring = N_("cannot read file data");
> goto call_lose_errno;
> @@ -1659,8 +1658,7 @@ open_verify (const char *name, int fd,
> else
> {
> phdr = alloca (maplength);
> - __lseek (fd, ehdr->e_phoff, SEEK_SET);
> - if ((size_t) __read_nocancel (fd, (void *) phdr, maplength)
> + if ((size_t) __pread64_nocancel (fd, (void *) phdr, maplength, ehdr->e_phoff)
OK. Wrapped.
> != maplength)
> {
> read_error:
> @@ -1710,8 +1708,7 @@ open_verify (const char *name, int fd,
>
> abi_note = abi_note_malloced;
> }
> - __lseek (fd, ph->p_offset, SEEK_SET);
> - if (__read_nocancel (fd, (void *) abi_note, size) != size)
> + if (__pread64_nocancel (fd, (void *) abi_note, size, ph->p_offset) != size)
OK. Wrapped.
> {
> free (abi_note_malloced);
> goto read_error;
> diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
> index 1b335ccbb3..080d66a971 100644
> --- a/sysdeps/x86/dl-prop.h
> +++ b/sysdeps/x86/dl-prop.h
> @@ -167,8 +167,7 @@ _dl_process_pt_note (struct link_map *l, const ElfW(Phdr) *ph,
> note_malloced = malloc (size);
> note = note_malloced;
> }
> - __lseek (fd, ph->p_offset, SEEK_SET);
> - if (__read_nocancel (fd, (void *) note, size) != size)
> + if (__pread64_nocancel (fd, (void *) note, size, ph->p_offset) != size)
OK.
> {
> if (note_malloced)
> free (note_malloced);
>
--
Cheers,
Carlos.