virtiofsd: Don't allow file creation with FUSE_OPEN
PATCH v2 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 the client happens to do it anyway, the server ends up passing this flag to open() without the mandatory mode_t 4th argument. Since open() is a variadic function, glibc will happily pass whatever it finds on the stack to the syscall. If this file is compiled with -D_FORTIFY_SOURCE=2, glibc will even detect that and abort:
*** invalid openat64 call: O_CREAT or O_TMPFILE without mode ***: terminated
Specifying O_CREAT with FUSE_OPEN is a protocol violation. Check this in do_open(), print out a message and return an error to the client, EINVAL like we already do when fuse_mbuf_iter_advance() fails.
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.
---
v2:
- do the check in core FUSE code instead of passthrough_ll (libfuse folks)
tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ 1 file changed, 6 insertions(+)
tools/virtiofsd/fuse_lowlevel.c +6 -0
@@ -1084,6 +1084,12 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid,return ; } +/* File creation is handled by do_create() or do_mknod() */ +if (arg->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +memset (&fi,0 ,sizeof (fi)); fi.flags = arg->flags; fi.kill_priv = arg->open_flags &FUSE_OPEN_KILL_SUIDGID ;
Signature · 1 line
2.31.1
Quoted 25 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 the client happens to do it anyway, the server ends up passing this flag to
open()without the mandatorymode_t4th argument. Sinceopen()is a variadic function, glibc will happily pass whatever it finds on the stack to the syscall. If this file is compiled with -D_FORTIFY_SOURCE=2, glibc will even detect that and abort:*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedSpecifying
O_CREATwithFUSE_OPENis a protocol violation. Check this indo_open(), print out a message and return an error to the client, EINVAL like we already do whenfuse_mbuf_iter_advance()fails.
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]>
Quoted 29 lines
---
v2:
- do the check in core FUSE code instead ofpassthrough_ll(libfuse folks)tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/fuse_lowlevel.c +6
-0@@ -1084,6 +1084,12 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid,return ; } +/* File creation is handled by do_create() or do_mknod() */ +if (arg->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +memset (&fi,0 ,sizeof (fi)); fi.flags = arg->flags; fi.kill_priv = arg->open_flags &FUSE_OPEN_KILL_SUIDGID ;Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Quoted 25 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 the client happens to do it anyway, the server ends up passing this flag to
open()without the mandatorymode_t4th argument. Sinceopen()is a variadic function, glibc will happily pass whatever it finds on the stack to the syscall. If this file is compiled with -D_FORTIFY_SOURCE=2, glibc will even detect that and abort:*** invalid openat64 call:
O_CREATorO_TMPFILEwithout mode ***: terminatedSpecifying
O_CREATwithFUSE_OPENis a protocol violation. Check this indo_open(), print out a message and return an error to the client, EINVAL like we already do whenfuse_mbuf_iter_advance()fails.
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]>
Queued
Quoted 30 lines
---
v2:
- do the check in core FUSE code instead ofpassthrough_ll(libfuse folks)tools/virtiofsd/fuse_lowlevel.c | 6 ++++++ 1 file changed, 6 insertions(+)tools/virtiofsd/fuse_lowlevel.c +6
-0@@ -1084,6 +1084,12 @@ static void do_open(fuse_req_t req, fuse_ino_t nodeid,return ; } +/* File creation is handled by do_create() or do_mknod() */ +if (arg->flags & (O_CREAT |O_TMPFILE )) { +fuse_reply_err (req,EINVAL ); +return ; + } +memset (&fi,0 ,sizeof (fi)); fi.flags = arg->flags; fi.kill_priv = arg->open_flags &FUSE_OPEN_KILL_SUIDGID ;Signature · 1 line
2.31.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK