Debian Codegraph @

tests/Makefile

raw
1 #
2 # NOTE the built tests are all designed to be run from this
3 # working directory when built DYNAMIC=yes. That is, they
4 # link to the shared libraries in ../libcap/ .
5 #
6 topdir=$(shell pwd)/..
7 include ../Make.Rules
8 #
9
10 all:
11 @echo leave test building to test target
12
13 install:
14 @echo nothing to install from tests
15
16 FORCE_RPATH_LINKSO=-Wl,-rpath,../libcap
17
18 ifeq ($(DYNAMIC),yes)
19 LINKEXTRA=$(FORCE_RPATH_LINKSO)
20 DEPS=../libcap/libcap.so
21 ifeq ($(PTHREADS),yes)
22 DEPS += ../libcap/libpsx.so
23 endif
24 else
25 # For this build variant override the LDFLAGS to link statically from
26 # libraries within the build tree. If you never want this, use
27 # make DYNAMIC=yes ...
28 LDFLAGS = --static
29 DEPS=../libcap/libcap.a
30 ifeq ($(PTHREADS),yes)
31 DEPS += ../libcap/libpsx.a
32 endif
33 endif
34
35 ../libcap/libcap.so:
36 $(MAKE) -C ../libcap libcap.so
37
38 ../libcap/libcap.a:
39 $(MAKE) -C ../libcap libcap.a
40
41 ../libcap/loader.txt:
42 $(MAKE) -C ../libcap loader.txt
43
44 ifeq ($(PTHREADS),yes)
45 ../libcap/libpsx.so:
46 $(MAKE) -C ../libcap libpsx.so
47
48 ../libcap/libpsx.a:
49 $(MAKE) -C ../libcap libpsx.a
50 endif
51
52 ../progs/tcapsh-static:
53 $(MAKE) -C ../progs tcapsh-static
54
55 test:
56 ifeq ($(PTHREADS),yes)
57 $(MAKE) run_psx_test run_libcap_psx_test
58 ifeq ($(SHARED),yes)
59 $(MAKE) run_b219174
60 endif
61 endif
62
63 sudotest: test
64 $(MAKE) run_uns_test
65 $(MAKE) run_libcap_launch_test
66 ifeq ($(PTHREADS),yes)
67 $(MAKE) run_libcap_psx_launch_test run_exploit_test
68 endif
69
70 # unprivileged
71 run_psx_test: psx_test
72 ./psx_test
73
74 psx_test: psx_test.c $(DEPS)
75 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB)
76
77 run_libcap_psx_test: libcap_psx_test
78 ./libcap_psx_test
79
80 libcap_psx_test: libcap_psx_test.c $(DEPS)
81 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB)
82
83 # privileged
84 uns_test: uns_test.c $(DEPS)
85 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB)
86
87 run_uns_test: uns_test
88 echo exit | $(SUDO) ./uns_test
89
90 run_libcap_launch_test: libcap_launch_test noop ../progs/tcapsh-static
91 $(SUDO) ./libcap_launch_test
92
93 run_libcap_psx_launch_test: libcap_psx_launch_test ../progs/tcapsh-static
94 $(SUDO) ./libcap_psx_launch_test
95
96 libcap_launch_test: libcap_launch_test.c $(DEPS)
97 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB)
98
99 # This varies only slightly from the above insofar as it currently
100 # only links in the pthreads fork support. TODO() we need to change
101 # the source to do something interesting with pthreads.
102 libcap_psx_launch_test: libcap_launch_test.c $(DEPS)
103 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DWITH_PTHREADS $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) $(LIBPSXLIB)
104
105
106 # This test demonstrates that libpsx is needed to secure multithreaded
107 # programs that link against libcap.
108 run_exploit_test: exploit noexploit
109 @echo exploit should succeed
110 $(SUDO) ./exploit ; if [ $$? -ne 0 ]; then exit 0; else exit 1 ; fi
111 @echo exploit should fail
112 $(SUDO) ./noexploit ; if [ $$? -eq 0 ]; then exit 0; else exit 1 ; fi
113
114 exploit: exploit.o $(DEPS)
115 $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBCAPLIB) -lpthread
116
117 # Note, for some reason, the order of libraries is important to avoid
118 # the exploit working for dynamic linking.
119 noexploit: exploit.o $(DEPS)
120 $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ $(LINKEXTRA) $(LIBPSXLIB) $(LIBCAPLIB)
121
122 # This one runs in a chroot with no shared library files.
123 noop: noop.c
124 $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ --static
125
126 # validate that a shred library that, itself launches threads, is
127 # covered by -lpsx.
128
129 ifeq ($(PTHREADS),yes)
130 ifeq ($(SHARED),yes)
131 run_b219174: weaver.so b219174
132 ./weaver.so
133 ./b219174
134
135 # This is *NOT* linked against libpsx.
136 weaver.so: weaver.c weaver.h ../libcap/execable.h ../libcap/loader.txt
137 $(LD) -o $@ $(CFLAGS) -fPIC $(CPPFLAGS) weaver.c -DSHARED_LOADER=\"$(shell cat ../libcap/loader.txt)\" -Wl,-e,__so_start -lpthread
138
139 # This only works when linked dynamically
140 b219174: b219174.c $(DEPS)
141 $(CC) $(CFLAGS) $(CPPFLAGS) $< -o $@ $(FORCE_RPATH_LINKSO) $(LIBPSXLIB) -ldl
142
143 endif
144 endif
145
146 clean:
147 rm -f psx_test libcap_psx_test libcap_launch_test uns_test *~
148 rm -f libcap_launch_test libcap_psx_launch_test core noop
149 rm -f exploit noexploit exploit.o weaver.so b219174