Skip to contentSkip to conversation

Pass "allow owner override" flags from NFSD down to actual FS.

PATCH Oleg Drokin 3 participants 4 messages Apr 22, 2006 – Apr 28, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello!

NFSD does its own internal checks to possibly override restrictive file mode for file owner already, to allow writing into (opened) file with some restrictive mode (like 0000). But it does not pass this info down to actual filesystems, and if that filesystem is also doing permission checks in open, such an open would fail at FS-level.
(I thought of making an example with NFS exported with NFS, but this appears
to be not allowed, so I choose different example).
For example Lustre is contacting its metadata server for every open, and metadata server does permission checks for open, obviously.

I wonder if something like the patch below can be useful for any other distributed FS now in use and ultimately to end up accepted into vanilla tree?

include/asm-generic/fcntl.h renamed from include/asm-generic/fcntl.h.orig +3 -0
@@ -52,6 +52,9 @@
 #ifndef O_NDELAY
 #define O_NDELAY	O_NONBLOCK
 #endif
+#ifndef O_OWNER_OVERRIDE
+#define O_OWNER_OVERRIDE 02000000
+#endif
 
 #define F_DUPFD		0	/* dup */
 #define F_GETFD		1	/* get close_on_exec */
include/linux/fs.h renamed from include/linux/fs.h.orig +1 -0
@@ -265,6 +265,7 @@ typedef void (dio_iodone_t)(struct kiocb
 #define ATTR_KILL_SUID	2048
 #define ATTR_KILL_SGID	4096
 #define ATTR_FILE	8192
+#define ATTR_OWNER_OVERRIDE	16384
 
 /*
  * This is the Inode Attributes structure, used for notify_change().  It
fs/nfsd/vfs.c renamed from fs/nfsd/vfs.c.orig +4 -3
@@ -341,9 +341,10 @@ nfsd_setattr(struct svc_rqst *rqstp, str
 	if ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid)
 		iap->ia_valid |= ATTR_KILL_SGID;
 
-	/* Change the attributes. */
+	/* Change the attributes. Allow owner of file to change attributes
+	 * even if mode does not permit so. */
 
-	iap->ia_valid |= ATTR_CTIME;
+	iap->ia_valid |= ATTR_CTIME | ATTR_OWNER_OVERRIDE;
 
 	err = nfserr_notsync;
 	if (!check_guard || guardtime == inode->i_ctime.tv_sec) {
@@ -640,7 +641,7 @@ nfsd_open(struct svc_rqst *rqstp, struct
 {
 	struct dentry	*dentry;
 	struct inode	*inode;
-	int		flags = O_RDONLY|O_LARGEFILE, err;
+	int		flags = O_RDONLY|O_LARGEFILE|O_OWNER_OVERRIDE, err;
 
 	/*
 	 * If we get here, then the client has already done an "open",
#1 lore raw

include/asm-generic/fcntl.h line 56

Quoted 9 lines · On Sat, 22 Apr 2006 23:29:35 +0300 Oleg Drokin <[email protected]> wrote:
include/asm-generic/fcntl.h renamed from include/asm-generic/fcntl.h.orig +2 -0
@@ -52,6 +52,9 @@
 #ifndef O_NDELAY
 #define O_NDELAY	O_NONBLOCK
 #endif
+#ifndef O_OWNER_OVERRIDE
+#define O_OWNER_OVERRIDE 02000000
                            ^^^^^^^^

Choose again, this clashes with O_DIRECT on alpha and O_RSYNC on parisc. (Or define O_OWNER_OVERRIDE for them.)

Signature · 3 lines
Cheers,
Stephen Rothwell                    [email protected]
http://www.canb.auug.org.au/~sfr/
#2 lore raw
In reply to Oleg Drokin
Quoted 12 lines · On Saturday April 22, [email protected] wrote:

Hello!

NFSD does its own internal checks to possibly override restrictive file mode for file owner already, to allow writing into (opened) file with some restrictive mode (like 0000). But it does not pass this info down to actual filesystems, and if that filesystem is also doing permission checks in open, such an open would fail at FS-level.
(I thought of making an example with NFS exported with NFS, but this appears
to be not allowed, so I choose different example).
For example Lustre is contacting its metadata server for every open, and metadata server does permission checks for open, obviously.

Quoted 4 lines

I wonder if something like the patch below can be useful for any other distributed FS now in use and ultimately to end up accepted into vanilla tree?

Would it be acceptable for the lowlevel filesystem to simply always assume OWNER_OVERRIDE??

There are no security concerns in allowing read or write access to an owner. The IRUSR bit is almost entirely pointless, and the IWUSR bit is at most hint for user-level processes. Given that you know the syscall interface will be checking these, and given that they have no security implication, is there really any value in having the lowlevel filesystem check them as well?

Other than that, my only concern is that it seems to allow a user-space application to open a file with O_OWNER_OVERRIDE and you would want that sort of change to get wide visibility. I don't think it is a problem, but there might be those who would.

NeilBrown

#3 lore raw

Hello!

Quoted 10 lines · Neil Brown
Quoted 10 lines

NFSD does its own internal checks to possibly override restrictive file mode for file owner already, to allow writing into (opened) file with some restrictive mode (like 0000). But it does not pass this info down to actual filesystems, and if that filesystem is also doing permission checks in open, such an open would fail at FS-level.
(I thought of making an example with NFS exported with NFS, but this appears
to be not allowed, so I choose different example).
For example Lustre is contacting its metadata server for every open, and metadata server does permission checks for open, obviously.

Quoted 5 lines
Quoted 3 lines

I wonder if something like the patch below can be useful for any other distributed FS now in use and ultimately to end up accepted into vanilla tree?

Would it be acceptable for the lowlevel filesystem to simply always assume OWNER_OVERRIDE??

No. E.g. Lustre is usually bypassing local permission checks since server would do those anyway. In this case we need to explicitly tell server that client did the check and server should skip it.

Quoted 6 lines

There are no security concerns in allowing read or write access to an owner. The IRUSR bit is almost entirely pointless, and the IWUSR bit is at most hint for user-level processes. Given that you know the syscall interface will be checking these, and given that they have no security implication, is there really any value in having the lowlevel filesystem check them as well?

If non-root process would be able to read/write files they own with 0 permission bits set, then various posix/whatever conformance testing suites regard this as a bug.

Quoted 4 lines

Other than that, my only concern is that it seems to allow a user-space application to open a file with O_OWNER_OVERRIDE and you would want that sort of change to get wide visibility. I don't think it is a problem, but there might be those who would.

I also do not think this is all that big problem, as owner can do chmod as well.
I just do not want to add any extra arguments to ->open() methods or something equally ugly to hide this flag from userspace.

Bye,
Oleg