Add NFSv4.2 POSIX ACL support
Subsystems (3)
Chuck Lever
maintainerv2 cover Add NFSv4.2 POSIX ACL support
From: Chuck Lever <[email protected]>
The Internet draft "POSIX Draft ACL support for Network File System Version 4, Minor Version 2":
https://datatracker.ietf.org/doc/draft-ietf-nfsv4-posix-acls/
defines an extension to NFSv4.2 that enables POSIX draft ACLs to be retrieved and set directly, without the lossy NFSv4->POSIX draft mapping algorithm. The extension adds four new attributes to the protocol.
This patch series implements the server side of this extension for knfsd. The mechanism is analogous to the NFS_ACL sideband protocol used with NFSv2/3, enabling POSIX draft ACLs to be manipulated directly by getfacl(1) and setfacl(1).
The current implementation does not support "per file" scope, where individual file objects store either an NFSv4 ACL or a POSIX draft ACL. Instead, the implementation assumes POSIX draft ACLs apply to an entire file system when support for POSIX draft ACLs is indicated.
Based on the nfsd-testing branch from:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
Changes since v1:
- Fold the patches with fixes into the first 8 patches
- Ensure the series is bisect-able
- Add CONFIG_NFSD_V4_POSIX_ACLS -- this feature is experimental
- Set "SUPPATTR" bits only at the end of series
- Use xdrgen, where practical, instead of hand-coded XDR
- Refactor SETATTR/CREATE to integrate better with existing APIs
Chuck Lever (3):
NFSD: Add a Kconfig setting to enable support for NFSv4 POSIX ACLs Add RPC language definition of NFSv4 POSIX ACL extension
NFSD: Add POSIX ACL file attributes to SUPPATTR bitmasks
Rick Macklem (9):
NFSD: Add nfsd4_encode_fattr4_acl_trueform
NFSD: Add nfsd4_encode_fattr4_acl_trueform_scope
NFSD: Add nfsd4_encode_fattr4_posix_default_acl
NFSD: Add nfsd4_encode_fattr4_posix_access_acl
NFSD: Do not allow NFSv4 (N)VERIFY to check POSIX ACL attributes
NFSD: Refactor nfsd_setattr()'s ACL error reporting
NFSD: Add support for XDR decoding POSIX draft ACLs
NFSD: Add support for POSIX draft ACLs for file creation
NFSD: Add POSIX draft ACL support to the NFSv4 SETATTR operation
Documentation/sunrpc/xdr/nfs4_1.x | 56 +++++ fs/nfsd/Kconfig | 19 ++ fs/nfsd/acl.h | 1 + fs/nfsd/nfs4acl.c | 17 +- fs/nfsd/nfs4proc.c | 96 ++++++-- fs/nfsd/nfs4xdr.c | 356 ++++++++++++++++++++++++++- fs/nfsd/nfs4xdr_gen.c | 167 ++++++++++++- fs/nfsd/nfs4xdr_gen.h | 12 +- fs/nfsd/nfsd.h | 17 +- fs/nfsd/vfs.c | 34 ++- fs/nfsd/vfs.h | 3 +- fs/nfsd/xdr4.h | 6 + include/linux/nfs4.h | 4 + include/linux/sunrpc/xdrgen/nfs4_1.h | 73 +++++- 14 files changed, 822 insertions(+), 39 deletions(-)
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 1/12 NFSD: Add a Kconfig setting to enable support for NFSv4 POSIX ACLs
From: Chuck Lever <[email protected]>
A new IETF draft extends NFSv4.2 with POSIX ACL attributes:
https://www.ietf.org/archive/id/draft-ietf-nfsv4-posix-acls-00.txt
This draft has not yet been ratified. A build-time configuration option allows developers and distributors to decide whether to expose this experimental protocol extension to NFSv4 clients. The option is disabled by default to prevent unintended deployment of potentially unstable protocol features in production environments.
This approach mirrors the existing NFSD_V4_DELEG_TIMESTAMPS option, which gates another experimental NFSv4 extension based on an unratified IETF draft.
--- fs/nfsd/Kconfig | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
fs/nfsd/Kconfig +19 -0
@@ -186,3 +186,22 @@ config NFSD_V4_DELEG_TIMESTAMPS draft-ietf-nfsv4-delstid-08 "Extending the Opening of Files". This is currently an experimental feature and is therefore left disabled by default. + +config NFSD_V4_POSIX_ACLS + bool "Support NFSv4 POSIX draft ACLs" + depends on NFSD_V4 + default n + help + Include experimental support for POSIX Access Control Lists + (ACLs) in NFSv4 as specified in the IETF draft + draft-ietf-nfsv4-posix-acls. This protocol extension enables + NFSv4 clients to retrieve and modify POSIX ACLs on exported + filesystems that support them. + + This feature is based on an unratified IETF draft + specification that may change in ways that impact + interoperability with existing clients. Enable only for + testing environments or when interoperability with specific + clients that implement this draft is required. + + If unsure, say N.
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 2/12 Add RPC language definition of NFSv4 POSIX ACL extension
In reply to Chuck LeverFrom: Chuck Lever <[email protected]>
The language definition was extracted from the new draft-ietf-nfsv4-posix-acls specification. This ensures good constant and type name alignment between the spec and the Linux kernel source code, and brings in some basic XDR utilities for handling NFSv4 POSIX draft ACLs.
--- Documentation/sunrpc/xdr/nfs4_1.x | 56 +++++++++ fs/nfsd/nfs4xdr_gen.c | 167 ++++++++++++++++++++++++++- fs/nfsd/nfs4xdr_gen.h | 12 +- include/linux/nfs4.h | 4 + include/linux/sunrpc/xdrgen/nfs4_1.h | 73 +++++++++++- 5 files changed, 309 insertions(+), 3 deletions(-)
Documentation/sunrpc/xdr/nfs4_1.x +56 -0
@@ -53,6 +53,11 @@ typedef unsigned int uint32_t; */ typedef uint32_t bitmap4<>; +typedef opaque utf8string<>; +typedef utf8string utf8str_cis; +typedef utf8string utf8str_cs; +typedef utf8string utf8str_mixed; + /* * Timeval */
@@ -184,3 +189,54 @@ enum open_delegation_type4 { OPEN_DELEGATE_READ_ATTRS_DELEG = 4, OPEN_DELEGATE_WRITE_ATTRS_DELEG = 5 }; + + +/* + * The following content was extracted from draft-ietf-nfsv4-posix-acls + */ + +enum aclmodel4 { + ACL_MODEL_NFS4 = 1, + ACL_MODEL_POSIX_DRAFT = 2, + ACL_MODEL_NONE = 3 +}; +pragma public aclmodel4; + +enum aclscope4 { + ACL_SCOPE_FILE_OBJECT = 1, + ACL_SCOPE_FILE_SYSTEM = 2, + ACL_SCOPE_SERVER = 3 +}; +pragma public aclscope4; + +enum posixacetag4 { + POSIXACE4_TAG_USER_OBJ = 1, + POSIXACE4_TAG_USER = 2, + POSIXACE4_TAG_GROUP_OBJ = 3, + POSIXACE4_TAG_GROUP = 4, + POSIXACE4_TAG_MASK = 5, + POSIXACE4_TAG_OTHER = 6 +}; +pragma public posixacetag4; + +typedef uint32_t posixaceperm4; +pragma public posixaceperm4; + +/* Bit definitions for posixaceperm4. */ +const POSIXACE4_PERM_EXECUTE = 0x00000001; +const POSIXACE4_PERM_WRITE = 0x00000002; +const POSIXACE4_PERM_READ = 0x00000004; + +struct posixace4 { + posixacetag4 tag; + posixaceperm4 perm; + utf8str_mixed who; +}; + +/* + * New for POSIX ACL extension + */ +const FATTR4_ACL_TRUEFORM = 89; +const FATTR4_ACL_TRUEFORM_SCOPE = 90; +const FATTR4_POSIX_DEFAULT_ACL = 91; +const FATTR4_POSIX_ACCESS_ACL = 92;
fs/nfsd/nfs4xdr_gen.c +166 -1
194 lines not on this page · raw message
fs/nfsd/nfs4xdr_gen.h +11 -1
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0 */ /* Generated by xdrgen. Manual edits will be lost. */ /* XDR specification file: ../../Documentation/sunrpc/xdr/nfs4_1.x */ -/* XDR specification modification time: Thu Dec 25 13:44:43 2025 */ +/* XDR specification modification time: Wed Dec 31 22:21:13 2025 */ #ifndef _LINUX_XDRGEN_NFS4_1_DECL_H#define _LINUX_XDRGEN_NFS4_1_DECL_H
@@ -21,5 +21,15 @@ bool xdrgen_encode_fattr4_time_deleg_access(struct xdr_stream *xdr, const fattr4bool xdrgen_decode_fattr4_time_deleg_modify (struct xdr_stream *xdr,fattr4_time_deleg_modify *ptr);bool xdrgen_encode_fattr4_time_deleg_modify (struct xdr_stream *xdr,const fattr4_time_deleg_modify *value); +bool xdrgen_decode_aclmodel4 (struct xdr_stream *xdr,aclmodel4 *ptr); +bool xdrgen_encode_aclmodel4 (struct xdr_stream *xdr,aclmodel4 value); +bool xdrgen_decode_aclscope4 (struct xdr_stream *xdr,aclscope4 *ptr); +bool xdrgen_encode_aclscope4 (struct xdr_stream *xdr,aclscope4 value); +bool xdrgen_decode_posixacetag4 (struct xdr_stream *xdr,posixacetag4 *ptr); +bool xdrgen_encode_posixacetag4 (struct xdr_stream *xdr,posixacetag4 value); + +bool xdrgen_decode_posixaceperm4 (struct xdr_stream *xdr,posixaceperm4 *ptr); +bool xdrgen_encode_posixaceperm4 (struct xdr_stream *xdr,const posixaceperm4 value); +#endif /* _LINUX_XDRGEN_NFS4_1_DECL_H */
include/linux/nfs4.h +4 -0
@@ -598,6 +598,10 @@ enum {#define FATTR4_WORD2_TIME_DELEG_ACCESS BIT(FATTR4_TIME_DELEG_ACCESS - 64)#define FATTR4_WORD2_TIME_DELEG_MODIFY BIT(FATTR4_TIME_DELEG_MODIFY - 64)#define FATTR4_WORD2_OPEN_ARGUMENTS BIT(FATTR4_OPEN_ARGUMENTS - 64) +#define FATTR4_WORD2_ACL_TRUEFORM BIT(FATTR4_ACL_TRUEFORM - 64) +#define FATTR4_WORD2_ACL_TRUEFORM_SCOPE BIT(FATTR4_ACL_TRUEFORM_SCOPE - 64) +#define FATTR4_WORD2_POSIX_DEFAULT_ACL BIT(FATTR4_POSIX_DEFAULT_ACL - 64) +#define FATTR4_WORD2_POSIX_ACCESS_ACL BIT(FATTR4_POSIX_ACCESS_ACL - 64)/* MDS threshold bitmap bits */ #define THRESHOLD_RD (1UL << 0)
include/linux/sunrpc/xdrgen/nfs4_1.h +72 -1
101 lines not on this page · raw message
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 3/12 NFSD: Add nfsd4_encode_fattr4_acl_trueform
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
Mapping between NFSv4 ACLs and POSIX ACLs is semantically imprecise:
a client that sets an NFSv4 ACL and reads it back may see a different ACL than it wrote. The proposed NFSv4 POSIX ACL extension introduces the FATTR4_ACL_TRUEFORM attribute, which reports whether a file object stores its access control permissions using NFSv4 ACLs or POSIX ACLs.
A client aware of this extension can avoid lossy translation by requesting and setting ACLs in their native format.
When NFSD is built with CONFIG_NFSD_V4_POSIX_ACLS, report ACL_MODEL_POSIX_DRAFT for file objects on file systems with the SB_POSIXACL flag set, and ACL_MODEL_NONE otherwise. Linux file systems do not store NFSv4 ACLs natively, so ACL_MODEL_NFS4 is never reported.
--- fs/nfsd/nfs4xdr.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
fs/nfsd/nfs4xdr.c +26 -0
@@ -3470,6 +3470,22 @@ static __be32 nfsd4_encode_fattr4_open_arguments(struct xdr_stream *xdr,return nfs_ok; } +#ifdef CONFIG_NFSD_V4_POSIX_ACLS + +static __be32 nfsd4_encode_fattr4_acl_trueform (struct xdr_stream *xdr, +const struct nfsd4_fattr_args *args) +{ +aclmodel4 trueform =ACL_MODEL_NONE ; + +if (IS_POSIXACL (d_inode (args->dentry))) + trueform =ACL_MODEL_POSIX_DRAFT ; +if (!xdrgen_encode_aclmodel4 (xdr, trueform)) +return nfserr_resource; +return nfs_ok; +} + +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ +static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { [FATTR4_SUPPORTED_ATTRS ] = nfsd4_encode_fattr4_supported_attrs, [FATTR4_TYPE ] = nfsd4_encode_fattr4_type,
@@ -3573,6 +3589,16 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { [FATTR4_TIME_DELEG_ACCESS] = nfsd4_encode_fattr4__inval, [FATTR4_TIME_DELEG_MODIFY] = nfsd4_encode_fattr4__inval, [FATTR4_OPEN_ARGUMENTS ] = nfsd4_encode_fattr4_open_arguments, + + /* Reserved */ + [87] = nfsd4_encode_fattr4__inval, + [88 ] = nfsd4_encode_fattr4__inval, + +#ifdef CONFIG_NFSD_V4_POSIX_ACLS + [FATTR4_ACL_TRUEFORM ] = nfsd4_encode_fattr4_acl_trueform, +#else + [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop, +#endif };/*
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 4/12 NFSD: Add nfsd4_encode_fattr4_acl_trueform_scope
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
The FATTR4_ACL_TRUEFORM_SCOPE attribute indicates the granularity at which the ACL model can vary: per file object, per file system, or uniformly across the entire server.
In Linux, the ACL model is determined by the SB_POSIXACL superblock flag, which applies uniformly to all files within a file system. Different exported file systems can have different ACL models, but individual files cannot differ from their containing file system. ACL_SCOPE_FILE_SYSTEM accurately reflects this behavior.
--- fs/nfsd/nfs4xdr.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
fs/nfsd/nfs4xdr.c +10 -0
@@ -3484,6 +3484,14 @@ static __be32 nfsd4_encode_fattr4_acl_trueform(struct xdr_stream *xdr,return nfs_ok; } +static __be32 nfsd4_encode_fattr4_acl_trueform_scope (struct xdr_stream *xdr, +const struct nfsd4_fattr_args *args) +{ +if (!xdrgen_encode_aclscope4 (xdr,ACL_SCOPE_FILE_SYSTEM )) +return nfserr_resource; +return nfs_ok; +} +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
@@ -3596,8 +3604,10 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { #ifdef CONFIG_NFSD_V4_POSIX_ACLS [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4_acl_trueform, + [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4_acl_trueform_scope, #else [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop, + [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4__noop,#endif };
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 5/12 NFSD: Add nfsd4_encode_fattr4_posix_default_acl
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
The POSIX ACL extension to NFSv4 defines FATTR4_POSIX_DEFAULT_ACL for retrieving a directory's default ACL. This patch adds the XDR encoder for that attribute.
For directories, the default ACL is retrieved via get_inode_acl() and each entry is encoded as a posixace4: tag type, permission bits, and principal name (empty for structural entries like USER_OBJ/GROUP_OBJ/MASK/OTHER, resolved via idmapping for USER/GROUP entries).
--- fs/nfsd/nfs4xdr.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+)
fs/nfsd/nfs4xdr.c +128 -0
@@ -43,6 +43,7 @@#include <linux/sunrpc/addr.h> #include <linux/xattr.h> #include <linux/vmalloc.h> +#include <linux/nfsacl.h> #include <uapi/linux/xattr.h>
@@ -2849,6 +2850,89 @@ nfsd4_encode_security_label(struct xdr_stream *xdr, struct svc_rqst *rqstp, {return 0 ; }#endif +#ifdef CONFIG_NFSD_V4_POSIX_ACLS + +static int nfsd4_posix_tagtotype (short tag) +{ +switch (tag) { +case ACL_USER_OBJ :return POSIXACE4_TAG_USER_OBJ ; +case ACL_GROUP_OBJ :return POSIXACE4_TAG_GROUP_OBJ ; +case ACL_USER :return POSIXACE4_TAG_USER ; +case ACL_GROUP :return POSIXACE4_TAG_GROUP ; +case ACL_MASK :return POSIXACE4_TAG_MASK ; +case ACL_OTHER :return POSIXACE4_TAG_OTHER ; +default :return -EINVAL ; + } +} + +static __be32 +nfsd4_encode_posixace4 (struct xdr_stream *xdr,struct svc_rqst *rqstp, +struct posix_acl_entry *acep) +{ +__be32 status; +int type; + + type =nfsd4_posix_tagtotype (acep->e_tag); +if (type <0 ) +return nfserr_resource; +if (!xdrgen_encode_posixacetag4 (xdr, type)) +return nfserr_resource; +if (!xdrgen_encode_posixaceperm4 (xdr, acep->e_perm)) +return nfserr_resource; + +/* who */ +switch (acep->e_tag) { +case ACL_USER_OBJ : +case ACL_GROUP_OBJ : +case ACL_MASK : +case ACL_OTHER : +if (xdr_stream_encode_u32 (xdr,0 ) !=XDR_UNIT ) +return nfserr_resource; +break ; +case ACL_USER : + status =nfsd4_encode_user (xdr, rqstp, acep->e_uid); +if (status != nfs_ok) +return status; +break ; +case ACL_GROUP : + status =nfsd4_encode_group (xdr, rqstp, acep->e_gid); +if (status != nfs_ok) +return status; +break ; +default : +return nfserr_resource; + } +return nfs_ok; +} + +static __be32 +nfsd4_encode_posixacl (struct xdr_stream *xdr,struct svc_rqst *rqstp, +struct posix_acl *acl) +{ +__be32 status; +int i; + +if (!acl) { +if (xdr_stream_encode_u32 (xdr,0 ) !=XDR_UNIT ) +return nfserr_resource; +return nfs_ok; + } + +if (acl->a_count >NFS_ACL_MAX_ENTRIES ) +return nfserr_resource; +if (xdr_stream_encode_u32 (xdr, acl->a_count) !=XDR_UNIT ) +return nfserr_resource; +for (i =0 ; i < acl->a_count; i++) { + status =nfsd4_encode_posixace4 (xdr, rqstp, &acl->a_entries[i]); +if (status != nfs_ok) +return status; + } + +return nfs_ok; +} + +#endif /* CONFIG_NFSD_V4_POSIX_ACL */ +static __be32 fattr_handle_absent_fs (u32 *bmval0,u32 *bmval1,u32 *bmval2,u32 *rdattr_err) {/* As per referral draft: */
@@ -2929,6 +3013,9 @@ struct nfsd4_fattr_args {u64 change_attr;#ifdef CONFIG_NFSD_V4_SECURITY_LABEL struct lsm_context context; +#endif +#ifdef CONFIG_NFSD_V4_POSIX_ACLS +struct posix_acl *dpacl;#endif u32 rdattr_err;bool contextsupport;
@@ -3492,6 +3579,12 @@ static __be32 nfsd4_encode_fattr4_acl_trueform_scope(struct xdr_stream *xdr,return nfs_ok; } +static __be32 nfsd4_encode_fattr4_posix_default_acl (struct xdr_stream *xdr, +const struct nfsd4_fattr_args *args) +{ +return nfsd4_encode_posixacl (xdr, args->rqstp, args->dpacl); +} +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
@@ -3605,9 +3698,11 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { #ifdef CONFIG_NFSD_V4_POSIX_ACLS [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4_acl_trueform, [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4_acl_trueform_scope, + [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4_posix_default_acl, #else [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop, [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4__noop, + [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4__noop, #endif };
@@ -3649,6 +3744,9 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,#ifdef CONFIG_NFSD_V4_SECURITY_LABEL args.context.context =NULL ;#endif +#ifdef CONFIG_NFSD_V4_POSIX_ACLS + args.dpacl =NULL ; +#endif /* * Make a local copy of the attribute bitmap that can be modified.
@@ -3755,6 +3853,32 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, }#endif /* CONFIG_NFSD_V4_SECURITY_LABEL */ +#ifdef CONFIG_NFSD_V4_POSIX_ACLS +if (attrmask[2 ] &FATTR4_WORD2_POSIX_DEFAULT_ACL ) { +struct inode *inode =d_inode (dentry); +struct posix_acl *dpacl; + +if (S_ISDIR (inode->i_mode)) { + dpacl =get_inode_acl (inode,ACL_TYPE_DEFAULT ); +if (IS_ERR (dpacl)) { +switch (PTR_ERR (dpacl)) { +case -EOPNOTSUPP : + attrmask[2 ] &= ~FATTR4_WORD2_POSIX_DEFAULT_ACL ; +break ; +case -EINVAL : + status = nfserr_attrnotsupp; + goto out; +default : + err =PTR_ERR (dpacl); + goto out_nfserr; + } + }else { + args.dpacl = dpacl; + } + } + } +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ +/* attrmask */ status =nfsd4_encode_bitmap4 (xdr, attrmask[0 ], attrmask[1 ], attrmask[2 ]);
@@ -3778,6 +3902,10 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, status = nfs_ok; out: +#ifdef CONFIG_NFSD_V4_POSIX_ACLS +if (args.dpacl) +posix_acl_release (args.dpacl); +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ #ifdef CONFIG_NFSD_V4_SECURITY_LABEL if (args.context.context)security_release_secctx (&args.context);
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 6/12 NFSD: Add nfsd4_encode_fattr4_posix_access_acl
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
The POSIX ACL extension to NFSv4 defines FATTR4_POSIX_ACCESS_ACL for retrieving the access ACL of a file or directory. This patch adds the XDR encoder for that attribute.
The access ACL is retrieved via get_inode_acl(). If the filesystem provides no explicit access ACL, one is synthesized from the file mode via posix_acl_from_mode(). Each entry is encoded as a
posixace4: tag type, permission bits, and principal name (empty for structural entries, resolved via idmapping for USER/GROUP entries).
Unlike the default ACL encoder which applies only to directories, this encoder handles all inode types and ensures an access ACL is always available through mode-based synthesis when needed.
--- fs/nfsd/nfs4xdr.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
fs/nfsd/nfs4xdr.c +35 -0
@@ -3016,6 +3016,7 @@ struct nfsd4_fattr_args {#endif #ifdef CONFIG_NFSD_V4_POSIX_ACLS struct posix_acl *dpacl; +struct posix_acl *pacl;#endif u32 rdattr_err;bool contextsupport;
@@ -3585,6 +3586,12 @@ static __be32 nfsd4_encode_fattr4_posix_default_acl(struct xdr_stream *xdr,return nfsd4_encode_posixacl (xdr, args->rqstp, args->dpacl); } +static __be32 nfsd4_encode_fattr4_posix_access_acl (struct xdr_stream *xdr, +const struct nfsd4_fattr_args *args) +{ +return nfsd4_encode_posixacl (xdr, args->rqstp, args->pacl); +} +#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = {
@@ -3699,10 +3706,12 @@ static const nfsd4_enc_attr nfsd4_enc_fattr4_encode_ops[] = { [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4_acl_trueform, [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4_acl_trueform_scope, [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4_posix_default_acl, + [FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4_posix_access_acl, #else [FATTR4_ACL_TRUEFORM] = nfsd4_encode_fattr4__noop, [FATTR4_ACL_TRUEFORM_SCOPE] = nfsd4_encode_fattr4__noop, [FATTR4_POSIX_DEFAULT_ACL] = nfsd4_encode_fattr4__noop, + [FATTR4_POSIX_ACCESS_ACL] = nfsd4_encode_fattr4__noop, #endif };
@@ -3746,6 +3755,7 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,#endif #ifdef CONFIG_NFSD_V4_POSIX_ACLS args.dpacl =NULL ; + args.pacl =NULL ;#endif /*
@@ -3877,6 +3887,29 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr, } } } +if (attrmask[2 ] &FATTR4_WORD2_POSIX_ACCESS_ACL ) { +struct inode *inode =d_inode (dentry); +struct posix_acl *pacl; + + pacl =get_inode_acl (inode,ACL_TYPE_ACCESS ); +if (!pacl) + pacl =posix_acl_from_mode (inode->i_mode,GFP_KERNEL ); +if (IS_ERR (pacl)) { +switch (PTR_ERR (pacl)) { +case -EOPNOTSUPP : + attrmask[2 ] &= ~FATTR4_WORD2_POSIX_ACCESS_ACL ; +break ; +case -EINVAL : + status = nfserr_attrnotsupp; + goto out; +default : + err =PTR_ERR (pacl); + goto out_nfserr; + } + }else { + args.pacl = pacl; + } + }#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ /* attrmask */
@@ -3905,6 +3938,8 @@ nfsd4_encode_fattr4(struct svc_rqst *rqstp, struct xdr_stream *xdr,#ifdef CONFIG_NFSD_V4_POSIX_ACLS if (args.dpacl)posix_acl_release (args.dpacl); +if (args.pacl) +posix_acl_release (args.pacl);#endif /* CONFIG_NFSD_V4_POSIX_ACLS */ #ifdef CONFIG_NFSD_V4_SECURITY_LABEL if (args.context.context)
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 7/12 NFSD: Do not allow NFSv4 (N)VERIFY to check POSIX ACL attributes
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
Section 9.3 of draft-ietf-nfsv4-posix-acls-00 prohibits use of the POSIX ACL attributes with VERIFY and NVERIFY operations: the server MUST reply NFS4ERR_INVAL when a client attempts this.
Beyond the protocol requirement, comparison of POSIX draft ACLs via (N)VERIFY presents an implementation challenge. Clients are not required to order the ACEs within a POSIX ACL in any particular way, making reliable attribute comparison impractical.
Return nfserr_inval when the client requests FATTR4_POSIX_ACCESS_ACL or FATTR4_POSIX_DEFAULT_ACL in a VERIFY or NVERIFY operation.
--- fs/nfsd/nfs4proc.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/nfsd/nfs4proc.c +5 -0
@@ -2278,6 +2278,11 @@ _nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (verify->ve_attrlen &3 )return nfserr_inval; +/* The POSIX draft ACLs cannot be tested via (N)VERIFY. */ +if (verify->ve_bmval[2 ] & (FATTR4_WORD2_POSIX_DEFAULT_ACL | +FATTR4_WORD2_POSIX_ACCESS_ACL )) +return nfserr_inval; +/* count in words: * bitmap_len(1) + bitmap(2) + attr_len(1) = 4 */
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 8/12 NFSD: Refactor nfsd_setattr()'s ACL error reporting
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
Support for FATTR4_POSIX_ACCESS_ACL and FATTR4_POSIX_DEFAULT_ACL attributes in subsequent patches allows clients to set both ACL types simultaneously during SETATTR and file creation. Each ACL type can succeed or fail independently, requiring the server to clear individual attribute bits in the reply bitmap when one fails while the other succeeds.
The existing na_aclerr field cannot distinguish which ACL type encountered an error. Separate error fields (na_paclerr for access ACLs, na_dpaclerr for default ACLs) enable the server to report per-ACL-type failures accurately.
This refactoring also adds validation previously absent: default ACL processing rejects non-directory targets with EINVAL and passes NULL to set_posix_acl() when a_count is zero to delete the ACL. Access ACL processing rejects zero a_count with EINVAL for ACL_SCOPE_FILE_SYSTEM semantics (the only scope currently supported).
The changes preserve compatibility with existing NFSv4 ACL code. NFSv4 ACL conversion (nfs4_acl_nfsv4_to_posix()) never produces POSIX ACLs with a_count == 0, so the new validation logic only affects future POSIX ACL attribute handling.
--- fs/nfsd/nfs4proc.c | 8 +++++--- fs/nfsd/vfs.c | 34 +++++++++++++++++++++++++++------- fs/nfsd/vfs.h | 3 ++- 3 files changed, 34 insertions(+), 11 deletions(-)
fs/nfsd/nfs4proc.c +5 -3
@@ -377,7 +377,7 @@ nfsd4_create_file(struct svc_rqst *rqstp, struct svc_fh *fhp,if (attrs.na_labelerr) open->op_bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; -if (attrs.na_aclerr) +if (attrs.na_paclerr || attrs.na_dpaclerr) open->op_bmval[0 ] &= ~FATTR4_WORD0_ACL ; out:end_creating (child);
@@ -858,7 +858,7 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (attrs.na_labelerr) create->cr_bmval[2 ] &= ~FATTR4_WORD2_SECURITY_LABEL ; -if (attrs.na_aclerr) +if (attrs.na_paclerr || attrs.na_dpaclerr) create->cr_bmval[0 ] &= ~FATTR4_WORD0_ACL ;set_change_info (&create->cr_cinfo, &cstate->current_fh);fh_dup2 (&cstate->current_fh, &resfh);
@@ -1232,7 +1232,9 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,if (!status) status =nfserrno (attrs.na_labelerr);if (!status) - status =nfserrno (attrs.na_aclerr); + status =nfserrno (attrs.na_dpaclerr); +if (!status) + status =nfserrno (attrs.na_paclerr); out:nfsd_attrs_free (&attrs);fh_drop_write (&cstate->current_fh);
fs/nfsd/vfs.c +27 -7
@@ -596,15 +596,35 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp,if (attr->na_seclabel && attr->na_seclabel->len) attr->na_labelerr =security_inode_setsecctx (dentry, attr->na_seclabel->data, attr->na_seclabel->len); -if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && attr->na_pacl) - attr->na_aclerr =set_posix_acl (&nop_mnt_idmap, - dentry,ACL_TYPE_ACCESS , - attr->na_pacl); -if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && - !attr->na_aclerr && attr->na_dpacl &&S_ISDIR (inode->i_mode)) - attr->na_aclerr =set_posix_acl (&nop_mnt_idmap, +if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && attr->na_dpacl) { +if (!S_ISDIR (inode->i_mode)) + attr->na_dpaclerr = -EINVAL ; +else if (attr->na_dpacl->a_count >0 ) +/* a_count == 0 means delete the ACL. */ + attr->na_dpaclerr =set_posix_acl (&nop_mnt_idmap, dentry,ACL_TYPE_DEFAULT , attr->na_dpacl); +else + attr->na_dpaclerr =set_posix_acl (&nop_mnt_idmap, + dentry,ACL_TYPE_DEFAULT , +NULL ); + } +if (IS_ENABLED (CONFIG_FS_POSIX_ACL ) && attr->na_pacl) { +/* +* For any file system that is not ACL_SCOPE_FILE_OBJECT, +* a_count == 0 MUST reply nfserr_inval. +* For a file system that is ACL_SCOPE_FILE_OBJECT, +* a_count == 0 deletes the ACL. +* XXX File systems that are ACL_SCOPE_FILE_OBJECT +* are not yet supported. +*/ +if (attr->na_pacl->a_count >0 ) + attr->na_paclerr =set_posix_acl (&nop_mnt_idmap, + dentry,ACL_TYPE_ACCESS , + attr->na_pacl); +else + attr->na_paclerr = -EINVAL ; + } out_fill_attrs:/* * RFC 1813 Section 3.3.2 does not mandate that an NFS server
fs/nfsd/vfs.h +2 -1
@@ -53,7 +53,8 @@ struct nfsd_attrs {struct posix_acl *na_dpacl;/* input */ int na_labelerr;/* output */ -int na_aclerr;/* output */ +int na_dpaclerr;/* output */ +int na_paclerr;/* output */ };static inline void nfsd_attrs_free (struct nfsd_attrs *attrs)
Signature · 1 line
2.52.0
Chuck Lever
maintainerPATCH v2 9/12 NFSD: Add support for XDR decoding POSIX draft ACLs
In reply to Chuck LeverFrom: Rick Macklem <[email protected]>
The POSIX ACL extension to NFSv4 defines FATTR4_POSIX_ACCESS_ACL and FATTR4_POSIX_DEFAULT_ACL for setting access and default ACLs via CREATE, OPEN, and SETATTR operations. This patch adds the XDR decoders for those attributes.
The nfsd4_decode_fattr4() function gains two additional parameters for receiving decoded POSIX ACLs. CREATE, OPEN, and SETATTR decoders pass pointers to these new parameters, enabling clients to set POSIX ACLs during object creation or modification.
--- fs/nfsd/acl.h | 1 + fs/nfsd/nfs4acl.c | 17 +++-- fs/nfsd/nfs4xdr.c | 157 ++++++++++++++++++++++++++++++++++++++++++++-- fs/nfsd/xdr4.h | 6 ++ 4 files changed, 171 insertions(+), 10 deletions(-)
fs/nfsd/acl.h +1 -0
@@ -49,5 +49,6 @@ int nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry, struct nfs4_acl **acl);__be32 nfsd4_acl_to_attr (enum nfs_ftype4 type,struct nfs4_acl *acl,struct nfsd_attrs *attr); +void sort_pacl_range (struct posix_acl *pacl,int start,int end);#endif /* LINUX_NFS4_ACL_H */
fs/nfsd/nfs4acl.c +13 -4
@@ -369,12 +369,21 @@ pace_gt(struct posix_acl_entry *pace1, struct posix_acl_entry *pace2)return false; } -static void -sort_pacl_range (struct posix_acl *pacl,int start,int end) { +/** +* sort_pacl_range - sort a range of POSIX ACL entries by tag and id +* @pacl: POSIX ACL containing entries to sort +* @start: starting index of range to sort +* @end: ending index of range to sort (inclusive) +* +* Sorts ACL entries in place so that USER entries are ordered by UID +* and GROUP entries are ordered by GID. Required before calling +* posix_acl_valid(). +*/ +void sort_pacl_range (struct posix_acl *pacl,int start,int end) +{int sorted =0 , i; -/* We just do a bubble sort; easy to do in place, and we're not -* expecting acl's to be long enough to justify anything more. */ +/* Bubble sort: acceptable here because ACLs are typically short. */ while (!sorted) { sorted =1 ;for (i = start; i < end; i++) {
fs/nfsd/nfs4xdr.c +151 -6
198 lines not on this page · raw message
fs/nfsd/xdr4.h +6 -0
@@ -245,6 +245,8 @@ struct nfsd4_create {int cr_umask;/* request */ struct nfsd4_change_info cr_cinfo;/* response */ struct nfs4_acl *cr_acl; +struct posix_acl *cr_dpacl; +struct posix_acl *cr_pacl;struct xdr_netobj cr_label; };#define cr_datalen u.link.datalen
@@ -397,6 +399,8 @@ struct nfsd4_open {struct nfs4_ol_stateid *op_stp;/* used during processing */ struct nfs4_clnt_odstate *op_odstate;/* used during processing */ struct nfs4_acl *op_acl; +struct posix_acl *op_dpacl; +struct posix_acl *op_pacl;struct xdr_netobj op_label;struct svc_rqst *op_rqstp; };
@@ -483,6 +487,8 @@ struct nfsd4_setattr {struct iattr sa_iattr;/* request */ struct nfs4_acl *sa_acl;struct xdr_netobj sa_label; +struct posix_acl *sa_dpacl; +struct posix_acl *sa_pacl; };struct nfsd4_setclientid {
Signature · 1 line
2.52.0
Quoted 52 lines · Chuck Lever
From: Chuck Lever <[email protected]>
The Internet draft "POSIX Draft ACL support for Network File System Version 4, Minor Version 2":
https://datatracker.ietf.org/doc/draft-ietf-nfsv4-posix-acls/
defines an extension to NFSv4.2 that enables POSIX draft ACLs to be retrieved and set directly, without the lossy
NFSv4->POSIXdraft mapping algorithm. The extension adds four new attributes to the protocol.This patch series implements the server side of this extension for knfsd. The mechanism is analogous to the
NFS_ACLsideband protocol used with NFSv2/3, enabling POSIX draft ACLs to be manipulated directly by getfacl(1) and setfacl(1).The current implementation does not support "per file" scope, where individual file objects store either an NFSv4 ACL or a POSIX draft ACL. Instead, the implementation assumes POSIX draft ACLs apply to an entire file system when support for POSIX draft ACLs is indicated.
Based on the nfsd-testing branch from:
https://git.kernel.org/pub/scm/linux/kernel/git/cel/linux.git
Changes since v1:
- Fold the patches with fixes into the first 8 patches
- Ensure the series is bisect-able
- AddCONFIG_NFSD_V4_POSIX_ACLS-- this feature is experimental
- Set "SUPPATTR" bits only at the end of series
- Use xdrgen, where practical, instead of hand-coded XDR
- Refactor SETATTR/CREATE to integrate better with existing APIsChuck Lever (3):
NFSD: Add aKconfigsetting to enable support for NFSv4 POSIX ACLs Add RPC language definition of NFSv4 POSIX ACL extension
NFSD: Add POSIX ACL file attributes to SUPPATTR bitmasksRick Macklem (9):
NFSD: Addnfsd4_encode_fattr4_acl_trueform
NFSD: Addnfsd4_encode_fattr4_acl_trueform_scope
NFSD: Addnfsd4_encode_fattr4_posix_default_acl
NFSD: Addnfsd4_encode_fattr4_posix_access_acl
NFSD: Do not allow NFSv4 (N)VERIFY to check POSIX ACL attributes
NFSD: Refactor nfsd_setattr()'s ACL error reporting
NFSD: Add support for XDR decoding POSIX draft ACLs
NFSD: Add support for POSIX draft ACLs for file creation
NFSD: Add POSIX draft ACL support to the NFSv4 SETATTR operation
Quoted 15 lines
Documentation/sunrpc/xdr/nfs4_1.x | 56 +++++ fs/nfsd/Kconfig | 19 ++ fs/nfsd/acl.h | 1 + fs/nfsd/nfs4acl.c | 17 +- fs/nfsd/nfs4proc.c | 96 ++++++-- fs/nfsd/nfs4xdr.c | 356 ++++++++++++++++++++++++++- fs/nfsd/nfs4xdr_gen.c | 167 ++++++++++++- fs/nfsd/nfs4xdr_gen.h | 12 +- fs/nfsd/nfsd.h | 17 +- fs/nfsd/vfs.c | 34 ++- fs/nfsd/vfs.h | 3 +- fs/nfsd/xdr4.h | 6 + include/linux/nfs4.h | 4 + include/linux/sunrpc/xdrgen/nfs4_1.h | 73 +++++- 14 files changed, 822 insertions(+), 39 deletions(-)
This all looks pretty reasonable. Nice work!