From patchwork Mon Jan 3 23:04:33 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: 49495 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com 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 80E203858C2C for ; Mon, 3 Jan 2022 23:07:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80E203858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1641251274; bh=266Bb9Y4ha98ahfT4KIkHHjnCCghd9omKFUw6Yk13ME=; 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=HWnnF1qhr5tsAQ2OBmB4itlcO58QQ46EUMoW2jpi5H9VzeTZTaGrv72WFj9q2TQCF Mau0d9hZHrkJOUlSOXGOlMPQeLaGDA+gq0TNIC50YqtTBGHDmL9CDq3Xv5Qjc5AjbE g6Yu6cbNQZU7rrIn3ew4MzdiNgvOqGNpZtWQY5pU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by sourceware.org (Postfix) with ESMTPS id 6B5C9385841A for ; Mon, 3 Jan 2022 23:04:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6B5C9385841A Received: by mail-pj1-x1030.google.com with SMTP id lr15-20020a17090b4b8f00b001b19671cbebso1200823pjb.1 for ; Mon, 03 Jan 2022 15:04:38 -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=266Bb9Y4ha98ahfT4KIkHHjnCCghd9omKFUw6Yk13ME=; b=TxhVHumvc/JWgnqDiHkl/Agefxk1QpcITkpWfLpzw9OzaiDV5/jaF1OHEs1jJGhey5 V0SD1RY0qC/Wztr7qJWF6UFlBoyE+wKDCDDkpey6pBALvypc7CVxD8KRd/VjjNnTw2kO j6ugZbp1Wo/MugWcjsclJlxAx/HWIvqQOem0AobyXxIK/OYS83PMZHp3qxKJ9yjQcIhs hQGZkHHvySeYdkqjlAp8mpt/V6vE4iwwO9JWN9A+TQ+ec4+pNNzSEvKKCJIUYEFvRZed zzfSlUPgSCqMDfrTo5jMNHFy1gCDuNqJyASLx2cih4dyyalxg7TV5b4KVhbuwW77XSNj muGw== X-Gm-Message-State: AOAM5300S1AB8wdTIDy9wbq2Rw8268IEIdt49psJfkaK5XbwGn3/R6ct AQCSz8RG+UweC63Wsc2kltIMAAAZfqw= X-Google-Smtp-Source: ABdhPJw4z4BOjCDLlN9QFDYI98kbFk4JLk2cmOStONhoYzgJEzaXDnmwEUk8wHApNIQrK/uA8hcnYA== X-Received: by 2002:a17:90b:8d:: with SMTP id bb13mr20785427pjb.156.1641251077372; Mon, 03 Jan 2022 15:04:37 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id k70sm32570132pgd.19.2022.01.03.15.04.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jan 2022 15:04:35 -0800 (PST) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.42]) by gnu-tgl-3.localdomain (Postfix) with ESMTPS id A8BE1C0D76; Mon, 3 Jan 2022 15:04:34 -0800 (PST) Received: from gnu-tgl-2.. (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 9641F300439; Mon, 3 Jan 2022 15:04:33 -0800 (PST) To: libc-alpha@sourceware.org Subject: [PATCH v7 4/4] elf: Add a test for PT_LOAD segments with invalid p_align [BZ #28688] Date: Mon, 3 Jan 2022 15:04:33 -0800 Message-Id: <20220103230433.1907240-5-hjl.tools@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20220103230433.1907240-1-hjl.tools@gmail.com> References: <20220103230433.1907240-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3029.0 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 | 11 +++++++++++ elf/tst-p_align3.c | 27 +++++++++++++++++++++++++++ elf/tst-p_align3.sh | 26 ++++++++++++++++++++++++++ elf/tst-p_alignmod3.c | 22 ++++++++++++++++++++++ 4 files changed, 86 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 e4be3fa518..eca730ae8f 100644 --- a/elf/Makefile +++ b/elf/Makefile @@ -409,6 +409,10 @@ tests += \ tst-p_alignmod2-edit \ tst-p_align1 \ tst-p_align2 \ + tst-p_align3 \ + +modules-names += \ + tst-p_alignmod3 \ endif @@ -2110,3 +2114,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) +{ +}