aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/csource
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2022-11-23 15:46:43 +0100
committerDmitry Vyukov <dvyukov@google.com>2022-11-23 16:43:13 +0100
commit5b34688832ec6fd81e395a1b5b3ea29a3ff483e9 (patch)
treee496419231f6648c3bbe553c37fcf0e883e4e40b /pkg/csource
parent928544a6c60ea87fafae67c861747ee5b41868b3 (diff)
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).
Diffstat (limited to 'pkg/csource')
-rw-r--r--pkg/csource/generated.go14
1 files changed, 6 insertions, 8 deletions
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 <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/types.h>
-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;