From patchwork Tue Feb 15 14:57:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 51128 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E7F03858403 for ; Tue, 15 Feb 2022 14:57:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E7F03858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1644937073; bh=uGRrV1pkEzUkrM/bcwNpU6My1406AJHw9PNZ1+8mAb8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Dv38DqqtO1A6VOHAy91O/rELTMLEiIuYBSqCP2Wm+Aei0djRCyjdqEKLT7WOIpMSj KLJVVp/FEE0tV96hRMTaOMpRwA1QQpVkyvEGB1S75QL6WWPRycKysExMm//f81da1r Fs+YIJvkGxrubisxx70HXAnT4UV0DsyvZktpKLnk= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by sourceware.org (Postfix) with ESMTPS id 5E7C93857C67 for ; Tue, 15 Feb 2022 14:57:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E7C93857C67 Received: by mail-pj1-x1032.google.com with SMTP id d9-20020a17090a498900b001b8bb1d00e7so2332688pjh.3 for ; Tue, 15 Feb 2022 06:57:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=uGRrV1pkEzUkrM/bcwNpU6My1406AJHw9PNZ1+8mAb8=; b=KMFxpKirzoVjydUiigPYaFkAZV3BGYVGQ/WyoGgDNf0LeoK6H4VtMjQi79j2mCalVf e2B5yDTcYNiWsoZofKqC2nqZlWyyyZODDhOfUpXVeAsS+ER0gSvPfEz0k41nwg1MCYHv iWTGemtoh6gbsX6YhkzgKOl6OBaPt5Wx+M2vMk8rsBnRc5nrGgAMLHrZ+BHgaJL4Y+zV aBf+1zkw1YnpGMeylZ7NIKRSsS6OOY58Aj7supJjzfHdpFxnqxLPbf0dZrmGJlBMmNIo tj/cBzmLEUuRtIs2RlHoTLB3p1MOcpJkxNnXs6l5dsVxvwjuW7zkJXhnruMwvWBVDwVD nJfg== X-Gm-Message-State: AOAM530vzVc5dEniO8kSqciur3KYzsrYTzpPuoRjc9w/PPDYJELtFEdS xBR61BKeHZn2Rvy/umBj8eOVDFRfP9E= X-Google-Smtp-Source: ABdhPJyISj3ZeQE6r+/oPLJTF81bE7R2plpDlnuRpeQyBjlDMzu6xZ8CVxqSg+rKzX7FOre0TfKoQw== X-Received: by 2002:a17:90a:670a:: with SMTP id n10mr4680095pjj.123.1644937033400; Tue, 15 Feb 2022 06:57:13 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id pf14sm13082278pjb.16.2022.02.15.06.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 06:57:12 -0800 (PST) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id A436EC02D4; Tue, 15 Feb 2022 06:57:11 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v2] elf: Check invalid hole in PT_LOAD segments [BZ #28838] Date: Tue, 15 Feb 2022 06:57:11 -0800 Message-Id: <20220215145711.3331849-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3029.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Changes in v2: 1. Update commit log. commit 163f625cf9becbb82dfec63a29e566324129c0cd Author: H.J. Lu Date: Tue Dec 21 12:35:47 2021 -0800 elf: Remove excessive p_align check on PT_LOAD segments [BZ #28688] removed the p_align check against the page size. It caused the loader error or crash on elf/tst-p_align3 when loading elf/tst-p_alignmod3.so, which has the invalid p_align in PT_LOAD segments, added by commit d8d94863ef125a392b929732b37e07dc927fbcd1 Author: H.J. Lu Date: Tue Dec 21 13:42:28 2021 -0800 The loader failure caused by a negative length passed to __mprotect is random, depending on architecture and toolchain. Update _dl_map_segments to detect invalid holes. This fixes BZ #28838. --- elf/dl-map-segments.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/elf/dl-map-segments.h b/elf/dl-map-segments.h index b3513e7909..024175b2d5 100644 --- a/elf/dl-map-segments.h +++ b/elf/dl-map-segments.h @@ -112,6 +112,9 @@ _dl_map_segments (struct link_map *l, int fd, unallocated. Then jump into the normal segment-mapping loop to handle the portion of the segment past the end of the file mapping. */ + if (__glibc_unlikely (loadcmds[nloadcmds - 1].mapstart < + c->mapend)) + return N_("ELF load command address/offset not page-aligned"); if (__glibc_unlikely (__mprotect ((caddr_t) (l->l_addr + c->mapend), loadcmds[nloadcmds - 1].mapstart - c->mapend,