• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0-or-later
3# Copyright (C) 2017 Red Hat, Inc.
4# Regression test if the vsyscall and vdso VMA regions are reported correctly.
5#
6# While [vsyscall] is mostly deprecated with newer systems, there is
7# still plenty of kernels compiled with CONFIG_LEGACY_VSYSCALL_NATIVE and
8# CONFIG_LEGACY_VSYSCALL_EMULATE (see linux/arch/x86/Kconfig for option
9# descriptions). First part of the test will check eligible kernels for
10# regression for a bug fixed by commit 103efcd9aac1 (fix perms/range of
11# vsyscall vma in /proc/*/maps).
12#
13# Second part of test checks [vdso] VMA permissions (fixed with commits
14# b6558c4a2378 (fix [vdso] page permissions) and e5b97dde514f (Add
15# VM_ALWAYSDUMP)). As a consequence of this bug, VMAs were not included
16# in core dumps which resulted in eg. incomplete backtraces and invalid
17# core dump files created by gdb.
18
19TST_SETUP=setup
20TST_CLEANUP=cleanup
21TST_TESTFUNC=vma_report_check
22TST_NEEDS_ROOT=1
23TST_NEEDS_TMPDIR=1
24TST_NEEDS_CMDS="gdb"
25
26CORE_LIMIT=$(ulimit -c)
27CORE_PATTERN=$(cat /proc/sys/kernel/core_pattern)
28
29setup()
30{
31	ulimit -c unlimited
32	echo "core" > /proc/sys/kernel/core_pattern
33	unset DEBUGINFOD_URLS
34}
35
36cleanup()
37{
38	ulimit -c "$CORE_LIMIT"
39	echo "$CORE_PATTERN" > /proc/sys/kernel/core_pattern
40}
41
42vma_report_check()
43{
44	if [ $(uname -m) = "x86_64" ]; then
45		if LINE=$(grep "vsyscall" /proc/self/maps); then
46			RIGHT="ffffffffff600000-ffffffffff601000[[:space:]][r-]-xp"
47			if echo "$LINE" | grep -q "$RIGHT"; then
48				tst_res TPASS "[vsyscall] reported correctly"
49			else
50				tst_res TFAIL "[vsyscall] reporting wrong"
51			fi
52		fi
53	fi
54
55	rm -rf core*
56	{ vma05_vdso; } > /dev/null 2>&1
57	TRACE=$(gdb -silent -ex="thread apply all backtrace" -ex="quit"\
58		vma05_vdso ./core* 2> /dev/null)
59	if echo "$TRACE" | grep -qF "??"; then
60		tst_res TFAIL "[vdso] bug not patched"
61	else
62		tst_res TPASS "[vdso] backtrace complete"
63	fi
64}
65
66. tst_test.sh
67tst_run
68