Skip to content

Commit 223b845

Browse files
committed
Merge tag 'fs.acl.rework.prep.v6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping
Pull vfs acl updates from Christian Brauner: "These are general fixes and preparatory changes related to the ongoing posix acl rework. The actual rework where we build a type safe posix acl api wasn't ready for this merge window but we're hopeful for the next merge window. General fixes: - Some filesystems like 9p and cifs have to implement custom posix acl handlers because they require access to the dentry in order to set and get posix acls while the set and get inode operations currently don't. But the ntfs3 filesystem has no such requirement and thus implemented custom posix acl xattr handlers when it really didn't have to. So this pr contains patch that just implements set and get inode operations for ntfs3 and switches it to rely on the generic posix acl xattr handlers. (We would've appreciated reviews from the ntfs3 maintainers but we didn't get any. But hey, if we really broke it we'll fix it. But fstests for ntfs3 said it's fine.) - The posix_acl_fix_xattr_common() helper has been adapted so it can be used by a few more callers and avoiding open-coding the same checks over and over. Other than the two general fixes this series introduces a new helper vfs_set_acl_prepare(). The reason for this helper is so that we can mitigate one of the source that change {g,u}id values directly in the uapi struct. With the vfs_set_acl_prepare() helper we can move the idmapped mount fixup into the generic posix acl set handler. The advantage of this is that it allows us to remove the posix_acl_setxattr_idmapped_mnt() helper which so far we had to call in vfs_setxattr() to account for idmapped mounts. While semantically correct the problem with this approach was that we had to keep the value parameter of the generic vfs_setxattr() call as non-const. This is rectified in this series. Ultimately, we will get rid of all the extreme kludges and type unsafety once we have merged the posix api - hopefully during the next merge window - built solely around get and set inode operations. Which incidentally will also improve handling of posix acls in security and especially in integrity modesl. While this will come with temporarily having two inode operation for posix acls that is nothing compared to the problems we have right now and so well worth it. We'll end up with something that we can actually reason about instead of needing to write novels to explain what's going on" * tag 'fs.acl.rework.prep.v6.1' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/idmapping: xattr: always us is_posix_acl_xattr() helper acl: fix the comments of posix_acl_xattr_set xattr: constify value argument in vfs_setxattr() ovl: use vfs_set_acl_prepare() acl: move idmapping handling into posix_acl_xattr_set() acl: add vfs_set_acl_prepare() acl: return EOPNOTSUPP in posix_acl_fix_xattr_common() ntfs3: rework xattr handlers and switch to POSIX ACL VFS helpers
2 parents da380ae + 38e3163 commit 223b845

File tree

9 files changed

+264
-191
lines changed

9 files changed

+264
-191
lines changed

fs/ntfs3/inode.c

-2
Original file line numberDiff line numberDiff line change
@@ -1927,8 +1927,6 @@ const struct inode_operations ntfs_link_inode_operations = {
19271927
.setattr = ntfs3_setattr,
19281928
.listxattr = ntfs_listxattr,
19291929
.permission = ntfs_permission,
1930-
.get_acl = ntfs_get_acl,
1931-
.set_acl = ntfs_set_acl,
19321930
};
19331931

19341932
const struct address_space_operations ntfs_aops = {

fs/ntfs3/xattr.c

+6-96
Original file line numberDiff line numberDiff line change
@@ -625,67 +625,6 @@ int ntfs_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
625625
return ntfs_set_acl_ex(mnt_userns, inode, acl, type, false);
626626
}
627627

