int main(int argc, char *argv[]) { int ret, whichtest; ret = prctl(PR_GET_KEEPCAPS); if (ret) { tst_resm(TBROK, "keepcaps was already set?\n"); tst_exit(); } if (!am_root()) { tst_resm(TBROK, "Run me as root and privileged\n"); tst_exit(); } if (argc < 2) { tst_resm(TBROK, "Usage: %s <tescase_num>", argv[0]); tst_exit(); } whichtest = atoi(argv[1]); if (whichtest < 1 || whichtest > 3) { tst_resm(TFAIL, "Valid tests are 1-3\n"); tst_exit(); } switch(whichtest) { case 1: do_setuid(EXPECT_NOPRIVS); /* does not return */ case 2: ret = prctl(PR_SET_KEEPCAPS, 1); if (ret == -1) { tst_resm(TFAIL|TERRNO, "PR_SET_KEEPCAPS failed\n"); tst_exit(); } ret = prctl(PR_GET_KEEPCAPS); if (!ret) { tst_resm(TFAIL|TERRNO, "PR_SET_KEEPCAPS did not set keepcaps\n"); tst_exit(); } do_setuid(EXPECT_PRIVS); /* does not return */ case 3: ret = prctl(PR_GET_SECUREBITS); ret = prctl(PR_SET_SECUREBITS, ret | SECBIT_KEEP_CAPS); if (ret == -1) { tst_resm(TFAIL|TERRNO, "PR_SET_SECUREBITS failed\n"); tst_exit(); } ret = prctl(PR_GET_KEEPCAPS); if (!ret) { tst_resm(TFAIL|TERRNO, "PR_SET_SECUREBITS did not set keepcaps\n"); tst_exit(); } do_setuid(EXPECT_PRIVS); /* does not return */ default: tst_resm(TFAIL, "should not reach here\n"); tst_exit(); } tst_resm(TFAIL, "should not reach here\n"); tst_exit(); }
int main(int argc, char *argv[]) { int ret, whichtest; tst_require_root(NULL); ret = prctl(PR_GET_KEEPCAPS); if (ret) tst_brkm(TBROK, NULL, "keepcaps was already set?"); if (argc < 2) tst_brkm(TBROK, NULL, "Usage: %s <tescase_num>", argv[0]); whichtest = atoi(argv[1]); if (whichtest < 1 || whichtest > 3) tst_brkm(TFAIL, NULL, "Valid tests are 1-3"); switch (whichtest) { case 1: do_setuid(EXPECT_NOPRIVS); /* does not return */ case 2: ret = prctl(PR_SET_KEEPCAPS, 1); if (ret == -1) { tst_brkm(TFAIL | TERRNO, NULL, "PR_SET_KEEPCAPS failed"); } ret = prctl(PR_GET_KEEPCAPS); if (!ret) { tst_brkm(TFAIL | TERRNO, NULL, "PR_SET_KEEPCAPS did not set keepcaps"); } do_setuid(EXPECT_PRIVS); /* does not return */ case 3: ret = prctl(PR_GET_SECUREBITS); ret = prctl(PR_SET_SECUREBITS, ret | SECBIT_KEEP_CAPS); if (ret == -1) { tst_brkm(TFAIL | TERRNO, NULL, "PR_SET_SECUREBITS failed"); } ret = prctl(PR_GET_KEEPCAPS); if (!ret) { tst_brkm(TFAIL | TERRNO, NULL, "PR_SET_SECUREBITS did not set keepcaps"); } do_setuid(EXPECT_PRIVS); /* does not return */ default: tst_brkm(TFAIL, NULL, "Valid tests are 1-3"); } }
int main(void) { int exit_status; /* Save the real and effective user IDs. */ ruid = getuid(); exit_status = do_setuid(); exit(exit_status); }
/** * <Ring 1> The main loop of TASK MM. * *****************************************************************************/ PUBLIC void task_mm() { init_mm(); while (1) { send_recv(RECEIVE, ANY, &mm_msg); int src = mm_msg.source; int reply = 1; int msgtype = mm_msg.type; switch (msgtype) { case FORK: mm_msg.RETVAL = do_fork(); break; case EXIT: do_exit(mm_msg.STATUS); reply = 0; break; case EXEC: mm_msg.RETVAL = do_exec(); break; case WAIT: do_wait(); reply = 0; break; case KILL: mm_msg.RETVAL = do_kill(); break; case RAISE: mm_msg.RETVAL = do_raise(); break; case BRK: mm_msg.RETVAL = do_brk(); break; case ACCT: mm_msg.RETVAL = do_acct(); break; case GETUID: mm_msg.RETVAL = do_getuid(); break; case SETUID: mm_msg.RETVAL = do_setuid(); break; case GETGID: mm_msg.RETVAL = do_getgid(); break; case SETGID: mm_msg.RETVAL = do_setgid(); break; case GETEUID: mm_msg.RETVAL = do_geteuid(); break; case GETEGID: mm_msg.RETVAL = do_getegid(); break; case SIGACTION: mm_msg.RETVAL = do_sigaction(); break; case ALARM: mm_msg.RETVAL = do_alarm(); break; default: dump_msg("MM::unknown msg", &mm_msg); assert(0); break; } if (reply) { mm_msg.type = SYSCALL_RET; send_recv(SEND, src, &mm_msg); } } }