summaryrefslogtreecommitdiff
path: root/test-uderef.sh
blob: 86ce0254fbcb80f433af2f2323778fcad0124a38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#! /bin/bash

# Test for uderef.  Since a successful test will kill the shell, we
# need to communicate via the filesystem whether the test worked or
# not.
echo 'Directory for test-uderef.sh'
pwd

# If the feature is not compiled into the kernel, fail right away.
if [ ! -f /sys/kernel/debug/provoke-crash/DIRECT ]; then
	echo "Kernel was not compiled with CONFIG_LKDTM"
	echo "Not possible to test for UDEREF, failing"
	echo "test: uderef: fail"
fi

# Put a marker file that we can check later.
touch /tmp/uderef-6256ff7e

cat /sys/kernel/debug/provoke-crash/DIRECT
(echo EXCEPTION > /sys/kernel/debug/provoke-crash/DIRECT;
 rm /tmp/uderef-6256ff7e) &
sleep 1

# If the marker is still present, it suggests that the UDEREF check
# killed the running shell, and we should consider this a pass.
if [ -f /tmp/uderef-6256ff7e ]; then
	echo "UDEREF appears to have been detected"
	echo "test: uderef: pass"

	rm /tmp/uderef-6256ff7e
else
	echo "UDEREF didn't appear to work"
	echo "test: uderef: fail"
fi