-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prctl: test prctl(NO_NEW_PRIVS) setting
Signed-off-by: Michał Mirosław <[email protected]>
- Loading branch information
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdlib.h> | ||
#include <sys/prctl.h> | ||
|
||
#include "zdtmtst.h" | ||
|
||
const char *test_doc = "Check that NO_NEW_PRIVS attribute is restored"; | ||
const char *test_author = "Michał Mirosław <[email protected]>"; | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
int ret; | ||
|
||
test_init(argc, argv); | ||
|
||
ret = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0); | ||
if (ret < 0) { | ||
pr_perror("Can't read NO_NEW_PRIVS attribute"); | ||
return 1; | ||
} | ||
if (ret != 0) | ||
fail("initial NO_NEW_PRIVS = %d != 0", ret); | ||
|
||
ret = prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); | ||
if (ret) { | ||
pr_perror("Can't set NO_NEW_PRIVS attribute"); | ||
return 1; | ||
} | ||
|
||
test_daemon(); | ||
test_waitsig(); | ||
|
||
ret = prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0); | ||
if (ret < 0) { | ||
pr_perror("Can't read NO_NEW_PRIVS attribute"); | ||
return 1; | ||
} | ||
if (ret != 1) | ||
fail("restored NO_NEW_PRIVS = %d != 1", ret); | ||
|
||
pass(); | ||
return 0; | ||
} |