2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

zdtm/memfd04: check execveat on memfd that has memory mappings

Signed-off-by: Andrei Vagin <avagin@gmail.com>
This commit is contained in:
Andrei Vagin 2023-09-28 18:07:13 +00:00
parent e86e8dac0d
commit 81a30c3206
4 changed files with 34 additions and 3 deletions

View File

@ -259,6 +259,7 @@ TST_NOFILE := \
memfd02-hugetlb \
memfd03 \
memfd04 \
memfd05 \
shmemfd \
shmemfd-priv \
time \
@ -656,6 +657,7 @@ socket-tcp6-unconn: CFLAGS += -D ZDTM_IPV6
socket-tcp4v6-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK -D ZDTM_IPV4V6
socket-tcp4v6-closing: CFLAGS += -D ZDTM_IPV4V6
memfd02-hugetlb: CFLAGS += -D ZDTM_HUGETLB
memfd05: CFLAGS += -D ZDTM_MEMFD05
sockets00-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
sockets01-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET

View File

@ -1,4 +1,5 @@
#include <linux/memfd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
@ -73,20 +74,46 @@ static const size_t script_len = sizeof(script) - 1;
int main(int argc, char *argv[])
{
#ifdef MEMFD05
char path[PATH_MAX];
char *addr_p, *addr_s;
int rofd;
#endif
int fd;
test_init(argc, argv);
fd = _memfd_create("somename", 0);
if (fd < 0) {
fail("memfd_create()");
pr_perror("memfd_create()");
return 1;
}
if (ftruncate(fd, script_len) == -1) {
pr_perror("ftruncate");
return 1;
}
if (write(fd, script, script_len) != script_len) {
fail("write(memfd)");
pr_perror("write(memfd)");
return 1;
}
#ifdef MEMFD05
snprintf(path, PATH_MAX - 1, "/proc/self/fd/%d", fd);
rofd = open(path, O_RDONLY);
if (rofd < 0) {
pr_perror("unable to open read-only memfd");
return 1;
}
addr_p = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_PRIVATE, rofd, 0);
if (addr_p == MAP_FAILED) {
pr_perror("mmap");
return 1;
}
addr_s = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
if (addr_s == MAP_FAILED) {
pr_perror("mmap");
return 1;
}
#endif
if (!test_exec_fd(fd))
return 1;

1
test/zdtm/static/memfd05.c Symbolic link
View File

@ -0,0 +1 @@
memfd04.c

View File

@ -0,0 +1 @@
memfd04.desc