• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# Copyright (C) 2017 Red Hat, Inc.
4#
5# This program is free software;  you can redistribute it and#or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13# for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, see <http://www.gnu.org/licenses/>.
17
18# Test description: [regression] Check if the vsyscall and vdso VMA regions are
19#                   reported correctly.
20#
21#       While [vsyscall] is mostly deprecated with newer systems, there is
22#       still plenty of kernels compiled with CONFIG_LEGACY_VSYSCALL_NATIVE and
23#       CONFIG_LEGACY_VSYSCALL_EMULATE (see linux/arch/x86/Kconfig for option
24#       descriptions). First part of the test will check eligible kernels for
25#       regression for a bug fixed by commit 103efcd9aac1 (fix perms/range of
26#       vsyscall vma in /proc/*/maps).
27#
28#       Second part of test checks [vdso] VMA permissions (fixed with commits
29#       b6558c4a2378 (fix [vdso] page permissions) and e5b97dde514f (Add
30#       VM_ALWAYSDUMP)). As a consequence of this bug, VMAs were not included
31#       in core dumps which resulted in eg. incomplete backtraces and invalid
32#       core dump files created by gdb.
33
34# Usage
35# ./vma05.sh
36
37TST_SETUP=setup
38TST_CLEANUP=cleanup
39TST_TESTFUNC=vma_report_check
40TST_NEEDS_ROOT=1
41TST_NEEDS_TMPDIR=1
42TST_NEEDS_CMDS="gdb"
43
44. tst_test.sh
45
46CORE_LIMIT=$(ulimit -c)
47CORE_PATTERN=$(cat /proc/sys/kernel/core_pattern)
48
49setup()
50{
51	ulimit -c unlimited
52	echo "core" > /proc/sys/kernel/core_pattern
53}
54
55cleanup()
56{
57	ulimit -c "$CORE_LIMIT"
58	echo "$CORE_PATTERN" > /proc/sys/kernel/core_pattern
59}
60
61vma_report_check()
62{
63	if [ $(uname -m) = "x86_64" ]; then
64		if LINE=$(grep "vsyscall" /proc/self/maps); then
65			RIGHT="ffffffffff600000-ffffffffff601000[[:space:]]r-xp"
66			if echo "$LINE" | grep -q "$RIGHT"; then
67				tst_res TPASS "[vsyscall] reported correctly"
68			else
69				tst_res TFAIL "[vsyscall] reporting wrong"
70			fi
71		fi
72	fi
73
74	rm -rf core*
75	{ vma05_vdso; } > /dev/null 2>&1
76	TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\
77		vma05_vdso ./core* 2> /dev/null)
78	if echo "$TRACE" | grep -qF "??"; then
79		tst_res TFAIL "[vdso] bug not patched"
80	else
81		tst_res TPASS "[vdso] backtrace complete"
82	fi
83}
84
85tst_run
86