From patchwork Tue Dec 21 21:54:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 49162 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 82C8A3858406 for ; Tue, 21 Dec 2021 21:55:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82C8A3858406 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1640123748; bh=eY2nd1J7msAI7uD/At3h0btMFJLJj1jrK/RM2MqB9L4=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=K8hGvcdYGyn5f3Em7RMl4uUZUL26j7mTuqwqcmusm9TqQs8CgyYt4h9qxWhPA22SY hYjuZGa0kg0bGI+j/2FAtLY1KHCyiqRP8cVFTfmvm0UFYGYd1excI5mh3kkRInzJpy mIHFTi35i9Yaetzl/BXHBiHhSJu3lM/v53C0tQJs= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id AF3CA3858401 for ; Tue, 21 Dec 2021 21:54:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AF3CA3858401 Received: by mail-pl1-x62c.google.com with SMTP id y7so326263plp.0 for ; Tue, 21 Dec 2021 13:54:45 -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:in-reply-to :references:mime-version:content-transfer-encoding; bh=eY2nd1J7msAI7uD/At3h0btMFJLJj1jrK/RM2MqB9L4=; b=Km6CwxoZXAQSqFo2EV9YzBbtHED1MlQ/GM/GQpxxeKhzXKj1LgPCr6pfgXSGRycvZN a1MEqSJEa/qzAUES3UZj7+moXOFLaCr9iS4387WLpOt0st34LEJTqBqMsWVj534SbsxV OGX4VCuh1KBzYwrAhD2Nm/fkg37jZ0O1IZw3X5zyaZtc1ESeOfxouk/PE5MyaPK5/xI4 euk1ur8otYRK6MNOJrY3NkVyHMaP6WvOCKgtfG14m8+7lX9wxYLe7Zl8zPZVRFAf/riQ eSNPJpPuhBz7szOy3Vil/mz7ZgDcqMRRQ3xKlBBqcR585njW9wpC2Qb2ltX0pigHo/3m +lGg== X-Gm-Message-State: AOAM5311HD9zG++lEpekph2xBizfN+xee1mNHsi7ZALBobVRwniTSYT3 DwoobEoKfgkdCTKgeW1tO1PoVbBcfso= X-Google-Smtp-Source: ABdhPJxmbsGhReaA2WgFb5KdRCODYUvZYtqq+anemC9+hldQxJJearJ/liwdHdSkWeNfvJSfFbQBLw== X-Received: by 2002:a17:90a:d498:: with SMTP id s24mr501394pju.46.1640123684833; Tue, 21 Dec 2021 13:54:44 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id t12sm3424657pjo.44.2021.12.21.13.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Dec 2021 13:54:43 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.42]) by gnu-tgl-3.localdomain (Postfix) with ESMTPS id 4D98AC072B; Tue, 21 Dec 2021 13:54:42 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 93A593003DD; Tue, 21 Dec 2021 13:54:38 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH 3/3] elf: Add a test for PT_LOAD segments with invalid p_align [BZ #28688] Date: Tue, 21 Dec 2021 13:54:38 -0800 Message-Id: <20211221215438.3084053-4-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211221215438.3084053-1-hjl.tools@gmail.com> References: <20211221215438.3084053-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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" Build tst-p_alignmod3.so with 256 byte page size and verify that it is rejected with a proper error message. --- elf/Makefile | 13 +++++++++++++ elf/tst-p_align3.c | 27 +++++++++++++++++++++++++++ elf/tst-p_align3.sh | 26 ++++++++++++++++++++++++++ elf/tst-p_alignmod3.c | 22 ++++++++++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 elf/tst-p_align3.c create mode 100755 elf/tst-p_align3.sh create mode 100644 elf/tst-p_alignmod3.c diff --git a/elf/Makefile b/elf/Makefile index 3831b991a4..f18c94f71b 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -385,6 +385,12 @@ tests += \ tst-p_align1 \ tst-p_align2 \ +tests-special += \ + $(objpfx)tst-p_align3.out \ + +modules-names += \ + tst-p_alignmod3 \ + endif # Most modules build with _ISOMAC defined, but those filtered out @@ -2026,3 +2032,10 @@ $(objpfx)tst-p_alignmod2.so: $(objpfx)tst-p_alignmod2-edit \ cp $(objpfx)tst-alignmod3.so $@ $(test-wrapper-env) $(run-program-env) $(rtld-prefix) \ $(objpfx)tst-p_alignmod2-edit $@ + +LDFLAGS-tst-p_alignmod3.so += -Wl,-z,max-page-size=0x100,-z,common-page-size=0x100 + +$(objpfx)tst-p_align3: $(objpfx)tst-p_alignmod3.so +$(objpfx)tst-p_align3.out: tst-p_align3.sh $(objpfx)tst-p_align3 + $(SHELL) $< $(common-objpfx) '$(test-program-prefix)'; \ + $(evaluate-test) diff --git a/elf/tst-p_align3.c b/elf/tst-p_align3.c new file mode 100644 index 0000000000..61c616ac3b --- /dev/null +++ b/elf/tst-p_align3.c @@ -0,0 +1,27 @@ +/* Check invalid p_align of PT_LOAD segments in a shared library. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +extern int do_load_test (void); + +static int +do_test (void) +{ + return do_load_test (); +} + +#include diff --git a/elf/tst-p_align3.sh b/elf/tst-p_align3.sh new file mode 100755 index 0000000000..11572aa217 --- /dev/null +++ b/elf/tst-p_align3.sh @@ -0,0 +1,26 @@ +#!/bin/sh +# Check invalid p_align of PT_LOAD segments in a shared library. +# Copyright (C) 2021 Free Software Foundation, Inc. +# This file is part of the GNU C Library. + +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. + +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +common_objpfx=$1; shift +test_program_prefix=$1; shift + +${test_program_prefix} \ + ${common_objpfx}elf/tst-p_align3 \ + 2> ${common_objpfx}elf/tst-p_align3.out && exit 1 +grep "ELF load command address/offset not page-aligned" ${common_objpfx}elf/tst-p_align3.out diff --git a/elf/tst-p_alignmod3.c b/elf/tst-p_alignmod3.c new file mode 100644 index 0000000000..90f3af467e --- /dev/null +++ b/elf/tst-p_alignmod3.c @@ -0,0 +1,22 @@ +/* Check invalid p_align of PT_LOAD segment in a shared library. + Copyright (C) 2021 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +void +do_load_test (void) +{ +}