Created
February 2, 2017 10:59
-
-
Save tixxdz/f7d1eadd4728b6aec00b8c2438411b15 to your computer and use it in GitHub Desktop.
Timgad LSM test
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
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <unistd.h> | |
#include <linux/prctl.h> | |
#include <sys/prctl.h> | |
#include <sys/ptrace.h> | |
extern char **environ; | |
static char *args[] = { "/bin/bash", NULL }; | |
int main(int argc, const char **argv) | |
{ | |
int ret; | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_GET_MOD_RESTRICT, 0, 0, 0); | |
if (ret < 0) | |
printf("Error PR_TIMGAD_GET_MOD_RESTRICT failed: %d (%m)\n", -errno); | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_SET_MOD_RESTRICT, 1, 0, 0); | |
if (ret < 0) { | |
fprintf(stderr, "Error PR_TIMGAD_SET_MOD_RESTRICT to 1 failed: %d (%m)\n", -errno); | |
return EXIT_FAILURE; | |
} | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_GET_MOD_RESTRICT, 0, 0, 0); | |
if (ret < 0) { | |
fprintf(stderr, "Error PR_TIMGAD_GET_MOD_RESTRICT failed: %d (%m)\n", -errno); | |
return EXIT_FAILURE; | |
} | |
printf(" task PR_TIMGAD_GET_MOD_RESTRICT: %d\n", ret); | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_SET_MOD_RESTRICT, 0, 0, 0); | |
if (ret < 0) { | |
fprintf(stderr, "PR_TIMGAD_SET_MOD_RESTRICT to 0 failed: %d (%m)\n", -errno); | |
} else { | |
fprintf(stderr, "Error PR_TIMGAD_SET_MOD_RESTRICT to 0 succeeded\n"); | |
return EXIT_FAILURE; | |
} | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_SET_MOD_RESTRICT, 2, 0, 0); | |
if (ret < 0) { | |
fprintf(stderr, "Error PR_TIMGAD_SET_MOD_RESTRICT to 2 failed: %d (%m)\n", -errno); | |
return EXIT_FAILURE; | |
} | |
ret = prctl(PR_TIMGAD_OPTS, PR_TIMGAD_GET_MOD_RESTRICT, 0, 0, 0); | |
if (ret < 0) { | |
fprintf(stderr, "Error PR_TIMGAD_GET_MOD_RESTRICT failed: %d (%m)\n", -errno); | |
return EXIT_FAILURE; | |
} | |
printf(" task PR_TIMGAD_GET_MOD_RESTRICT: %d\n", ret); | |
execv(args[0], args); | |
fprintf(stderr, "error on execve(): %d (%m)\n", -errno); | |
exit(EXIT_FAILURE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment