2014-09-12 14:39:26 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include "zdtmtst.h"
|
2017-05-02 16:51:46 -07:00
|
|
|
#include "get_smaps_bits.h"
|
2014-09-12 14:39:26 +04:00
|
|
|
|
|
|
|
#define MEM_SIZE (69632)
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
void *start;
|
|
|
|
unsigned long new_flags = 0;
|
|
|
|
unsigned long new_madv = 0;
|
|
|
|
test_init(argc, argv);
|
|
|
|
|
|
|
|
test_msg("Alloc vma of size %d\n", MEM_SIZE);
|
2021-07-19 07:28:38 +00:00
|
|
|
start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
2014-09-12 14:39:26 +04:00
|
|
|
if (start == MAP_FAILED) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("mmap failed");
|
2014-09-12 14:39:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2021-07-19 07:28:38 +00:00
|
|
|
test_msg("Lock vma from %p to %lx\n", start, (unsigned long)start + MEM_SIZE);
|
2014-09-12 14:39:26 +04:00
|
|
|
ret = mlock(start, MEM_SIZE);
|
|
|
|
if (ret < 0) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("mlock");
|
2014-09-12 14:39:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_daemon();
|
|
|
|
|
|
|
|
test_msg("Setuid to 18943\n");
|
|
|
|
ret = setuid(18943);
|
|
|
|
if (ret < 0) {
|
2015-10-20 18:10:00 +03:00
|
|
|
pr_perror("setuid");
|
2014-09-12 14:39:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
test_waitsig();
|
|
|
|
|
|
|
|
ret = get_smaps_bits((unsigned long)start, &new_flags, &new_madv);
|
|
|
|
if (ret < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
test_msg("Check smaps flags for MAP_LOCKED\n");
|
|
|
|
if (new_flags & MAP_LOCKED) {
|
|
|
|
pass();
|
|
|
|
} else {
|
2021-04-22 14:54:04 -07:00
|
|
|
fail("Vma is not locked after c/r");
|
2014-09-12 14:39:26 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|