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