Skip to content

Commit d424797

Browse files
jtlaytonchucklever
authored andcommitted
nfsd: inherit required unset default acls from effective set
A well-formed NFSv4 ACL will always contain OWNER@/GROUP@/EVERYONE@ ACEs, but there is no requirement for inheritable entries for those entities. POSIX ACLs must always have owner/group/other entries, even for a default ACL. nfsd builds the default ACL from inheritable ACEs, but the current code just leaves any unspecified ACEs zeroed out. The result is that adding a default user or group ACE to an inode can leave it with unwanted deny entries. For instance, a newly created directory with no acl will look something like this: # NFSv4 translation by server A::OWNER@:rwaDxtTcCy A::GROUP@:rxtcy A::EVERYONE@:rxtcy # POSIX ACL of underlying file user::rwx group::r-x other::r-x ...if I then add new v4 ACE: nfs4_setfacl -a A:fd:1000:rwx /mnt/local/test ...I end up with a result like this today: user::rwx user:1000:rwx group::r-x mask::rwx other::r-x default:user::--- default:user:1000:rwx default:group::--- default:mask::rwx default:other::--- A::OWNER@:rwaDxtTcCy A::1000:rwaDxtcy A::GROUP@:rxtcy A::EVERYONE@:rxtcy D:fdi:OWNER@:rwaDx A:fdi:OWNER@:tTcCy A:fdi:1000:rwaDxtcy A:fdi:GROUP@:tcy A:fdi:EVERYONE@:tcy ...which is not at all expected. Adding a single inheritable allow ACE should not result in everyone else losing access. The setfacl command solves a silimar issue by copying owner/group/other entries from the effective ACL when none of them are set: "If a Default ACL entry is created, and the Default ACL contains no owner, owning group, or others entry, a copy of the ACL owner, owning group, or others entry is added to the Default ACL. Having nfsd do the same provides a more sane result (with no deny ACEs in the resulting set): user::rwx user:1000:rwx group::r-x mask::rwx other::r-x default:user::rwx default:user:1000:rwx default:group::r-x default:mask::rwx default:other::r-x A::OWNER@:rwaDxtTcCy A::1000:rwaDxtcy A::GROUP@:rxtcy A::EVERYONE@:rxtcy A:fdi:OWNER@:rwaDxtTcCy A:fdi:1000:rwaDxtcy A:fdi:GROUP@:rxtcy A:fdi:EVERYONE@:rxtcy Reported-by: Ondrej Valousek <[email protected]> Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2136452 Suggested-by: Andreas Gruenbacher <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent f807747 commit d424797

File tree

1 file changed

+29
-5
lines changed

1 file changed

+29
-5
lines changed

fs/nfsd/nfs4acl.c

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ struct posix_ace_state_array {
441441
* calculated so far: */
442442

443443
struct posix_acl_state {
444-
int empty;
444+
unsigned char valid;
445445
struct posix_ace_state owner;
446446
struct posix_ace_state group;
447447
struct posix_ace_state other;
@@ -457,7 +457,6 @@ init_state(struct posix_acl_state *state, int cnt)
457457
int alloc;
458458

459459
memset(state, 0, sizeof(struct posix_acl_state));
460-
state->empty = 1;
461460
/*
462461
* In the worst case, each individual acl could be for a distinct
463462
* named user or group, but we don't know which, so we allocate
@@ -500,7 +499,7 @@ posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
500499
* and effective cases: when there are no inheritable ACEs,
501500
* calls ->set_acl with a NULL ACL structure.
502501
*/
503-
if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT))
502+
if (!state->valid && (flags & NFS4_ACL_TYPE_DEFAULT))
504503
return NULL;
505504

506505
/*
@@ -622,11 +621,12 @@ static void process_one_v4_ace(struct posix_acl_state *state,
622621
struct nfs4_ace *ace)
623622
{
624623
u32 mask = ace->access_mask;
624+
short type = ace2type(ace);
625625
int i;
626626

627-
state->empty = 0;
627+
state->valid |= type;
628628

629-
switch (ace2type(ace)) {
629+
switch (type) {
630630
case ACL_USER_OBJ:
631631
if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
632632
allow_bits(&state->owner, mask);
@@ -726,6 +726,30 @@ static int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *acl,
726726
if (!(ace->flag & NFS4_ACE_INHERIT_ONLY_ACE))
727727
process_one_v4_ace(&effective_acl_state, ace);
728728
}
729+
730+
/*
731+
* At this point, the default ACL may have zeroed-out entries for owner,
732+
* group and other. That usually results in a non-sensical resulting ACL
733+
* that denies all access except to any ACE that was explicitly added.
734+
*
735+
* The setfacl command solves a similar problem with this logic:
736+
*
737+
* "If a Default ACL entry is created, and the Default ACL contains
738+
* no owner, owning group, or others entry, a copy of the ACL
739+
* owner, owning group, or others entry is added to the Default ACL."
740+
*
741+
* Copy any missing ACEs from the effective set, if any ACEs were
742+
* explicitly set.
743+
*/
744+
if (default_acl_state.valid) {
745+
if (!(default_acl_state.valid & ACL_USER_OBJ))
746+
default_acl_state.owner = effective_acl_state.owner;
747+
if (!(default_acl_state.valid & ACL_GROUP_OBJ))
748+
default_acl_state.group = effective_acl_state.group;
749+
if (!(default_acl_state.valid & ACL_OTHER))
750+
default_acl_state.other = effective_acl_state.other;
751+
}
752+
729753
*pacl = posix_state_to_acl(&effective_acl_state, flags);
730754
if (IS_ERR(*pacl)) {
731755
ret = PTR_ERR(*pacl);

0 commit comments

Comments
 (0)