Skip to content

Commit 3160a71

Browse files
J. Bruce FieldsLinus Torvalds
authored andcommitted
[PATCH] knfsd: nfsd4: fix handling of directories without default ACLs
When setting an ACL that lacks inheritable ACEs on a directory, we should set a default ACL of zero length, not a default ACL with all bits denied. Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu> Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent bec50c4 commit 3160a71

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

‎fs/nfsd/nfs4acl.c‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ struct posix_ace_state_array {
416416
* calculated so far: */
417417

418418
struct posix_acl_state {
419+
int empty;
419420
struct posix_ace_state owner;
420421
struct posix_ace_state group;
421422
struct posix_ace_state other;
@@ -431,6 +432,7 @@ init_state(struct posix_acl_state *state, int cnt)
431432
int alloc;
432433

433434
memset(state, 0, sizeof(struct posix_acl_state));
435+
state->empty = 1;
434436
/*
435437
* In the worst case, each individual acl could be for a distinct
436438
* named user or group, but we don't no which, so we allocate
@@ -498,6 +500,20 @@ posix_state_to_acl(struct posix_acl_state *state, unsigned int flags)
498500
int nace;
499501
int i, error = 0;
500502

503+
/*
504+
* ACLs with no ACEs are treated differently in the inheritable
505+
* and effective cases: when there are no inheritable ACEs, we
506+
* set a zero-length default posix acl:
507+
*/
508+
if (state->empty && (flags & NFS4_ACL_TYPE_DEFAULT)) {
509+
pacl = posix_acl_alloc(0, GFP_KERNEL);
510+
return pacl ? pacl : ERR_PTR(-ENOMEM);
511+
}
512+
/*
513+
* When there are no effective ACEs, the following will end
514+
* up setting a 3-element effective posix ACL with all
515+
* permissions zero.
516+
*/
501517
nace = 4 + state->users->n + state->groups->n;
502518
pacl = posix_acl_alloc(nace, GFP_KERNEL);
503519
if (!pacl)
@@ -613,6 +629,8 @@ static void process_one_v4_ace(struct posix_acl_state *state,
613629
u32 mask = ace->access_mask;
614630
int i;
615631

632+
state->empty = 0;
633+
616634
switch (ace2type(ace)) {
617635
case ACL_USER_OBJ:
618636
if (ace->type == NFS4_ACE_ACCESS_ALLOWED_ACE_TYPE) {
@@ -717,7 +735,8 @@ int nfs4_acl_nfsv4_to_posix(struct nfs4_acl *acl, struct posix_acl **pacl,
717735
ret = PTR_ERR(*pacl);
718736
goto out_dstate;
719737
}
720-
*dpacl = posix_state_to_acl(&default_acl_state, flags);
738+
*dpacl = posix_state_to_acl(&default_acl_state,
739+
flags | NFS4_ACL_TYPE_DEFAULT);
721740
if (IS_ERR(*dpacl)) {
722741
ret = PTR_ERR(*dpacl);
723742
posix_acl_release(*pacl);

0 commit comments

Comments
 (0)