virtiofsd: Don't allow file creation with FUSE_OPEN
PATCH 1/1 virtiofsd: Don't allow file creation with FUSE_OPEN
A well behaved FUSE client uses FUSE_CREATE to create files. It isn't supposed to pass O_CREAT along a FUSE_OPEN request, as documented in the "fuse_lowlevel.h" header :
/**
* Open a file
*
* Open flags are available in fi->flags. The following rules
* apply.
*
* - Creation (O_CREAT, O_EXCL, O_NOCTTY) flags will be
* filtered out / handled by the kernel.
But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call: O_CREAT or O_TMPFILE without mode ***: terminated
This is because virtiofsd ends up passing this flag to openat() without passing a mode_t 4th argument which is mandatory with O_CREAT, and glibc aborts.
The offending path is:
lo_open()
lo_do_open()
lo_inode_open()Other callers of lo_inode_open() only pass O_RDWR and lo_create() passes a valid fd to lo_do_open() which thus doesn't even call lo_inode_open() in this case.
Specifying O_CREAT with FUSE_OPEN is a protocol violation. Check this in lo_open() and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.
The FUSE filesystem doesn't currently support O_TMPFILE, but the very same would happen if O_TMPFILE was passed in a FUSE_OPEN request. Check that as well.
--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/virtiofsd/passthrough_ll.c +6 -0
@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } + err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) {
Signature · 1 line
2.31.1
Quoted 35 lines · * Greg Kurz ([email protected]) wrote:
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.
Quoted 5 lines
The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>
That seems reasonable, so
should you also send a corresponding patch for libfuse's example code we're based on?
Dave
Quoted 24 lines
--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +6
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } + err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) {Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 40 lines · On Thu, 17 Jun 2021 15:29:12 +0100 "Dr. David Alan Gilbert"…
Quoted 39 lines · * Greg Kurz ([email protected]) wrote:
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.
Quoted 9 lines
Quoted 1 line
Signed-off-by Greg Kurz <[email protected]>That seems reasonable, so
Reviewed-by Dr. David Alan Gilbert <[email protected]>should you also send a corresponding patch for libfuse's example code we're based on?
Good idea. I've just done that.
Cheers,
--
Greg
Quoted 26 lines
Dave
Quoted 24 lines
--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +6
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } + err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) {Signature · 1 line
2.31.1
Quoted 13 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.
Quoted 3 lines
But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminated
So did you hit this error with current fuse client. If yes, that means client needs fixing as well?
Or you are doing this fix based on comment in fuse_lowlevel.h.
I am wondering why this protocl restriction is there that open() path should not be able to honor O_CREAT.
Vivek
Quoted 48 lines
This is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +6
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } + err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) {Signature · 1 line
2.31.1
Quoted 14 lines · On Thu, 17 Jun 2021 21:40:07 -0400 Vivek Goyal <[email protected]> wrote:
Quoted 13 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.
Quoted 4 lines
Quoted 3 lines
But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminated
This is also the consequence of virtiofsd being compiled with -D_FORTIFY_SOURCE=2. Without that, no abort but arbitrary data is passed as mode_t argument to the openat() syscall instead.
Quoted 3 lines
So did you hit this error with current fuse client. If yes, that means client needs fixing as well?
I've patched the client to cause this:
fs/fuse/file.c +1 -0
@@ -28,6 +28,7 @@ static int fuse_send_open(struct fuse_mount *fm, u64 nodeid,memset (&inarg,0 ,sizeof (inarg)); inarg.flags = open_flags & ~(O_CREAT |O_EXCL |O_NOCTTY ); +if (opcode ==FUSE_OPEN ) inarg.flags |=O_TMPFILE ;if (!fm->fc->atomic_o_trunc) inarg.flags &= ~O_TRUNC ;
Quoted 5 lines
Or you are doing this fix based on comment in
fuse_lowlevel.h.I am wondering why this protocl restriction is there that
open()path should not be able to honorO_CREAT.
It isn't a protocol restriction IMHO. The distinction between file creation and file opening has always been there since the start. Older versions of the protocol would send FUSE_MKNOD to create a file and then send FUSE_OPEN to open it. Because this was racy, FUSE_CREATE was introduced at some point to do both operations atomically.
Question is : what would be the semantics of O_CREAT in FUSE_OPEN ?
Quoted 51 lines
Vivek
Quoted 48 lines
This is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +6
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } + err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) {Signature · 1 line
2.31.1
Miklos Szeredi
maintainerQuoted 50 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +0
-0
tools/virtiofsd/passthrough_ll.c static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) · line 2153
Quoted 9 lines
tools/virtiofsd/passthrough_ll.c +6
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; } +/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +
Okay. Question comes to mind whether the check should be even more strict, possibly allowing just a specific set of flags, and erroring out on everything else?
AFAICS linux kernel should never pass anything to FUSE_OPEN outside of this set:
O_RDONLYO_WRONLYO_RDWRO_APPENDO_NDELAYO_NONBLOCK__O_SYNCO_DSYNC
FASYNCO_DIRECTO_LARGEFILEO_NOFOLLOWO_NOATIME
A separate question is whether virtiofsd should also be silently ignoring some of the above flags.
Thanks,
Miklos
Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +0
-1err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) { --2.31.1
Quoted 54 lines · On Fri, 18 Jun 2021 10:58:33 +0200 Miklos Szeredi <[email protected]> wrote:
Quoted 53 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +0
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; }
Quoted 11 lines
tools/virtiofsd/passthrough_ll.c static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) · line 2153
Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +6
-0+/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +Okay. Question comes to mind whether the check should be even more strict, possibly allowing just a specific set of flags, and erroring out on everything else?
I've focused on O_CREAT and O_TMPFILE because they cause an explicit abort() in glibc when the code is compiled with -D_FORTIFY_SOURCE=2, but yes, maybe it could make sense to check more of them.
Quoted 16 lines
AFAICS linux kernel should never pass anything to
FUSE_OPENoutside of this set:
O_RDONLYO_WRONLYO_RDWRO_APPENDO_NDELAYO_NONBLOCK__O_SYNCO_DSYNC
FASYNCO_DIRECTO_LARGEFILEO_NOFOLLOWO_NOATIME
Quoted 3 lines
A separate question is whether virtiofsd should also be silently ignoring some of the above flags.
Dunno on the top of my head...
BTW, as suggested by Dave, I've submitted a similar patch to upstream libfuse:
https://github.com/libfuse/libfuse/pull/615
And I got interesting suggestions:
1) do it in core FUSE, i.e. fuse_lowlevel.c, since this isn't specific to passthrough_ll AFAICT
2) print out an error
3) exit
1 makes a lot of sense. I guess 2 is fine this cannot be used by a buggy guest to flood some log file on the host. 3 doesn't seems to be an acceptable solution, and it wouldn't change much the outcome compared to what we have now.
So I will go for 1 and 2.
Cheers,
--
Greg
Quoted 11 lines
Thanks,
MiklosQuoted 6 lines
tools/virtiofsd/passthrough_ll.c +0
-1err =lo_do_open (lo, inode,-1 , fi);lo_inode_put (lo, &inode);if (err) { --2.31.1
Miklos Szeredi
maintainerQuoted 90 lines · Greg Kurz
Quoted 54 lines · On Fri, 18 Jun 2021 10:58:33 +0200 Miklos Szeredi <[email protected]> wrote:
Quoted 53 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/passthrough_ll.c +0
-0@@ -2145,6 +2145,12 @@ static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi)return ; }Quoted 11 lines
tools/virtiofsd/passthrough_ll.c static void lo_open(fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi) · line 2153
Quoted 6 lines
tools/virtiofsd/passthrough_ll.c +6
-0+/* File creation is handled by lo_create() */ +if (fi->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +Okay. Question comes to mind whether the check should be even more strict, possibly allowing just a specific set of flags, and erroring out on everything else?
I've focused on
O_CREATandO_TMPFILEbecause they cause an explicitabort()in glibc when the code is compiled with -D_FORTIFY_SOURCE=2, but yes, maybe it could make sense to check more of them.Quoted 16 lines
AFAICS linux kernel should never pass anything to
FUSE_OPENoutside of this set:
O_RDONLYO_WRONLYO_RDWRO_APPENDO_NDELAYO_NONBLOCK__O_SYNCO_DSYNC
FASYNCO_DIRECTO_LARGEFILEO_NOFOLLOWO_NOATIME
Quoted 5 lines
Quoted 3 lines
A separate question is whether virtiofsd should also be silently ignoring some of the above flags.
Dunno on the top of my head...
Let's discuss this separately as this is mostly unrelated. Added an item to the virtiofs-todo etherpad.
Quoted 12 lines
BTW, as suggested by Dave, I've submitted a similar patch to upstream libfuse:
https://github.com/libfuse/libfuse/pull/615
And I got interesting suggestions:
1) do it in core FUSE, i.e.fuse_lowlevel.c, since this isn't specific topassthrough_llAFAICT
2) print out an error
3) exit
Quoted 6 lines
1 makes a lot of sense. I guess 2 is fine this cannot be used by a buggy guest to flood some log file on the host. 3 doesn't seems to be an acceptable solution, and it wouldn't change much the outcome compared to what we have now.
So I will go for 1 and 2.
Okay, good.
Thanks,
Miklos
Quoted 35 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.
Quoted 8 lines
The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)
Thank you!
Quoted 40 lines · On Mon, 21 Jun 2021 14:36:12 +0100 Stefan Hajnoczi <[email protected]> wrote:
Quoted 39 lines · Greg Kurz
A well behaved FUSE client uses
FUSE_CREATEto create files. It isn't supposed to passO_CREATalong aFUSE_OPENrequest, as documented in the "fuse_lowlevel.h" header :/**
* Open a file
*
* Open flags are available infi->flags. The following rules
* apply.
*
* - Creation (O_CREAT,O_EXCL,O_NOCTTY) flags will be
* filtered out / handled by the kernel.But if it does anyway, virtiofsd crashes with:
*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedThis is because virtiofsd ends up passing this flag to
openat()without passing amode_t4th argument which is mandatory withO_CREAT, and glibc aborts.The offending path is:
lo_open()lo_do_open() lo_inode_open()Other callers of
lo_inode_open()only passO_RDWRandlo_create()passes a valid fd tolo_do_open()which thus doesn't even calllo_inode_open()in this case.Specifying
O_CREATwithFUSE_OPENis a protocol violation. Check this inlo_open()and return an error to the client : EINVAL since this is already what glibc returns with other illegal flag combinations.The FUSE filesystem doesn't currently support
O_TMPFILE, but the very same would happen ifO_TMPFILEwas passed in aFUSE_OPENrequest. Check that as well.
Quoted 8 lines
Quoted 4 lines
Signed-off-by Greg Kurz <[email protected]>--- tools/virtiofsd/passthrough_ll.c | 6 ++++++ 1 file changed, 6 insertions(+)Thank you!
Reviewed-by Stefan Hajnoczi <[email protected]>
Upstream libfuse folks suggested to do the change in fuse_lowlevel.c so that it fixes all filesystems, not only those based on passthrough_ll.c.
I'll thus post a new version.
They also seemed to be a little concerned by open() returning EINVAL to the end user who did nothing wrong (kernel did). They suggested that the server should rather print out an error and exit... which isn't really an option for us. And anyway, we already return EINVAL when we can't extract the arguments of the request. So I won't address this concern, but I still wanted to share it here.