[CRIU] [PATCH 2/2] zdtm: test for mlocked area restores if programm have no credentials
Pavel Tikhomirov
ptikhomirov at parallels.com
Fri Sep 12 03:39:26 PDT 2014
Test maps 17 pages and mlocks them, then changes user id from root
to 18943, after c/r checks that MAP_LOCKED bit is set for that vma.
Signed-off-by: Pavel Tikhomirov <ptikhomirov at parallels.com>
---
test/zdtm.sh | 2 ++
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/mlock_setuid.c | 55 ++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+)
create mode 100644 test/zdtm/live/static/mlock_setuid.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index da85c92..50fc8fc 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -25,6 +25,7 @@ static/maps01
static/maps02
static/maps04
static/maps05
+static/mlock_setuid
static/maps_file_prot
static/mprotect00
static/mtime_mmap
@@ -197,6 +198,7 @@ TEST_SUID_LIST="
pid00
caps00
maps01
+mlock_setuid
groups
sched_prio00
sched_policy00
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index 4cea9e4..1525b37 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -285,6 +285,7 @@ sigpending: override LDLIBS += -lrt
vdso01: override LDLIBS += -lrt
mntns_link_remap: override CFLAGS += -DZDTM_LINK_REMAP
maps02: get_smaps_bits.o
+mlock_setuid: get_smaps_bits.o
$(LIB): force
$(Q) $(MAKE) -C $(LIBDIR)
diff --git a/test/zdtm/live/static/mlock_setuid.c b/test/zdtm/live/static/mlock_setuid.c
new file mode 100644
index 0000000..b961d1c
--- /dev/null
+++ b/test/zdtm/live/static/mlock_setuid.c
@@ -0,0 +1,55 @@
+#include <sys/types.h>
+#include <unistd.h>
+#include <sys/mman.h>
+#include "zdtmtst.h"
+
+#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);
+ start = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ if (start == MAP_FAILED) {
+ err("mmap failed");
+ return -1;
+ }
+
+ test_msg("Lock vma from %lx to %lx\n", start, start + MEM_SIZE);
+ ret = mlock(start, MEM_SIZE);
+ if (ret < 0) {
+ err("mlock");
+ return -1;
+ }
+
+ test_daemon();
+
+ test_msg("Setuid to 18943\n");
+ ret = setuid(18943);
+ if (ret < 0) {
+ err("setuid");
+ 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 {
+ fail("Vma is not locked after c/r\n");
+ return -1;
+ }
+
+ return 0;
+}
--
1.9.3
More information about the CRIU
mailing list