~serge-hallyn/+junk/usernstests

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
if [ `id -u` -ne 0 ]; then
	echo "Must run as root"
	exit 1
fi

nsexec=`which nsexec`
if [ $? -ne 0 ]; then
	echo "Please install nsexec from ppa:serge-hallyn/nsexec"
	exit 1
fi

gdb=`which gdb`
if [ $? -ne 0 ]; then
	echo "gdb not installed, not running tests"
	exit 1
fi

gdbcommands=/etc/gdbcommands
if [ ! -f "$f" ]; then
	gdbcommands=./gdbcommands
fi

# Can I ptrace my own tasks
sleep 60 &
gdb -x $gdbcommands -p $!
ret=$?
if [ $ret -ne 0 ]; then
	echo "Error: root could not ptrace his own tasks"
	exit 1
fi

# Can I ptrace tasks in child userns
nsexec -cU /bin/sleep 60 &
p=`pgrep -P $! sleep`
gdb -x $gdbcommands -p $p
ret=$?
if [ $ret -ne 0 ]; then
	echo "Error: could not ptrace tasks in child userns"
	exit 1
fi

# untested: can a non-root task ptrace tasks in child uersns he created?

# Can child userns ptrace task in parent userns?
sleep 60 &
nsexec -ceU $gdb -x $gdbcommands -p $!
ret=$?
if [ $ret -eq 0 ]; then
	echo "Error: child userns can ptrace parent userns"
	exit 1
fi

echo "All ptrace userns tests passed"