From: NeilBrown <neilb@ownmail.net>
To: linux-kernel@vger.kernel.org
Subject: [PATCH 8/8] vfs: add MAY_SERVE_FILE and FMODE_SERVE_FILE
Date: Wed, 2 Dec 2026 17:05:08 +1100 [thread overview]
Message-ID: <20261202060607.2627366-9-neilb@ownmail.net> (raw)
In-Reply-To: <20261202060607.2627366-1-neilb@ownmail.net>
From: NeilBrown <neil@brown.name>
Most access permissions have security implications, but some are for
convenience.
In particular:
r/w/x access for the owner have no security implication as the owner can
always change these flags.
The different between 'x' and 'r' permission has no security
implications. A user with 'r' could find a way to map the file and
execute the code, a user with 'x' could execute the file under a
debugger and extract the contents.
When serving files over the network, the client can provide the
convenience of imposing these permissions while the server cannot
in general impose them.
A server must allow a client to read the content of an execute-only file
so that it can be loaded into client memory and executed. A server must
allow a client to write to a file that was created without
write-permission - at least as long as it remains open after the O_CREAT
open which gave it that permission. In this case the creating user will
be the owner.
nfsd already manages these permission requirements in most cases.
However the need to use ->atomic_open interferes with the ability of
nfsd to allow extra permissions. To provide complete correctness we
need to instruct ->atomic_open to bypass the convenience permissions.
Also if core VFS code understands these needs we can achieve more code
sharing between nfsd and VFS.
So we introduce MAY_SERVE_FILE which instructs permission() functions,
and generic_permission() in particular, to allow read-access to
execute-only files and to allow all access to an owner.
We also add FMODE_SERVE_FILE which is passed to ->atomic_open so these
functions can handle when needed. No ->atomic_open functions are
changed to make use of it yet.
Setting these in vfs_lookup_open() will mean that nfsd gets the
permission checking that it requires when it is changed to use
vfs_lookup_open().
Signed-off-by: NeilBrown <neil@brown.name>
---
Documentation/filesystems/vfs.rst | 5 +++++
fs/namei.c | 15 +++++++++++++--
include/linux/fs.h | 6 ++++--
3 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst
index d1d32540e85f..9d6e9e8bfdae 100644
--- a/Documentation/filesystems/vfs.rst
+++ b/Documentation/filesystems/vfs.rst
@@ -644,6 +644,11 @@ otherwise noted.
FMODE_CREATED should be set if it is possible that this operation
created the object.
+ If atomic_open() calls finish_open() then it must have performed
+ all necessary access permission checks. If FMODE_SERVE_FILE
+ is set in file->f_mode, then it should assume MAY_SERVE_FILE if
+ possible.
+
This method is only called if the last component is negative or
needs lookup. Cached positive dentries are still handled by
f_op->open().
diff --git a/fs/namei.c b/fs/namei.c
index c685fbe7671c..fded05d15c08 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -441,6 +441,11 @@ static int acl_permission_check(const struct mnt_idmap *idmap,
unsigned int mode = inode->i_mode;
vfsuid_t vfsuid;
+ if (mask & MAY_SERVE_FILE) {
+ /* 'x' permission grants 'r' permission */
+ mode |= (mode & 0111) << 2;
+ }
+
/*
* Common cheap case: everybody has the requested
* rights, and there are no ACLs to check. No need
@@ -468,7 +473,12 @@ static int acl_permission_check(const struct mnt_idmap *idmap,
if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) {
mask &= 7;
mode >>= 6;
- return (mask & ~mode) ? -EACCES : 0;
+ if (likely((mask & ~mode) == 0))
+ return 0;
+ if (mask & MAY_SERVE_FILE)
+ /* Owner always gets access */
+ return 0;
+ return -EACCES;
}
/* Do we have ACL's? */
@@ -4777,6 +4787,7 @@ struct file *vfs_lookup_open(struct path *parent, struct qstr *last,
file = alloc_empty_file(open_flag, current_cred());
if (IS_ERR(file))
return file;
+ file->f_mode |= FMODE_SERVE_FILE;
nd.path = *parent;
nd.last = *last;
@@ -4788,7 +4799,7 @@ struct file *vfs_lookup_open(struct path *parent, struct qstr *last,
op.mode = mode;
}
op.open_flag = open_flag;
- op.acc_mode = ACC_MODE(open_flag);;
+ op.acc_mode = ACC_MODE(open_flag) | MAY_SERVE_FILE;
if (open_flag & O_TRUNC)
op.acc_mode |= MAY_WRITE;
dentry = lookup_open(&nd, file, &op);
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 79c376d4bc57..4337a77d051f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -99,6 +99,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
#define MAY_CHDIR 0x00000040
/* called from RCU mode, don't block */
#define MAY_NOT_BLOCK 0x00000080
+/* Passed by nfsd - owner may have any access, X access gives R */
+#define MAY_SERVE_FILE 0x00000100
/*
* flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond
@@ -121,8 +123,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
#define FMODE_WRITE_RESTRICTED ((__force fmode_t)(1 << 6))
/* File supports atomic writes */
#define FMODE_CAN_ATOMIC_WRITE ((__force fmode_t)(1 << 7))
-
-/* FMODE_* bit 8 */
+/* File used to serve file to a client, so MAY_SERVE_FILE applies */
+#define FMODE_SERVE_FILE ((__force fmode_t)(1 << 8))
/* 32bit hashes as llseek() offset (for directories) */
#define FMODE_32BITHASH ((__force fmode_t)(1 << 9))
--
2.50.0.107.gf914562f5916.dirty
prev parent reply other threads:[~2026-12-02 6:06 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 6:05 [PATCH 0/8] vfs: improvements for atomic_open and vfs_lookup_open NeilBrown
2026-12-02 6:05 ` [PATCH 1/8] vfs: revise and expand documentation for atomic_open NeilBrown
2026-12-02 6:05 ` [PATCH 2/8] vfs: only set op.mode when O_CREAT in vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 3/8] vfs: don't call ->atomic_open with hashed negative in non-O_CREAT case NeilBrown
2026-12-02 6:05 ` [PATCH 4/8] vfs: add some allowed open flags to vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 5/8] vfs: O_NONBLOCK|O_CREAT open shouldn't wait for directory delegation NeilBrown
2026-12-02 6:05 ` [PATCH 6/8] vfs: don't return -ENODEV from vfs_lookup_open() NeilBrown
2026-12-02 6:05 ` [PATCH 7/8] vfs: change vfs_lookup_open() to use do_open(), not vfs_open() NeilBrown
2026-12-02 6:05 ` NeilBrown [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261202060607.2627366-9-neilb@ownmail.net \
--to=neilb@ownmail.net \
--cc=linux-kernel@vger.kernel.org \
--cc=neil@brown.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®