From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.157 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796191600; b=PjOgOmR0Ih0l2sjkOYd5Q47ozdHcN0FEzDLMr3+rXRd7+uUEU3IfaBz8Td/EbYdzu5tA OMf40xAMerCASZNWXc2IAwmLm8SEybYOihPqEz/jPfO8u8VKP+xSQgF+nmvpLvDbc6s/d ktiqzjqw6S1sF5sns7R/CG+YRSIeXIOKw7dJKuOPHWhaKgESzh7+V2EJ5HT9GMrxqLT6r 9ocnmsTOJqWXYhQvPZm79DTipH19aPVL6nKOhzJJisnEg99n1iU90P2lb9hv2RA9YKzk5 jPvG2ggm0oCpURyoHybTCNpTYMSm0DysPXWEQDHY3O1WbKkMAtcKMsPQoO5Ms8YcBKg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796191600; 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=ZlL3WmCoup3UuwrT18JuLEqNtFDUP8klQ4o5joQ0v4c=; b=4XzbI8vBG5WE6n5gQG3RY3vLJpSO8JHEOf1GuKUXR+U14gDL0CU//ueLBTJhXmdJmpvP oVODKEDLFJfCtrf7iawx5zm9lAT3JEzS0lGljwh4O1T6zHfrpSV2AZgYwasxiNM1W6YP2 0zsw6HPOt+t6wrRvMSXAgHdGpUcHBi6DiBftxr4uUF8TnryAZttSYxxougbyeP6ax9oC0 GPrAEfQHwn920xtZOUqaLVY6YZWuZ5dJFsfnCUmN/x4rVPGhvLbS90CItWRN+0GwatFeO OytfZVzNReBlwC4TcHkkDdO+x9wl8A+OrKsowy/vvjM0LMQefWyWNiOd8tx0+b8MzRA== 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="LS94sf/+"; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ATAi1Z3i; arc=none smtp.remote-ip=103.168.172.157 Received: from fhigh-a6-smtp.messagingengine.com (fhigh-a6-smtp.messagingengine.com [103.168.172.157]) (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 39CCB606A32F for ; Wed, 2 Dec 2026 06:06:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 39CCB606A32F 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=LS94sf/+; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=ATAi1Z3i Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.phl.internal (Postfix) with ESMTP id 6251C140019D for ; Wed, 2 Dec 2026 01:06:39 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 02 Dec 2026 01:06:39 -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=1796191599; x=1796277999; bh=ZlL3WmCoup3UuwrT18JuLEqNtFDUP8klQ4o5joQ0v4c=; b= LS94sf/+72JBLTWb/q0RuQrQAijK2Nbl3g7JEbEhdxFN2nMtGh9BgW4hi1s9hRSg GFtnErRlId+XdhJpEk9lZJIpOV5xwrC7o8G1TfzXNekUZE/exfDa1ZbihazdnDFH zkSabN5OBPcO3oGDm5wu0JjYxP9WnjxIBU7rLJA83MqStEw5Sm6WII22AXfXm6hp yAPHmzQjWkOrTEx5GCsjRMMEVvjtpxDHlob8TOprv8b5XLQ9CFcU0xJtm0s84okp bvX+Y4nqR6kZoglihWoRmYIuoUkU6piF+zlvge/K7qTznYzmxtYAtZYxKeDp/ydN Q5oW5fPw3/JDEieOoVRsFw== 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=1796191599; x=1796277999; bh=Z lL3WmCoup3UuwrT18JuLEqNtFDUP8klQ4o5joQ0v4c=; b=ATAi1Z3iy73sik3to NGnZfDC3OjOjZgcKinqB1zFco5OVL8rUgqdgdKnunlupxeaYWduzG4rdkOu94L0p o1gG2liB08AOmwQhAx5HPCui6/FHOtQ1gGpYHjzZuTvNMBmzPd7j55xeX7yZWk2W nnix5AGtj8OUsb/Ema8eMHKtRu2TNPdbOB0DWMw0x9NIeWF9BiaLfMflBHsp14C8 1u45IyEY/emx/7gQLvkA590tjTXZh93w6h/0f7tyNALE59Mp7WqfiJx50RClufhj dnCxHf0RDOiKuKPpRB6kbSSPHIUpGnjY/56APS//VDiMrimOHOSyW++8DPHkWU3F NcjeQ== 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=1796191599; d=ownmail.net; mf=PG5laWxiQG93bm1haWwubmV0Pg==; rt=PGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:lhNf8520Yn1eKzZnEF9pHIOt/X5mk/oOt1pSLUanjaFEGK3 o/gNgT665KuvoMFugE6e1Y0VahTxDzln3iWM0k8gSaeSlcGbTneA+eCSqwXXsBw9 gvbSCjYQHktoigB4NVnU1Zp6etdNnpzr6eFMcvMAh8/94rJEbQZVMkwuzE/95Qso kyPhcIX686OQxrtO1kO1jLHqls7fOWMb5M+Pfvwx6P7sg9iqZnI4H9/ZUzaVCRJH 5tId2ouRlWqnuEoVXZaYKOghOpQZnIyxAvtXblO/8N7m0GUCpveB3DbPAUTo7xke zOb56BOUIQkNT1Zy45U4s2o4thhOKE6ALVWafnw==; 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:Ilj2O4aPAyJ9MIXbXWyNhK3s6Mp7LomcaTOUS5SMiig=:xv2mBdf0CPfQjRv+bYvJbcYcuoWu4SNAUMkQZiUOeTM=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTE3yiVLxYK42+gUVc7HGVov1LwIym7ckVXhOzQmSDGzgvnVOY8BBe/GemA26GgpmS exCy7yEPlRNGJhyykSBLSL4nLgyA7ZUXcxjiawv+EwdXS9WrxoQyzjmwXk39CQQ9TGCi+f HUvTkNde2EYwnVRonIEJG95sbHBI8uQb/mt++1p6tEOjnekZ63TYZpyS1znTRnopppZMH1 T78arByB2n3UXYhbyAMPvgzHgu7WQDdEbptSXA2NwnLi+lcUKiGcqppy9dB/XhgGs1RZ3R n2zD5RZR0mVY1nArAnFdutZj7LzOvzqg31GfEdWwLk+YLNzwQLH++82YT8Sj5cCysy1tbs XVPEBQNjlwBrVx/OJoLKM1ypyRsATr1PkriwL8RHYBlGRYmuScYAGmMtFM1gzwqUa5OvX4 uq09bW7UMdCgmLLBqGD43JxCY+aS3AVQoaOOPdzzA3Fznz/J5yAnR+0JMGCX89iGorRrrp i1xhKXsg8ffJaNtuOJYFQi8jMvNtBBYey/uHXp0ZKvDRpJxYvi7wo9JORY6KjO+lJ93EJo qu4r1051vmKma3JTeaL0ixq+cma8DKZc5ANgQWNMrS+0PFYCNPMoe2q1UGFv+aimpJeHCq PlvJMKDrvVGWzOoTEJZixl6qDVS3Ozm9VaqS/BqYlmuyEWm6dzZRtVmFpzBQ X-ME-Proxy: Feedback-ID: i9d664b8f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 2 Dec 2026 01:06:38 -0500 (EST) From: NeilBrown 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 Message-ID: <20261202060607.2627366-9-neilb@ownmail.net> X-Mailer: git-send-email 2.50.0.107.gf914562f5916.dirty In-Reply-To: <20261202060607.2627366-1-neilb@ownmail.net> References: <20261202060607.2627366-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 | 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