From 2d9c9156416a36d7a757db336df0fc1edbd378b1 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 11 Feb 2023 10:07:55 -0500 Subject: [PATCH] Return NOTTY for all btrfs ioctl calls mergerfs tries to pass through ioctl calls but due to the complexity of btrfs calls their is risk of segfaults. In the future it may be required to whitelist all supported ioctl calls. --- src/fuse_ioctl.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/fuse_ioctl.cpp b/src/fuse_ioctl.cpp index 6f480221..0a8f434f 100644 --- a/src/fuse_ioctl.cpp +++ b/src/fuse_ioctl.cpp @@ -44,6 +44,9 @@ typedef char IOCTL_BUF[4096]; #define IOCTL_APP_TYPE 0xDF #define IOCTL_FILE_INFO _IOWR(IOCTL_APP_TYPE,0,IOCTL_BUF) +// From linux/btrfs.h +#define BTRFS_IOCTL_MAGIC 0x94 + #ifndef FS_IOC_GETFLAGS # define FS_IOC_GETFLAGS _IOR('f',1,long) #endif @@ -314,6 +317,13 @@ namespace l return (_IOC_TYPE(cmd_) == IOCTL_APP_TYPE); } + static + bool + is_btrfs_ioctl_cmd(const unsigned long cmd_) + { + return (_IOC_TYPE(cmd_) == BTRFS_IOCTL_MAGIC); + } + static int ioctl_custom(const fuse_file_info_t *ffi_, @@ -340,6 +350,8 @@ namespace FUSE void *data_, uint32_t *out_bufsz_) { + if(l::is_btrfs_ioctl_cmd(cmd_)) + return -ENOTTY; if(l::is_mergerfs_ioctl_cmd(cmd_)) return l::ioctl_custom(ffi_,cmd_,data_);