From patchwork Mon Aug 5 21:56:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leandro Pereira X-Patchwork-Id: 33975 Received: (qmail 116178 invoked by alias); 5 Aug 2019 21:56:07 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 116170 invoked by uid 89); 5 Aug 2019 21:56:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-HELO: NAM03-CO1-obe.outbound.protection.outlook.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PB8XqFtIEnfz3IGxgEQplhQrmpWHtIWLBwWp9dl5ezSMEU2luKboWzF7Z8CX7L8XOk3fNrjJily1bKM+szL82ilzNegxY1JVN4vWdGVwXQTjTnCu4Vtth49pUEIVpXaayCSSZ7dCB49uGmEHma9cbYBQtqs6HBBR7BKf8Okn+eSrxvclB7ZZ81Ld1KeskrzrBME/VnGR73hKPAVUk8LzpzUZYfcUwOJ2TPxrAOVrHYp+YcmzpSzNqJurBfXAjb9TSMnxjTza33sjubenyARP/GO1e+P0kAdxC0ciBkhhRXg2E4IbE2pVU7FEz+lkqFiRN01xmwhFak8xJciKClV11w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O22ROZjOWstbdLYaavw746AHHNmkFgkxnmdWlj5ha14=; b=FEZNK+c5PFsOTGooWKfrrr95gWdvLZXGQwKSWkvb2PWnFIsWMLqqrC/CAYbj9DCZFa+FjCPtpiTEdfCm3Zo22aV6JaG5lGv0gCyR1YphywTS3CbgQRsfNYjS9V2Y1U8Teso7FJP9vvWnAC7kBz9E8emgkk8aKkfCUZgf9JV+aqo5vlnK6KuykVyGaAbNFA0x7FCiVuixREvCeOUJw5wylB2XeApnex7ZnP6t8WHDETpfdIGDVewm2wgOIaCKKNek28XUsNCwYeHBVjgTrfAg72bYcaXyAXnZ+r97gQ9LObkxefKf18rrkfI+sf05C6nuAOHwgft4wp8subP89rzyug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microsoft.com; dmarc=pass action=none header.from=microsoft.com; dkim=pass header.d=microsoft.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=O22ROZjOWstbdLYaavw746AHHNmkFgkxnmdWlj5ha14=; b=V1MWsELWzmvapcO6mfGdlu5KEd4ZizRwmIs++xIhOYyTlOiEa0xDCvL7aavQsEkrrE9q7kAGes6+j2vKUvyebqmO3BP5MULlgFZlJXWVkYxW9RiZ0Xx6p375jtlyWWqphZVveGaG5DCiiTg0S/nJabIlgelH2wcFFD4m3RLBWbY= From: Leandro Pereira To: "libc-alpha@sourceware.org" Subject: [PATCH 2/2] elf: Use nocancel pread64() instead of lseek()+read() Date: Mon, 5 Aug 2019 21:56:03 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Leandro.Pereira@microsoft.com; x-ms-oob-tlc-oobclassifiers: OLM:1443; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Emgg1wxuqW20iy/11si/edqDRb9TjAMPZ3tUmXZ1JITQI89E8f/7hBegPL3aYKRjxUwBho+Nfg490hIrfXA6YQ== 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 * elf/dl-load.c: Use __pread64_nocancel() instead of __lseek()+ __read_nocancel(). * sysdeps/x86/dl-prop.h: Likewise. Reviewed-by: Carlos O'Donell --- 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 { 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) { 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) != 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) { 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) { if (note_malloced) free (note_malloced);