From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 866FD3858415 for ; Tue, 8 Feb 2022 01:09:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 866FD3858415 Received: by mail-pl1-x635.google.com with SMTP id x3so12533996pll.3 for ; Mon, 07 Feb 2022 17:09:03 -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=YCIHiH4Pit98Gb18MnARM9AlwrLMZNvJI1IewGMha60=; b=rTO5mhFbY+q+ouXBxzeKpvToXh3bAeijKQl3F0Q5a4Cp2XxNLwHvUcXkSFmv6JbH2k zcTGwR192S4j5664xnk/rfVkkOZcwHqgCkFfmMb5C1Wvo0Kyh4cvKxJE3Hpssh57aIYE 9FnLBnczv6OlUyUWDlvdIq820KBMtGK75wE17QTyIwqFJxiypH9OtOIsjQVX4dVmdpKg VuEeKbuVXvn3MzvqiNtbnavvoYqFwtt2Xtp+ThEWS0UtEJRtsrMIcrkpkmCVa6/wJn44 b59qMHdkY8yeZyURmUapzi4ws3nVBh262+dcIOthfJOLdXuIrc6dTFlU6LZIeegIPKJk DF9A== X-Gm-Message-State: AOAM533D4QPCXlv9qzN1HbeJL5o0HnRTpZCTWo9uhAsF6se4om07qYz2 TLFfMB+MSYjehR8UAhW7SwjaJleWkhA= X-Google-Smtp-Source: ABdhPJzB1TOQC+cJYnHuVsd162Y50uXfQicPapiKhffROEUWJkixT63uM/Y1ZbQPztzTwz9RZedNDg== X-Received: by 2002:a17:90a:cc5:: with SMTP id 5mr1738216pjt.156.1644282542260; Mon, 07 Feb 2022 17:09:02 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:3644:1eae:5601:d29]) by smtp.gmail.com with ESMTPSA id s42sm14111864pfg.146.2022.02.07.17.09.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Feb 2022 17:09:01 -0800 (PST) From: Alan Modra To: binutils@sourceware.org Subject: [PATCH 2/4] PR28824, relro security issues, x86 keep COMMONPAGESIZE relro Date: Tue, 8 Feb 2022 11:38:31 +1030 Message-Id: <20220208010833.2103874-3-amodra@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220208010833.2103874-1-amodra@gmail.com> References: <20220208010833.2103874-1-amodra@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3036.6 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Feb 2022 01:09:05 -0000 x86 treats MAXPAGESIZE as a memory optimisation parameter, actual hardware paging is always COMMPAGESIZE of 4k. Use COMMONPAGESIZE for the end of the relro segment alignment. The previous patch regresses pr18176, increasing the testcase file size from 322208 to 2099872 bytes. Fixing this on x86 will require introducing a gap after the end of the relro segment (of up to relropagesize-1 bytes). PR 28824 PR 18176 * ld.h (ld_config_type): Add relro_use_commonpagesize field. * ldexp.c (fold_segment_align): Set relropagesize depending on relro_use_commonpagesize. * emultempl/elf-x86.em (elf_x86_create_output_section_statements): Set relro_use_commonpagesize. * testsuite/ld-x86-64/pr18176.d: xfail. diff --git a/ld/emultempl/elf-x86.em b/ld/emultempl/elf-x86.em index f75521cecea..134e4e1b616 100644 --- a/ld/emultempl/elf-x86.em +++ b/ld/emultempl/elf-x86.em @@ -33,6 +33,7 @@ static struct elf_linker_x86_params params; static void elf_x86_create_output_section_statements (void) { + config.relro_use_commonpagesize = true; _bfd_elf_linker_x86_set_options (&link_info, ¶ms); } diff --git a/ld/ld.h b/ld/ld.h index f3086bf30de..c7e4ca3d334 100644 --- a/ld/ld.h +++ b/ld/ld.h @@ -276,6 +276,10 @@ typedef struct /* If set, code and non-code sections should never be in one segment. */ bool separate_code; + /* TRUE if the end of the relro segment should be aligned to + COMMONPAGESIZE rather than MAXPAGESIZE. */ + bool relro_use_commonpagesize; + /* The rpath separation character. Usually ':'. */ char rpath_separator; diff --git a/ld/ldexp.c b/ld/ldexp.c index a38cec7829d..ab724074732 100644 --- a/ld/ldexp.c +++ b/ld/ldexp.c @@ -481,7 +481,10 @@ fold_segment_align (seg_align_type *seg, etree_value_type *lhs) seg->base = expld.result.value; seg->commonpagesize = commonpage; seg->maxpagesize = maxpage; - seg->relropagesize = maxpage; + if (config.relro_use_commonpagesize) + seg->relropagesize = commonpage; + else + seg->relropagesize = maxpage; seg->relro_end = 0; } else diff --git a/ld/testsuite/ld-x86-64/pr18176.d b/ld/testsuite/ld-x86-64/pr18176.d index a99ff15ac6b..728c15a3dd8 100644 --- a/ld/testsuite/ld-x86-64/pr18176.d +++ b/ld/testsuite/ld-x86-64/pr18176.d @@ -3,6 +3,7 @@ #ld: -melf_x86_64 -shared -z relro -T pr18176.t -z max-page-size=0x200000 -z common-page-size=0x1000 $NO_DT_RELR_LDFLAGS #readelf: -l --wide #target: x86_64-*-linux* +#xfail: *-*-* #... GNU_RELRO 0x04bd17 0x000000000024bd17 0x000000000024bd17 0x0022e9 0x0022e9 R 0x1