628-
static int ntfs_xattr_get_acl(struct user_namespace *mnt_userns,
629-
struct inode *inode, int type, void *buffer,
630-
size_t size)
631-
{
632-
struct posix_acl *acl;
633-
int err;
634-
635-
if (!(inode->i_sb->s_flags & SB_POSIXACL)) {
636-
ntfs_inode_warn(inode, "add mount option \"acl\" to use acl");
637-
return -EOPNOTSUPP;
638-
}
639-
640-
acl = ntfs_get_acl(inode, type, false);
641-
if (IS_ERR(acl))
642-
return PTR_ERR(acl);
643-
644-
if (!acl)
645-
return -ENODATA;
646-
647-
err = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
648-
posix_acl_release(acl);
649-
650-
return err;
651-
}
652-
653-
static int ntfs_xattr_set_acl(struct user_namespace *mnt_userns,
654-
struct inode *inode, int type, const void *value,
655-
size_t size)
656-
{
657-
struct posix_acl *acl;
658-
int err;
659-
660-
if (!(inode->i_sb->s_flags & SB_POSIXACL)) {
661-
ntfs_inode_warn(inode, "add mount option \"acl\" to use acl");
662-
return -EOPNOTSUPP;
663-
}
664-
665-
if (!inode_owner_or_capable(mnt_userns, inode))
666-
return -EPERM;
667-
668-
if (!value) {
669-
acl = NULL;
670-
} else {
671-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
672-
if (IS_ERR(acl))
673-
return PTR_ERR(acl);
674-
675-
if (acl) {
676-
err = posix_acl_valid(&init_user_ns, acl);
677-
if (err)
678-
goto release_and_out;
679-
}
680-
}
681-
682-
err = ntfs_set_acl(mnt_userns, inode, acl, type);
683-
684-
release_and_out:
685-
posix_acl_release(acl);
686-
return err;
687-
}
688-
689628
/*
690629
* ntfs_init_acl - Initialize the ACLs of a new inode.
691630
*
@@ -852,23 +791,6 @@ static int ntfs_getxattr(const struct xattr_handler *handler, struct dentry *de,
852791
goto out;
853792
}
854793

855-
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
856-
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
857-
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
858-
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
859-
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
860-
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
861-
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
862-
/* TODO: init_user_ns? */
863-
err = ntfs_xattr_get_acl(
864-
&init_user_ns, inode,
865-
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
866-
? ACL_TYPE_ACCESS
867-
: ACL_TYPE_DEFAULT,
868-
buffer, size);
869-
goto out;
870-
}
871-
#endif
872794
/* Deal with NTFS extended attribute. */
873795
err = ntfs_get_ea(inode, name, name_len, buffer, size, NULL);
874796

@@ -981,22 +903,6 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,
981903
goto out;
982904
}
983905

984-
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
985-
if ((name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1 &&
986-
!memcmp(name, XATTR_NAME_POSIX_ACL_ACCESS,
987-
sizeof(XATTR_NAME_POSIX_ACL_ACCESS))) ||
988-
(name_len == sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1 &&
989-
!memcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT,
990-
sizeof(XATTR_NAME_POSIX_ACL_DEFAULT)))) {
991-
err = ntfs_xattr_set_acl(
992-
mnt_userns, inode,
993-
name_len == sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1
994-
? ACL_TYPE_ACCESS
995-
: ACL_TYPE_DEFAULT,
996-
value, size);
997-
goto out;
998-
}
999-
#endif
1000906
/* Deal with NTFS extended attribute. */
1001907
err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0);
1002908

@@ -1086,15 +992,19 @@ static bool ntfs_xattr_user_list(struct dentry *dentry)
1086992
}
1087993

1088994
// clang-format off
1089-
static const struct xattr_handler ntfs_xattr_handler = {
995+
static const struct xattr_handler ntfs_other_xattr_handler = {
1090996
.prefix = "",
1091997
.get = ntfs_getxattr,
1092998
.set = ntfs_setxattr,
1093999
.list = ntfs_xattr_user_list,
10941000
};
10951001

10961002
const struct xattr_handler *ntfs_xattr_handlers[] = {
1097-
&ntfs_xattr_handler,
1003+
#ifdef CONFIG_NTFS3_FS_POSIX_ACL
1004+
&posix_acl_access_xattr_handler,
1005+
&posix_acl_default_xattr_handler,
1006+
#endif
1007+
&ntfs_other_xattr_handler,
10981008
NULL,
10991009
};
11001010
// clang-format on

fs/overlayfs/overlayfs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static inline int ovl_do_setxattr(struct ovl_fs *ofs, struct dentry *dentry,
250250
size_t size, int flags)
251251
{
252252
int err = vfs_setxattr(ovl_upper_mnt_userns(ofs), dentry, name,
253-
(void *)value, size, flags);
253+
value, size, flags);
254254

255255
pr_debug("setxattr(%pd2, \"%s\", \"%*pE\", %zu, %d) = %i\n",
256256
dentry, name, min((int)size, 48), value, size, flags, err);

fs/overlayfs/super.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,20 @@ ovl_posix_acl_xattr_set(const struct xattr_handler *handler,
10221022

10231023
/* Check that everything is OK before copy-up */
10241024
if (value) {
1025-
acl = posix_acl_from_xattr(&init_user_ns, value, size);
1025+
/* The above comment can be understood in two ways:
1026+
*
1027+
* 1. We just want to check whether the basic POSIX ACL format
1028+
* is ok. For example, if the header is correct and the size
1029+
* is sane.
1030+
* 2. We want to know whether the ACL_{GROUP,USER} entries can
1031+
* be mapped according to the underlying filesystem.
1032+
*
1033+
* Currently, we only check 1. If we wanted to check 2. we
1034+
* would need to pass the mnt_userns and the fs_userns of the
1035+
* underlying filesystem. But frankly, I think checking 1. is
1036+
* enough to start the copy-up.
1037+
*/
1038+
acl = vfs_set_acl_prepare(&init_user_ns, &init_user_ns, value, size);
10261039
if (IS_ERR(acl))
10271040
return PTR_ERR(acl);
10281041
}

0 commit comments

Comments
 (0)