From 5b34688832ec6fd81e395a1b5b3ea29a3ff483e9 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 23 Nov 2022 15:46:43 +0100 Subject: executor: simplify setup_loop_device We can close memfd as soon as we passed it to LOOP_SET_FD (it holds a reference to the file). --- pkg/csource/generated.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'pkg/csource/generated.go') diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go index 5144782b6..754feaa68 100644 --- a/pkg/csource/generated.go +++ b/pkg/csource/generated.go @@ -6672,7 +6672,7 @@ static int puff_zlib_to_file(const unsigned char* source, unsigned long sourcele #include #include #include -static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* memfd_p, int* loopfd_p) +static int setup_loop_device(unsigned char* data, unsigned long size, const char* loopname, int* loopfd_p) { int err = 0, loopfd = -1; int memfd = syscall(__NR_memfd_create, "syzkaller", 0); @@ -6704,7 +6704,7 @@ static int setup_loop_device(unsigned char* data, unsigned long size, const char } } - *memfd_p = memfd; + close(memfd); *loopfd_p = loopfd; return 0; @@ -6722,11 +6722,11 @@ error: static long syz_read_part_table(volatile unsigned long size, volatile long image) { unsigned char* data = (unsigned char*)image; - int err = 0, res = -1, loopfd = -1, memfd = -1; + int err = 0, res = -1, loopfd = -1; char loopname[64]; snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); - if (setup_loop_device(data, size, loopname, &memfd, &loopfd) == -1) + if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; struct loop_info64 info; @@ -6758,7 +6758,6 @@ error_clear_loop: if (res) ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); - close(memfd); errno = err; return res; } @@ -6778,7 +6777,7 @@ static long syz_mount_image( volatile long image) { unsigned char* data = (unsigned char*)image; - int res = -1, err = 0, loopfd = -1, memfd = -1, need_loop_device = !!size; + int res = -1, err = 0, loopfd = -1, need_loop_device = !!size; char* mount_opts = (char*)optsarg; char* target = (char*)dir; char* fs = (char*)fsarg; @@ -6788,7 +6787,7 @@ static long syz_mount_image( if (need_loop_device) { memset(loopname, 0, sizeof(loopname)); snprintf(loopname, sizeof(loopname), "/dev/loop%llu", procid); - if (setup_loop_device(data, size, loopname, &memfd, &loopfd) == -1) + if (setup_loop_device(data, size, loopname, &loopfd) == -1) return -1; source = loopname; } @@ -6836,7 +6835,6 @@ error_clear_loop: if (need_loop_device) { ioctl(loopfd, LOOP_CLR_FD, 0); close(loopfd); - close(memfd); } errno = err; return res; -- cgit mrf-deployment