~serge-hallyn/+junk/usernstests

« back to all changes in this revision

Viewing changes to ptrace.sh

  • Committer: Serge Hallyn
  • Date: 2011-07-11 18:04:14 UTC
  • Revision ID: serge.hallyn@canonical.com-20110711180414-u6cvypi7pmi0u9zg
initial push

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
if [ `id -u` -ne 0 ]; then
 
3
        echo "Must run as root"
 
4
        exit 1
 
5
fi
 
6
 
 
7
nsexec=`which nsexec`
 
8
if [ $? -ne 0 ]; then
 
9
        echo "Please install nsexec from ppa:serge-hallyn/nsexec"
 
10
        exit 1
 
11
fi
 
12
 
 
13
gdb=`which gdb`
 
14
if [ $? -ne 0 ]; then
 
15
        echo "gdb not installed, not running tests"
 
16
        exit 1
 
17
fi
 
18
 
 
19
gdbcommands=/etc/gdbcommands
 
20
if [ ! -f "$f" ]; then
 
21
        gdbcommands=./gdbcommands
 
22
fi
 
23
 
 
24
# Can I ptrace my own tasks
 
25
sleep 60 &
 
26
gdb -x $gdbcommands -p $!
 
27
ret=$?
 
28
if [ $ret -ne 0 ]; then
 
29
        echo "Error: root could not ptrace his own tasks"
 
30
        exit 1
 
31
fi
 
32
 
 
33
# Can I ptrace tasks in child userns
 
34
nsexec -cU /bin/sleep 60 &
 
35
p=`pgrep -P $! sleep`
 
36
gdb -x $gdbcommands -p $p
 
37
ret=$?
 
38
if [ $ret -ne 0 ]; then
 
39
        echo "Error: could not ptrace tasks in child userns"
 
40
        exit 1
 
41
fi
 
42
 
 
43
# untested: can a non-root task ptrace tasks in child uersns he created?
 
44
 
 
45
# Can child userns ptrace task in parent userns?
 
46
sleep 60 &
 
47
nsexec -ceU $gdb -x $gdbcommands -p $!
 
48
ret=$?
 
49
if [ $ret -eq 0 ]; then
 
50
        echo "Error: child userns can ptrace parent userns"
 
51
        exit 1
 
52
fi
 
53
 
 
54
echo "All ptrace userns tests passed"