Skip to content

Commit 0c3bc78

Browse files
committed
ntfs: fix acl handling
While looking at our current POSIX ACL handling in the context of some overlayfs work I went through a range of other filesystems checking how they handle them currently and encountered ntfs3. The posic_acl_{from,to}_xattr() helpers always need to operate on the filesystem idmapping. Since ntfs3 can only be mounted in the initial user namespace the relevant idmapping is init_user_ns. The posix_acl_{from,to}_xattr() helpers are concerned with translating between the kernel internal struct posix_acl{_entry} and the uapi struct posix_acl_xattr_{header,entry} and the kernel internal data structure is cached filesystem wide. Additional idmappings such as the caller's idmapping or the mount's idmapping are handled higher up in the VFS. Individual filesystems usually do not need to concern themselves with these. The posix_acl_valid() helper is concerned with checking whether the values in the kernel internal struct posix_acl can be represented in the filesystem's idmapping. IOW, if they can be written to disk. So this helper too needs to take the filesystem's idmapping. Fixes: be71b5c ("fs/ntfs3: Add attrib operations") Cc: Konstantin Komarov <[email protected]> Cc: [email protected] Signed-off-by: Christian Brauner (Microsoft) <[email protected]>
1 parent bf1ac16 commit 0c3bc78

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

fs/ntfs3/xattr.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,7 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,
478478
}
479479

480480
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
481-
static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns,
482-
struct inode *inode, int type,
481+
static struct posix_acl *ntfs_get_acl_ex(struct inode *inode, int type,
483482
int locked)
484483
{
485484
struct ntfs_inode *ni = ntfs_i(inode);
@@ -514,7 +513,7 @@ static struct posix_acl *ntfs_get_acl_ex(struct user_namespace *mnt_userns,
514513

515514
/* Translate extended attribute to acl. */
516515
if (err >= 0) {
517-
acl = posix_acl_from_xattr(mnt_userns, buf, err);
516+
acl = posix_acl_from_xattr(&init_user_ns, buf, err);
518517
} else if (err == -ENODATA) {
519518
acl = NULL;
520519
} else {
@@ -537,8 +536,7 @@ struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu)
537536
if (rcu)
538537
return ERR_PTR(-ECHILD);
539538

540-
/* TODO: init_user_ns? */
541-
return ntfs_get_acl_ex(&init_user_ns, inode, type, 0);
539+
return ntfs_get_acl_ex(inode, type, 0);
542540
}
543541

544542
static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,
@@ -595,7 +593,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,
595593
value = kmalloc(size, GFP_NOFS);
596594
if (!value)
597595
return -ENOMEM;
598-
err = posix_acl_to_xattr(mnt_userns, acl, value, size);
596+
err = posix_acl_to_xattr(&init_user_ns, acl, value, size);
599597
if (err < 0)
600598
goto out;
601599
flags = 0;
@@ -641,7 +639,7 @@ static int ntfs_xattr_get_acl(struct user_namespace *mnt_userns,
641639
if (!acl)
642640
return -ENODATA;
643641

644-
err = posix_acl_to_xattr(mnt_userns, acl, buffer, size);
642+
err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
645643
posix_acl_release(acl);
646644

647645
return err;
@@ -665,12 +663,12 @@ static int ntfs_xattr_set_acl(struct user_namespace *mnt_userns,
665663
if (!value) {
666664
acl = NULL;
667665
} else {
668-
acl = posix_acl_from_xattr(mnt_userns, value, size);
666+
acl = posix_acl_from_xattr(&init_user_ns, value, size);
669667
if (IS_ERR(acl))
670668
return PTR_ERR(acl);
671669

672670
if (acl) {
673-
err = posix_acl_valid(mnt_userns, acl);
671+
err = posix_acl_valid(&init_user_ns, acl);
674672
if (err)
675673
goto release_and_out;
676674
}

0 commit comments

Comments
 (0)