From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=202.12.124.152 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796256576; b=fCQo7ZdhRgoJc987dSrrza3ejiB+BFS+k0mCfPmF0J3AG22yDoIJTmh/hGGAIWJp7DAT op+SFOeiudkml9orEqKGJMmpFhfxpce5xnGuvIz7Y0jWgueCLsDWnxtM5zN0PAwl116MV sC98lBYPBEazukRaoxPGFDYMq5OAE8QVlws4pRMEpkfCG2F9LWO/gGNdXLSF2r4yanYuc KxiiYUO/a7c/Vge4hn3CLetkDigmw6yFeYrUuYUZ3pIpOzKeNN54yrOkHhIjloVVeZNa2 4b2cfjOLNBGIFx6T2jojc2mvr3IexJPldmkugNsIZvbS1+zeKIkXVJXKvtwOcjG/rVg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796256576; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:Reply-To:MIME-Version:Content-Transfer-Encoding; bh=dFM8DqupoITilbblPXyvV+BS58Gx+sv/xviO3fKLrTI=; b=4nKNKpV9rgZLjXAcTc8aPz7NdHmPOHLPcQnIEdde7Gtxxu+ZK08341G+W2lW+O6KAfVu Mt10rlvegMPHmhRX/zL4He93xWlAozGf3B5FzDx6Was3psLAl8iEeKVVvmzGV0e2oO6f3 3F1ahQKTTQiaEXftyFZxFh9jBMHSkK0FI7iCi1hCvItzmgU2T1HFA1e+wR8rTfLiMhyz+ TYIyMwHp1CiWT18NW0Pev954P0JAlt7Z7nEsga0sraNIGK14fd47ENKYkOAb1FsS7CZ/4 UKIPyfOPyiIw6H4+/rSTROk+gVqpGi71ZbbW0VaQjcJ3QqefFZWRsAXUrjhv5Du0Ajw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=ownmail.net; spf=pass smtp.mailfrom=ownmail.net; dkim=pass header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=aPV44VZF; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b="A84/ijwS"; arc=none smtp.remote-ip=202.12.124.152 Received: from fhigh-b1-smtp.messagingengine.com (fhigh-b1-smtp.messagingengine.com [202.12.124.152]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B26ED606A332 for ; Thu, 3 Dec 2026 00:09:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B26ED606A332 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ownmail.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ownmail.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=ownmail.net header.i=@ownmail.net header.a=rsa-sha256 header.s=fm3 header.b=aPV44VZF; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=A84/ijwS Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 1C5867A01FC for ; Wed, 2 Dec 2026 19:09:35 -0500 (EST) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-03.internal (MEProxy); Wed, 02 Dec 2026 19:09:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ownmail.net; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:reply-to:subject:subject:to:to; s=fm3; t=1796256574; x=1796342974; bh=dFM8DqupoITilbblPXyvV+BS58Gx+sv/xviO3fKLrTI=; b= aPV44VZFDNxvelc/ChwyY1B6yfg4Tw3yZ0yPylN+RVH/7s1pNuIyxPL0uU61FeJU FqClqnQifbBuddQ6msYw/cEBhOMJOuoSAUZ5MKvHv0b5KMpHUIr2BJz0c7pVISJT 9Z0hUyVk95tjBGzcdyIzBhMHqt94iGIM7UWmfNsXiLxJ0pcrVopBQ5W+S4pO1xfa NikfkVxLUKQmnvsA5v4LJSUoCeMnqAr59dKbXEleoqpMFvtEuc8c+OlqxhVVBn1C CfqsZPfE3AhKyHLhkV8KQ2DnLSkxzPZAOUqReTS7+GvdNnN6uz06iUg20Undyh3U TzHIWs9vjhKgAa5Q25xRbA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:feedback-id:feedback-id:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796256574; x=1796342974; bh=d FM8DqupoITilbblPXyvV+BS58Gx+sv/xviO3fKLrTI=; b=A84/ijwS9uGNA8D+L /6D6x6Iui/jzwPbmyZm7E9MQyM/u9RIy/qXpIPfa4NMBrTtrcUad/PrWYGyav0A7 UwzNFk6k5qlHdYRB6DPkGAvi2LiR8p5Z+/a8binDYUU0NOmMztdqOx1UVh3/RasP VO5olb1vgRYOvJ7tZBmprFHmVmZIr9LfBLvVms4cXCO0jFE2g00KFDgFoO+jFypy JHjNTkFcSvPLNEtEljmy47ELmCBMTzpfUi03BhPehAzdKKrbqzgu+HS3ts1c70jj ytClf4cojKW35aMkvwAte4sBZUfV7ycTLzPezW4Vvy0Gmgl+ZfnWdeR53g3KKrjq G+4oA== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=ownmail.net a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796256574; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:zfaMZP71xsxG3twRtn1rRrUzI4lYn7URl4MaF2+JNLwLZfT FRNia9eIVGG5cXZgP5o2EIk7MS++LTqIOKTmww/WmY8xwwuAl95B58Yus9Q8NvYV 85jUOTzi1ALZLljQqifzChgGl2uCbc1T8qpmKIuS1+xmYV42ROQer1bOo4ZBTF6x IPuS2Ax5MEaCfZ710zICFy3pGP37F0FGOwPyE48XO8mAwgjykzvz0AV5ljSUR/lr r8NFgZFKGS7pfCHtlgux1r6HRsHGSdJw+AyHFfDVQSILZ2N5LACb9HvFiEzTKis3 oU6wrzJSMxkptxJRrd3uwF3I0UrufBd/Z03zx+Q==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=content-transfer-encoding,date,feedback-id,from,in-reply-to, message-id,mime-version,references,reply-to,subject,to; Message-Instance: m=1; h=sha256:umyDcZ9hOHjPC9sSrVPYd5Qzb81mnBI2PbVlBpm7LEE=:dqTVbQDH20Fu/WaMYgFU1HmSqJLpxGTGk2Rry73x/oA=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTEk7W2urxng3XGtsqgBSAihcmhsvNGvgXw20nbGEMVLbua2VpqSQVrQQ/bg3x9oHI 2U248MaPJhG1HzmtvnLR7bUOngaQ85sTLwQMHyZTX2+3WJ49HqLEx3VpN0ufoRwVheXDP9 1D+etNYMr6+5PlweDNJSWG483gtmONAADgd5K0nT21v2vfFhL8m4RTj+eg7dQ3ozUH7HQg MgdWvFgOGeSEuZmAnXMq9gn/Vv+Xdk6tiYB/+BCyjeg3w53kPBpMn3UVSHc5luDO87vMyU TngMqapyON7sXN+NdQktZie+TxW/kvzHrC5wvPlLBxT34IdTsnDVjZEExUIc0lXeC+WCp1 AkuUXZYI59QEYoUfTWXlYY8m3Kd8ira1vCkXcfu5D6sjk6XdQHZQNjd+P0JlA1mjPJSnm2 4ZTMXPlyV/h+aYtdUI/S3DvdS9R2ZzZWCs8yKhjfHcXl4KoJOjLwbzCYccvbu0Qa0LMtVU t37prQU5JycBFqlRpzEU7Qy/Pauw0H5cFLPKWByrGxI9nMV/IFetrd82wlqzXzXabUY+yN gu/7y1ULZ/HZ/Nua+IggcFAjggdR58y6DY+rZvYuwP4PWCttr0eemYF840zn240zgC+H4Y 5tqSkbcNZGH8+eLIabUEWUfd/7rNxjvDAwtpStN0YJG187Qj+qw6grhOSnZQ X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 2 Dec 2026 19:09:33 -0500 (EST) From: NeilBrown To: linux-kernel@vger.kernel.org Subject: [PATCH 9/9] vfs: add MAY_SERVE_FILE and FMODE_SERVE_FILE Date: Thu, 3 Dec 2026 11:08:04 +1100 Message-ID: <20261203000848.2986775-10-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261203000848.2986775-1-neilb@ownmail.net> References: <20261203000848.2986775-1-neilb@ownmail.net> Reply-To: NeilBrown X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: NeilBrown 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 --- Documentation/filesystems/vfs.rst | 6 ++++++ fs/namei.c | 27 ++++++++++++++++++++++++--- include/linux/fs.h | 6 ++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/Documentation/filesystems/vfs.rst b/Documentation/filesystems/vfs.rst index d1d32540e85f..700d176936ae 100644 --- a/Documentation/filesystems/vfs.rst +++ b/Documentation/filesystems/vfs.rst @@ -644,6 +644,12 @@ otherwise noted. FMODE_CREATED should be set if it is possible that this operation created the object. + If atomic_open() performs permission checks, it should + check if FMODE_SERVE_FILE is set in file->f_mode. If it + is then it should assume MAY_SERVE_FILE and not deny access + to an owner, or deny read access to a file for which eXecute + access is available. + 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 77a03e44029a..fa74d11e315f 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 @@ -466,6 +471,9 @@ static int acl_permission_check(const struct mnt_idmap *idmap, /* Are we the owner? If so, ACL's don't matter */ vfsuid = i_uid_into_vfsuid(idmap, inode); if (likely(vfsuid_eq_kuid(vfsuid, current_fsuid()))) { + if (mask & MAY_SERVE_FILE) + /* Owner always gets access */ + return 0; mask &= 7; mode >>= 6; return (mask & ~mode) ? -EACCES : 0; @@ -474,8 +482,20 @@ static int acl_permission_check(const struct mnt_idmap *idmap, /* Do we have ACL's? */ if (IS_POSIXACL(inode) && (mode & S_IRWXG)) { int error = check_acl(idmap, inode, mask); - if (error != -EAGAIN) - return error; + if (error != -EAGAIN) { + if (likely(error != -EACCES || + !(mask & MAY_SERVE_FILE))) + return error; + if (mask & MAY_READ) + /* + * eXec permission allows us to Read for + * file serving. + */ + error = check_acl(idmap, inode, + (mask & ~MAY_READ) | MAY_EXEC); + if (error != -EAGAIN) + return error; + } } /* Only RWX matters for group/other mode bits */ @@ -4777,6 +4797,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; @@ -4791,7 +4812,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