Skip to content

Commit

Permalink
zdtm/memfd04: check that execveat works on memfd when it has a mapping
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Vagin <[email protected]>
  • Loading branch information
avagin committed Sep 23, 2023
1 parent 1a94432 commit a0483a9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions test/zdtm/static/memfd04.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <linux/memfd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -73,20 +74,27 @@ static const size_t script_len = sizeof(script) - 1;

int main(int argc, char *argv[])
{
char *addr;
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)");
addr = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0);
if (addr == MAP_FAILED) {
pr_perror("mmap");
return 1;
}
memcpy(addr, script, script_len);

if (!test_exec_fd(fd))
return 1;
Expand Down

0 comments on commit a0483a9

Please sign in to comment.