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