diff --git a/tests/Regression/RELRO-protection-effective/Makefile b/tests/Regression/RELRO-protection-effective/Makefile new file mode 100644 index 0000000..b7e7b7e --- /dev/null +++ b/tests/Regression/RELRO-protection-effective/Makefile @@ -0,0 +1,63 @@ +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Makefile of /tools/binutils/Regression/RELRO-protection-effective +# Description: bz1174826 +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +export TEST=/tools/binutils/Regression/RELRO-protection-effective +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Martin Cermak " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: bz1174826" >> $(METADATA) + @echo "Type: Regression" >> $(METADATA) + @echo "TestTime: 5m" >> $(METADATA) + @echo "RunFor: binutils" >> $(METADATA) + @echo "Requires: binutils gcc" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2+" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + @echo "Bug: 1174826" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/Regression/RELRO-protection-effective/PURPOSE b/tests/Regression/RELRO-protection-effective/PURPOSE new file mode 100644 index 0000000..b10fb9c --- /dev/null +++ b/tests/Regression/RELRO-protection-effective/PURPOSE @@ -0,0 +1,34 @@ +PURPOSE of /tools/binutils/Regression/RELRO-protection-effective +Description: bz1174826 +Author: Martin Cermak +Bug summary: RELRO is not read-only on PowerLE +Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1174826 + +/* + * Test to exercise PIE and RELRO provided by Roland McGrath . + * + * Description: + * Simple test for RELRO, which happens to be a PIE too, but that's only + * because this kind of example has to be in PIC code to make RELRO relevant, + * and PIE makes it simpler to write a standalone one-file test than writing + * a DSO. + * + * The "const" makes "foo" .rodata material, and the init to an external symbol + * reference makes it require a data relocation. Enabling -z relro for this + * link puts that .rodata into a RELRO area. This program will crash because + * the page containing "foo" has been made read-only when "main" runs. + * Without RELRO, it would let you modify "foo" even though it's supposed to + * be const. + * + * Test with RELRO should fail: + * $ gcc -pie -fPIE -g -Wl,-z,relro -o relro relro.c + * $ ./relro + * Segmentation fault (core dumped) + * + * Test without RELRO should pass: + * $ gcc -pie -fPIE -g -Wl,-z,norelro -o no-relro relro.c + * $ ./no-relro + * +**/ + + diff --git a/tests/Regression/RELRO-protection-effective/main.fmf b/tests/Regression/RELRO-protection-effective/main.fmf new file mode 100644 index 0000000..afa66f5 --- /dev/null +++ b/tests/Regression/RELRO-protection-effective/main.fmf @@ -0,0 +1,43 @@ +summary: bz1174826 +description: "Bug summary: RELRO is not read-only on PowerLE\nBugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1174826\n\ + \n/* \ + \ \n * Test to exercise PIE and RELRO provided by Roland McGrath .\n\ + \ * \ + \ \n * Description: \ + \ \n * Simple test for RELRO, which happens to be a PIE too,\ + \ but that's only \n * because this kind of example has to be in PIC\ + \ code to make RELRO relevant, \n * and PIE makes it simpler to write a standalone\ + \ one-file test than writing \n * a DSO. \ + \ \n * \ + \ \n * The \"const\" makes \"\ + foo\" .rodata material, and the init to an external symbol\n * reference makes\ + \ it require a data relocation. Enabling -z relro for this \n * link puts\ + \ that .rodata into a RELRO area. This program will crash because \n * the\ + \ page containing \"foo\" has been made read-only when \"main\" runs. \ + \ \n * Without RELRO, it would let you modify \"foo\" even though it's supposed\ + \ to \n * be const. \ + \ \n * \ + \ \n * Test with RELRO should fail: \ + \ \n * $ gcc -pie -fPIE -g -Wl,-z,relro -o relro\ + \ relro.c \n * $ ./relro \ + \ \n * Segmentation fault (core\ + \ dumped) \n * \ + \ \n * Test without\ + \ RELRO should pass: \n * $\ + \ gcc -pie -fPIE -g -Wl,-z,norelro -o no-relro relro.c \ + \ \n * $ ./no-relro \ + \ \n * \ + \ \n**/\n\n\n" +contact: Martin Cermak +component: +- binutils +test: ./runtest.sh +framework: beakerlib +recommend: +- binutils +- gcc +duration: 5m +link: +- relates: https://bugzilla.redhat.com/show_bug.cgi?id=1174826 +extra-summary: /tools/binutils/Regression/RELRO-protection-effective +extra-task: /tools/binutils/Regression/RELRO-protection-effective diff --git a/tests/Regression/RELRO-protection-effective/runtest.sh b/tests/Regression/RELRO-protection-effective/runtest.sh new file mode 100755 index 0000000..cbfab38 --- /dev/null +++ b/tests/Regression/RELRO-protection-effective/runtest.sh @@ -0,0 +1,65 @@ +#!/bin/bash +# vim: dict=/usr/share/beakerlib/dictionary.vim cpt=.,w,b,u,t,i,k +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# runtest.sh of /tools/binutils/Regression/RELRO-protection-effective +# Description: bz1174826 +# Author: Martin Cermak +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +# +# Copyright (c) 2014 Red Hat, Inc. +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 2 of +# the License, or (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see http://www.gnu.org/licenses/. +# +# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="binutils" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + touch /tmp/disable-qe-abrt + rlRun "TMPD=\$(mktemp -d)" + rlRun "pushd $TMPD" + cat > relro.c <<-EOF +#include + +void *const foo = &stdout; + +int main (void) +{ + *(void **) &foo = &stderr; + return 0; +} +EOF + rlRun "gcc -pie -fPIE -g -Wl,-z,relro -o relro relro.c" + rlRun "gcc -pie -fPIE -g -Wl,-z,norelro -o no-relro relro.c" + rlPhaseEnd + + rlPhaseStartTest + rlRun "./relro" 139 + rlRun "./no-relro" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "popd" + rlRun "rm -r $TMPD" + rm -f /tmp/disable-qe-abrt + rlPhaseEnd +rlJournalPrintText +rlJournalEnd