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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
|
/* $OpenBSD: syscalls.c,v 1.12 2018/04/26 08:15:41 beck Exp $ */
/*
* Copyright (c) 2017 Bob Beck <beck@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <err.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/errno.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
pid_t child;
char pp_dir1[] = "/tmp/ppdir1.XXXXXX"; /* pledgepathed */
char pp_dir2[] = "/tmp/ppdir2.XXXXXX"; /* not pledgepathed */
char pp_file1[] = "/tmp/ppfile1.XXXXXX"; /* pledgepathed */
char pp_file2[] = "/tmp/ppfile2.XXXXXX"; /* not pledgepathed */
#define PP_SHOULD_SUCCEED(A, B) do { \
if (A) { \
err(1, "%s:%d - %s", __FILE__, __LINE__, B); \
} \
} while (0)
#define PP_SHOULD_FAIL(A, B) do { \
if (A) { \
if (do_pp && errno != ENOENT) \
err(1, "%s:%d - %s", __FILE__, __LINE__, B); \
} else { \
if (do_pp) \
errx(1, "%s:%d - %s worked when it should not " \
"have", __FILE__, __LINE__, B); \
} \
} while(0)
/* all the things unless we override */
static int pp_flags = O_RDWR|O_EXEC|O_CREAT;
static void
do_pledgepath(void)
{
if (pledgepath(pp_dir1, pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath(pp_file1, pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
static int
runcompare(int (*func)(int))
{
int ppath = 0, nonppath = 0, status;
pid_t pid = fork();
if (pid == 0) {
exit(func(0));
}
status = 0;
waitpid(pid, &status, 0);
if (WIFEXITED(status))
nonppath = WEXITSTATUS(status);
pid = fork();
if (pid == 0) {
exit(func(1));
}
status = 0;
waitpid(pid, &status, 0);
if (WIFEXITED(status))
ppath = WEXITSTATUS(status);
if (ppath == nonppath) {
printf("[SUCCESS] ppath = %d, nonppath = %d\n", ppath, nonppath);
return 0;
}
printf("[FAIL] ppath = %d, nonppath = %d\n", ppath, nonppath);
return 1;
}
static int
test_open(int do_pp)
{
char filename[256];
int dirfd;
int dirfd2;
int dirfd3;
PP_SHOULD_SUCCEED(((dirfd = open("/", O_RDONLY | O_DIRECTORY)) == -1), "open");
PP_SHOULD_SUCCEED(((dirfd2 = open(pp_dir2, O_RDONLY | O_DIRECTORY)) == -1), "open");
if (do_pp) {
printf("testing open and openat\n");
do_pledgepath();
if (pledgepath("/tmp/alpha", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/bravo", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/charlie", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/delta", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/echo", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/foxtrot", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/golf", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/hotel", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/india", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/juliet", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/kilo", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/lima", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/money", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/november", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/oscar", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/papa", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/quebec", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/romeo", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/sierra", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/tango", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/uniform", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/victor", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/whiskey", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/xray", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/yankee", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
if (pledgepath("/tmp/zulu", pp_flags) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((pledge("paths stdio rpath cpath wpath exec", NULL) == -1), "pledge");
PP_SHOULD_FAIL((open(pp_file2, O_RDWR) == -1), "open");
PP_SHOULD_FAIL(((dirfd3= open(pp_dir2, O_RDONLY | O_DIRECTORY)) == -1), "open");
PP_SHOULD_SUCCEED((open(pp_file1, O_RDWR) == -1), "open");
if (!do_pp) {
/* Unlink the pledgepathed file and make it again */
PP_SHOULD_SUCCEED((unlink(pp_file1) == -1), "unlink");
PP_SHOULD_SUCCEED((open(pp_file1, O_RDWR|O_CREAT) == -1), "open");
}
sleep(1);
PP_SHOULD_SUCCEED((open(pp_file1, O_RDWR) == -1), "open");
if (do_pp) {
if (pledgepath(pp_file1, O_RDONLY) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_FAIL((open(pp_file1, O_RDWR) == -1), "open");
PP_SHOULD_SUCCEED((openat(dirfd, "etc/hosts", O_RDONLY) == -1), "openat");
PP_SHOULD_FAIL((openat(dirfd, pp_file2, O_RDWR) == -1), "openat");
PP_SHOULD_SUCCEED((openat(dirfd2, "hooray", O_RDWR|O_CREAT) == -1), "openat");
PP_SHOULD_FAIL((open(pp_file2, O_RDWR) == -1), "open");
(void) snprintf(filename, sizeof(filename), "%s/%s", pp_dir1, "newfile");
PP_SHOULD_SUCCEED((open(filename, O_RDWR|O_CREAT) == -1), "open");
(void) snprintf(filename, sizeof(filename), "%s/%s", pp_dir2, "newfile");
PP_SHOULD_FAIL((open(filename, O_RDWR|O_CREAT) == -1), "open");
if (do_pp) {
printf("testing O_RDONLY\n");
if (pledgepath(pp_file1, O_RDONLY) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((open(pp_file1, O_RDONLY) == -1), "open");
PP_SHOULD_FAIL((open(pp_file2, O_RDWR) == -1), "open");
if (do_pp) {
printf("testing O_RDWR\n");
if (pledgepath(pp_file1, O_RDWR) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((open(pp_file1, O_RDONLY) == -1), "open");
PP_SHOULD_SUCCEED((open(pp_file1, O_RDWR) == -1), "open");
PP_SHOULD_FAIL((open(pp_file2, O_EXEC) == -1), "open");
if (do_pp) {
printf("testing O_EXEC\n");
if (pledgepath(pp_file1, O_EXEC) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((open(pp_file1, O_RDONLY) == -1), "open");
// XXX PP_SHOULD_SUCCEED((open(pp_file1, O_EXEC) == -1), "open");
PP_SHOULD_FAIL((open(pp_file2, O_RDWR) == -1), "open");
if (do_pp) {
printf("(testing pledgepath after pledge)\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio rpath cpath wpath", NULL) == -1), "pledge");
printf("(testing dropping ppath)\n");
PP_SHOULD_FAIL((open(pp_file2, O_RDWR) == -1), "open");
return 0;
}
static int
test_unlink(int do_pp)
{
char filename1[256];
char filename2[256];
char filename3[] = "/tmp/nukeme.XXXXXX";
int fd;
(void) snprintf(filename1, sizeof(filename1), "%s/%s", pp_dir1,
"nukeme");
(void) snprintf(filename2, sizeof(filename2), "%s/%s", pp_dir2,
"nukeme");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
PP_SHOULD_SUCCEED((open(filename2, O_RDWR|O_CREAT) == -1), "open");
if ((fd = mkstemp(filename3)) == -1)
err(1, "%s:%d - mkstemp", __FILE__, __LINE__);
if (do_pp) {
printf("testing unlink\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("paths stdio fattr rpath cpath wpath", NULL) == -1),
"pledge");
PP_SHOULD_SUCCEED((unlink(filename1) == -1), "unlink");
PP_SHOULD_FAIL((unlink(filename2) == -1), "unlink");
PP_SHOULD_FAIL((unlink(filename3) == -1), "unlink");
if (do_pp) {
printf("testing unlink without O_CREAT\n");
if (pledgepath(filename3, O_RDWR) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_FAIL((unlink(filename3) == -1), "unlink");
return 0;
}
static int
test_link(int do_pp)
{
char filename[256];
char filename2[256];
if (do_pp) {
printf("testing link\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("paths stdio fattr rpath cpath wpath", NULL) == -1),
"pledge");
(void) snprintf(filename, sizeof(filename), "%s/%s", pp_dir1,
"linkpp1");
(void) snprintf(filename2, sizeof(filename2), "%s/%s", pp_dir2,
"linkpp2");
unlink(filename);
unlink(filename2);
PP_SHOULD_SUCCEED((link(pp_file1, filename) == -1), "link");
unlink(filename);
PP_SHOULD_FAIL((link(pp_file2, filename) == -1), "link");
PP_SHOULD_FAIL((link(pp_file1, filename2) == -1), "link");
if (do_pp) {
printf("testing link without O_CREAT\n");
if (pledgepath(filename, O_RDWR) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_FAIL((link(pp_file1, filename) == -1), "link");
unlink(filename);
return 0;
}
static int
test_chdir(int do_pp)
{
if (do_pp) {
printf("testing chdir\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((chdir(pp_dir1) == -1), "chdir");
PP_SHOULD_FAIL((chdir(pp_dir2) == -1), "chdir");
return 0;
}
static int
test_rename(int do_pp)
{
char filename1[256];
char filename2[256];
char rfilename1[256];
char rfilename2[256];
int dirfd1, dirfd2;
if ((dirfd1 = open(pp_dir1, O_RDONLY | O_DIRECTORY)) == -1)
err(1, "%s:%d - open of dir1", __FILE__, __LINE__);
if ((dirfd2 = open(pp_dir2, O_RDONLY | O_DIRECTORY)) == -1)
err(1, "%s:%d - open of dir2", __FILE__, __LINE__);
(void) snprintf(filename1, sizeof(filename1), "%s/%s", pp_dir1,
"file1");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
(void) snprintf(filename2, sizeof(filename2), "%s/%s", pp_dir2,
"file2");
PP_SHOULD_SUCCEED((open(filename2, O_RDWR|O_CREAT) == -1), "open");
(void) snprintf(rfilename1, sizeof(rfilename1), "%s/%s", pp_dir1,
"rfile1");
(void) snprintf(rfilename2, sizeof(rfilename2), "%s/%s", pp_dir2,
"rfile2");
if (do_pp) {
printf("testing rename\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath wpath cpath", NULL) == -1),
"pledge");
PP_SHOULD_SUCCEED((rename(filename1, rfilename1) == -1), "rename");
PP_SHOULD_FAIL((rename(filename2, rfilename2) == -1), "rename");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
PP_SHOULD_FAIL((rename(filename1, rfilename2) == -1), "rename");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
PP_SHOULD_FAIL((rename(filename1, pp_file2) == -1), "rename");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
PP_SHOULD_SUCCEED((renameat(dirfd1, "file1", dirfd2, "rfile2") == -1),
"renameat");
PP_SHOULD_SUCCEED((open(filename1, O_RDWR|O_CREAT) == -1), "open");
PP_SHOULD_FAIL((renameat(dirfd1, "file1", dirfd2, rfilename2) == -1),
"renameat");
return (0);
}
static int
test_access(int do_pp)
{
if (do_pp) {
printf("testing access\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((access(pp_file1, R_OK) == -1), "access");
PP_SHOULD_FAIL((access(pp_file2, R_OK) == -1), "access");
PP_SHOULD_SUCCEED((access(pp_dir1, R_OK) == -1), "access");
PP_SHOULD_FAIL((access(pp_dir2, R_OK) == -1), "access");
return 0;
}
static int
test_chflags(int do_pp)
{
if (do_pp) {
printf("testing chflags\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((chflags(pp_file1, UF_NODUMP) == -1), "chflags");
PP_SHOULD_FAIL((chflags(pp_file2, UF_NODUMP) == -1), "chflags");
return 0;
}
static int
test_stat(int do_pp)
{
if (do_pp) {
printf("testing stat\n");
do_pledgepath();
}
struct stat sb;
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((stat(pp_file1, &sb) == -1), "stat");
PP_SHOULD_FAIL((stat(pp_file2, &sb) == -1), "stat");
PP_SHOULD_SUCCEED((stat(pp_dir1, &sb) == -1), "stat");
PP_SHOULD_FAIL((stat(pp_dir2, &sb) == -1), "stat");
return 0;
}
static int
test_statfs(int do_pp)
{
if (do_pp) {
printf("testing statfs\n");
do_pledgepath();
}
struct statfs sb;
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((statfs(pp_file1, &sb) == -1), "statfs");
PP_SHOULD_FAIL((statfs(pp_file2, &sb) == -1), "statfs");
PP_SHOULD_SUCCEED((statfs(pp_dir1, &sb) == -1), "statfs");
PP_SHOULD_FAIL((statfs(pp_dir2, &sb) == -1), "statfs");
return 0;
}
static int
test_symlink(int do_pp)
{
char filename[256];
char filename2[256];
char buf[256];
struct stat sb;
if (do_pp) {
printf("testing symlink and lstat and readlink\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("paths stdio fattr rpath cpath wpath", NULL) == -1),
"pledge");
(void) snprintf(filename, sizeof(filename), "%s/%s", pp_dir1,
"slinkpp1");
(void) snprintf(filename2, sizeof(filename2), "%s/%s", pp_dir2,
"slinkpp2");
unlink(filename);
unlink(filename2);
PP_SHOULD_SUCCEED((symlink(pp_file1, filename) == -1), "symlink");
PP_SHOULD_SUCCEED((lstat(filename, &sb) == -1), "lstat");
PP_SHOULD_SUCCEED((lstat(pp_file1, &sb) == -1), "lstat");
PP_SHOULD_SUCCEED((readlink(filename, buf, sizeof(buf)) == -1), "readlink");
unlink(filename);
PP_SHOULD_SUCCEED((symlink(pp_file2, filename) == -1), "symlink");
PP_SHOULD_SUCCEED((lstat(filename, &sb) == -1), "lstat");
PP_SHOULD_SUCCEED((readlink(filename, buf, sizeof(buf)) == -1), "readlink");
PP_SHOULD_FAIL((lstat(pp_file2, &sb) == -1), "lstat");
PP_SHOULD_FAIL((symlink(pp_file1, filename2) == -1), "symlink");
PP_SHOULD_FAIL((readlink(filename2, buf, sizeof(buf)) == -1), "readlink");
unlink(filename);
if (do_pp) {
printf("testing symlink without O_CREAT\n");
if (pledgepath(filename, O_RDWR) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_FAIL((symlink(pp_file1, filename) == -1), "symlink");
return 0;
}
static int
test_chmod(int do_pp)
{
if (do_pp) {
printf("testing chmod\n");
do_pledgepath();
}
PP_SHOULD_SUCCEED((pledge("stdio fattr rpath", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((chmod(pp_file1, S_IRWXU) == -1), "chmod");
PP_SHOULD_FAIL((chmod(pp_file2, S_IRWXU) == -1), "chmod");
PP_SHOULD_SUCCEED((chmod(pp_dir1, S_IRWXU) == -1), "chmod");
PP_SHOULD_FAIL((chmod(pp_dir2, S_IRWXU) == -1), "chmod");
return 0;
}
static int
test_exec(int do_pp)
{
char *argv[] = {"/usr/bin/true", NULL};
extern char **environ;
if (do_pp) {
printf("testing execve with O_EXEC only\n");
if (pledgepath("/usr/bin/true", O_EXEC) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((pledge("paths stdio fattr exec", NULL) == -1), "pledge");
PP_SHOULD_SUCCEED((execve(argv[0], argv, environ) == -1), "execve");
return 0;
}
static int
test_exec2(int do_pp)
{
char *argv[] = {"/usr/bin/true", NULL};
extern char **environ;
if (do_pp) {
printf("testing execve without O_EXEC\n");
if (pledgepath("/usr/bin/true", O_RDWR) == -1)
err(1, "%s:%d - pledgepath", __FILE__, __LINE__);
}
PP_SHOULD_SUCCEED((pledge("paths stdio fattr exec", NULL) == -1), "pledge");
PP_SHOULD_FAIL((execve(argv[0], argv, environ) == -1), "execve");
return 0;
}
int
main (int argc, char *argv[])
{
int fd1, fd2, failures = 0;
PP_SHOULD_SUCCEED((mkdtemp(pp_dir1) == NULL), "mkdtmp");
PP_SHOULD_SUCCEED((mkdtemp(pp_dir2) == NULL), "mkdtmp");
PP_SHOULD_SUCCEED(((fd1 = mkstemp(pp_file1)) == -1), "mkstemp");
close(fd1);
PP_SHOULD_SUCCEED((chmod(pp_file1, S_IRWXU) == -1), "chmod");
PP_SHOULD_SUCCEED(((fd2 = mkstemp(pp_file2)) == -1), "mkstemp");
close(fd2);
failures += runcompare(test_open);
failures += runcompare(test_unlink);
failures += runcompare(test_link);
failures += runcompare(test_chdir);
failures += runcompare(test_rename);
failures += runcompare(test_access);
failures += runcompare(test_chflags);
failures += runcompare(test_stat);
failures += runcompare(test_statfs);
failures += runcompare(test_symlink);
failures += runcompare(test_chmod);
failures += runcompare(test_exec);
failures += runcompare(test_exec2);
exit(failures);
}
|