mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-22 09:58:09 +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:
parent
e86e8dac0d
commit
81a30c3206
@ -259,6 +259,7 @@ TST_NOFILE := \
|
|||||||
memfd02-hugetlb \
|
memfd02-hugetlb \
|
||||||
memfd03 \
|
memfd03 \
|
||||||
memfd04 \
|
memfd04 \
|
||||||
|
memfd05 \
|
||||||
shmemfd \
|
shmemfd \
|
||||||
shmemfd-priv \
|
shmemfd-priv \
|
||||||
time \
|
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-last-ack: CFLAGS += -D ZDTM_TCP_LAST_ACK -D ZDTM_IPV4V6
|
||||||
socket-tcp4v6-closing: CFLAGS += -D ZDTM_IPV4V6
|
socket-tcp4v6-closing: CFLAGS += -D ZDTM_IPV4V6
|
||||||
memfd02-hugetlb: CFLAGS += -D ZDTM_HUGETLB
|
memfd02-hugetlb: CFLAGS += -D ZDTM_HUGETLB
|
||||||
|
memfd05: CFLAGS += -D ZDTM_MEMFD05
|
||||||
|
|
||||||
sockets00-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
sockets00-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
||||||
sockets01-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
sockets01-seqpacket: CFLAGS += -D ZDTM_UNIX_SEQPACKET
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <linux/memfd.h>
|
#include <linux/memfd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -73,20 +74,46 @@ static const size_t script_len = sizeof(script) - 1;
|
|||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
#ifdef MEMFD05
|
||||||
|
char path[PATH_MAX];
|
||||||
|
char *addr_p, *addr_s;
|
||||||
|
int rofd;
|
||||||
|
#endif
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
test_init(argc, argv);
|
test_init(argc, argv);
|
||||||
|
|
||||||
fd = _memfd_create("somename", 0);
|
fd = _memfd_create("somename", 0);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
fail("memfd_create()");
|
pr_perror("memfd_create()");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (ftruncate(fd, script_len) == -1) {
|
||||||
|
pr_perror("ftruncate");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(fd, script, script_len) != script_len) {
|
if (write(fd, script, script_len) != script_len) {
|
||||||
fail("write(memfd)");
|
pr_perror("write(memfd)");
|
||||||
return 1;
|
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))
|
if (!test_exec_fd(fd))
|
||||||
return 1;
|
return 1;
|
||||||
|
1
test/zdtm/static/memfd05.c
Symbolic link
1
test/zdtm/static/memfd05.c
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
memfd04.c
|
1
test/zdtm/static/memfd05.desc
Symbolic link
1
test/zdtm/static/memfd05.desc
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
memfd04.desc
|
Loading…
x
Reference in New Issue
Block a user