Skip to content

Instantly share code, notes, and snippets.

@tixxdz
Created February 2, 2017 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tixxdz/f7d1eadd4728b6aec00b8c2438411b15 to your computer and use it in GitHub Desktop.
Save tixxdz/f7d1eadd4728b6aec00b8c2438411b15 to your computer and use it in GitHub Desktop.
Timgad LSM test
#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