aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Duo <stefanoduo@google.com>2020-08-16 15:22:35 +0000
committerDmitry Vyukov <dvyukov@google.com>2020-08-18 14:18:38 +0200
commit6fe61c6bc722931e08eefbbcf3a270af74997ef8 (patch)
tree5b14ab4b9b001c3de3d0739a31b2b3d40a89e924
parentb9683dbdfdbea5815c2cf48b20aada181dca1be3 (diff)
executor/common_linux.go: fix build breakage for Linux 4.14
Locally define structures and constants required by syz_fuse_handle_req() and remove linux/fuse.h. dependency. Reported-by: syzbot+f5f98e1608b272285aa5@syzkaller.appspotmail.com
-rw-r--r--executor/common_linux.h92
-rw-r--r--pkg/csource/generated.go76
2 files changed, 158 insertions, 10 deletions
diff --git a/executor/common_linux.h b/executor/common_linux.h
index e8a485147..244707191 100644
--- a/executor/common_linux.h
+++ b/executor/common_linux.h
@@ -4269,12 +4269,95 @@ static void setup_usb()
#if SYZ_EXECUTOR || __NR_syz_fuse_handle_req
#include <fcntl.h>
-#include <linux/fuse.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
+// From linux/fuse.h
+#define FUSE_MIN_READ_BUFFER 8192
+
+// From linux/fuse.h
+enum fuse_opcode {
+ FUSE_LOOKUP = 1,
+ FUSE_FORGET = 2, // no reply
+ FUSE_GETATTR = 3,
+ FUSE_SETATTR = 4,
+ FUSE_READLINK = 5,
+ FUSE_SYMLINK = 6,
+ FUSE_MKNOD = 8,
+ FUSE_MKDIR = 9,
+ FUSE_UNLINK = 10,
+ FUSE_RMDIR = 11,
+ FUSE_RENAME = 12,
+ FUSE_LINK = 13,
+ FUSE_OPEN = 14,
+ FUSE_READ = 15,
+ FUSE_WRITE = 16,
+ FUSE_STATFS = 17,
+ FUSE_RELEASE = 18,
+ FUSE_FSYNC = 20,
+ FUSE_SETXATTR = 21,
+ FUSE_GETXATTR = 22,
+ FUSE_LISTXATTR = 23,
+ FUSE_REMOVEXATTR = 24,
+ FUSE_FLUSH = 25,
+ FUSE_INIT = 26,
+ FUSE_OPENDIR = 27,
+ FUSE_READDIR = 28,
+ FUSE_RELEASEDIR = 29,
+ FUSE_FSYNCDIR = 30,
+ FUSE_GETLK = 31,
+ FUSE_SETLK = 32,
+ FUSE_SETLKW = 33,
+ FUSE_ACCESS = 34,
+ FUSE_CREATE = 35,
+ FUSE_INTERRUPT = 36,
+ FUSE_BMAP = 37,
+ FUSE_DESTROY = 38,
+ FUSE_IOCTL = 39,
+ FUSE_POLL = 40,
+ FUSE_NOTIFY_REPLY = 41,
+ FUSE_BATCH_FORGET = 42,
+ FUSE_FALLOCATE = 43,
+ FUSE_READDIRPLUS = 44,
+ FUSE_RENAME2 = 45,
+ FUSE_LSEEK = 46,
+ FUSE_COPY_FILE_RANGE = 47,
+ FUSE_SETUPMAPPING = 48,
+ FUSE_REMOVEMAPPING = 49,
+
+ // CUSE specific operations
+ CUSE_INIT = 4096,
+
+ // Reserved opcodes: helpful to detect structure endian-ness
+ CUSE_INIT_BSWAP_RESERVED = 1048576, // CUSE_INIT << 8
+ FUSE_INIT_BSWAP_RESERVED = 436207616, // FUSE_INIT << 24
+};
+
+// From linux/fuse.h
+struct fuse_in_header {
+ uint32 len;
+ uint32 opcode;
+ uint64 unique;
+ uint64 nodeid;
+ uint32 uid;
+ uint32 gid;
+ uint32 pid;
+ uint32 padding;
+};
+
+// From linux/fuse.h
+struct fuse_out_header {
+ uint32 len;
+ // This is actually a int32_t but *_t variants fail to compile inside
+ // the executor (it appends an additional _t for some reason) and int32
+ // does not exist. Since we don't touch this field, defining it as
+ // unsigned should not cause any problems.
+ uint32 error;
+ uint64 unique;
+};
+
// Struct shared between syz_fuse_handle_req() and the fuzzer. Used to provide
// a fuzzed response for each request type.
struct syz_fuse_req_out {
@@ -4297,10 +4380,9 @@ struct syz_fuse_req_out {
};
// Link the reponse to the request and send it to /dev/fuse.
-static int
-fuse_send_response(int fd,
- const struct fuse_in_header* in_hdr,
- struct fuse_out_header* out_hdr)
+static int fuse_send_response(int fd,
+ const struct fuse_in_header* in_hdr,
+ struct fuse_out_header* out_hdr)
{
if (!out_hdr) {
debug("fuse_send_response: received a NULL out_hdr\n");
diff --git a/pkg/csource/generated.go b/pkg/csource/generated.go
index 83781ded9..fae8005ae 100644
--- a/pkg/csource/generated.go
+++ b/pkg/csource/generated.go
@@ -8932,11 +8932,78 @@ static void setup_usb()
#if SYZ_EXECUTOR || __NR_syz_fuse_handle_req
#include <fcntl.h>
-#include <linux/fuse.h>
#include <stddef.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
+#define FUSE_MIN_READ_BUFFER 8192
+enum fuse_opcode {
+ FUSE_LOOKUP = 1,
+ FUSE_FORGET = 2,
+ FUSE_GETATTR = 3,
+ FUSE_SETATTR = 4,
+ FUSE_READLINK = 5,
+ FUSE_SYMLINK = 6,
+ FUSE_MKNOD = 8,
+ FUSE_MKDIR = 9,
+ FUSE_UNLINK = 10,
+ FUSE_RMDIR = 11,
+ FUSE_RENAME = 12,
+ FUSE_LINK = 13,
+ FUSE_OPEN = 14,
+ FUSE_READ = 15,
+ FUSE_WRITE = 16,
+ FUSE_STATFS = 17,
+ FUSE_RELEASE = 18,
+ FUSE_FSYNC = 20,
+ FUSE_SETXATTR = 21,
+ FUSE_GETXATTR = 22,
+ FUSE_LISTXATTR = 23,
+ FUSE_REMOVEXATTR = 24,
+ FUSE_FLUSH = 25,
+ FUSE_INIT = 26,
+ FUSE_OPENDIR = 27,
+ FUSE_READDIR = 28,
+ FUSE_RELEASEDIR = 29,
+ FUSE_FSYNCDIR = 30,
+ FUSE_GETLK = 31,
+ FUSE_SETLK = 32,
+ FUSE_SETLKW = 33,
+ FUSE_ACCESS = 34,
+ FUSE_CREATE = 35,
+ FUSE_INTERRUPT = 36,
+ FUSE_BMAP = 37,
+ FUSE_DESTROY = 38,
+ FUSE_IOCTL = 39,
+ FUSE_POLL = 40,
+ FUSE_NOTIFY_REPLY = 41,
+ FUSE_BATCH_FORGET = 42,
+ FUSE_FALLOCATE = 43,
+ FUSE_READDIRPLUS = 44,
+ FUSE_RENAME2 = 45,
+ FUSE_LSEEK = 46,
+ FUSE_COPY_FILE_RANGE = 47,
+ FUSE_SETUPMAPPING = 48,
+ FUSE_REMOVEMAPPING = 49,
+ CUSE_INIT = 4096,
+ CUSE_INIT_BSWAP_RESERVED = 1048576,
+ FUSE_INIT_BSWAP_RESERVED = 436207616,
+};
+struct fuse_in_header {
+ uint32 len;
+ uint32 opcode;
+ uint64 unique;
+ uint64 nodeid;
+ uint32 uid;
+ uint32 gid;
+ uint32 pid;
+ uint32 padding;
+};
+struct fuse_out_header {
+ uint32 len;
+ uint32 error;
+ uint64 unique;
+};
struct syz_fuse_req_out {
struct fuse_out_header* init;
struct fuse_out_header* lseek;
@@ -8955,10 +9022,9 @@ struct syz_fuse_req_out {
struct fuse_out_header* create_open;
struct fuse_out_header* ioctl;
};
-static int
-fuse_send_response(int fd,
- const struct fuse_in_header* in_hdr,
- struct fuse_out_header* out_hdr)
+static int fuse_send_response(int fd,
+ const struct fuse_in_header* in_hdr,
+ struct fuse_out_header* out_hdr)
{
if (!out_hdr) {
debug("fuse_send_response: received a NULL out_hdr\n");