mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-15 15:36:56 +07:00
b8a7a3a667
When get_acl() is called for an inode whose ACL is not cached yet, the get_acl inode operation is called to fetch the ACL from the filesystem. The inode operation is responsible for updating the cached acl with set_cached_acl(). This is done without locking at the VFS level, so another task can call set_cached_acl() or forget_cached_acl() before the get_acl inode operation gets to calling set_cached_acl(), and then get_acl's call to set_cached_acl() results in caching an outdate ACL. Prevent this from happening by setting the cached ACL pointer to a task-specific sentinel value before calling the get_acl inode operation. Move the responsibility for updating the cached ACL from the get_acl inode operations to get_acl(). There, only set the cached ACL if the sentinel value hasn't changed. The sentinel values are chosen to have odd values. Likewise, the value of ACL_NOT_CACHED is odd. In contrast, ACL object pointers always have an even value (ACLs are aligned in memory). This allows to distinguish uncached ACLs values from ACL objects. In addition, switch from guarding inode->i_acl and inode->i_default_acl upates by the inode->i_lock spinlock to using xchg() and cmpxchg(). Filesystems that do not want ACLs returned from their get_acl inode operations to be cached must call forget_cached_acl() to prevent the VFS from doing so. (Patch written by Al Viro and Andreas Gruenbacher.) Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
138 lines
2.8 KiB
C
138 lines
2.8 KiB
C
/*
|
|
* linux/fs/hfsplus/posix_acl.c
|
|
*
|
|
* Vyacheslav Dubeyko <slava@dubeyko.com>
|
|
*
|
|
* Handler for Posix Access Control Lists (ACLs) support.
|
|
*/
|
|
|
|
#include "hfsplus_fs.h"
|
|
#include "xattr.h"
|
|
#include "acl.h"
|
|
|
|
struct posix_acl *hfsplus_get_posix_acl(struct inode *inode, int type)
|
|
{
|
|
struct posix_acl *acl;
|
|
char *xattr_name;
|
|
char *value = NULL;
|
|
ssize_t size;
|
|
|
|
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
|
|
|
|
switch (type) {
|
|
case ACL_TYPE_ACCESS:
|
|
xattr_name = XATTR_NAME_POSIX_ACL_ACCESS;
|
|
break;
|
|
case ACL_TYPE_DEFAULT:
|
|
xattr_name = XATTR_NAME_POSIX_ACL_DEFAULT;
|
|
break;
|
|
default:
|
|
return ERR_PTR(-EINVAL);
|
|
}
|
|
|
|
size = __hfsplus_getxattr(inode, xattr_name, NULL, 0);
|
|
|
|
if (size > 0) {
|
|
value = (char *)hfsplus_alloc_attr_entry();
|
|
if (unlikely(!value))
|
|
return ERR_PTR(-ENOMEM);
|
|
size = __hfsplus_getxattr(inode, xattr_name, value, size);
|
|
}
|
|
|
|
if (size > 0)
|
|
acl = posix_acl_from_xattr(&init_user_ns, value, size);
|
|
else if (size == -ENODATA)
|
|
acl = NULL;
|
|
else
|
|
acl = ERR_PTR(size);
|
|
|
|
hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value);
|
|
|
|
return acl;
|
|
}
|
|
|
|
int hfsplus_set_posix_acl(struct inode *inode, struct posix_acl *acl,
|
|
int type)
|
|
{
|
|
int err;
|
|
char *xattr_name;
|
|
size_t size = 0;
|
|
char *value = NULL;
|
|
|
|
hfs_dbg(ACL_MOD, "[%s]: ino %lu\n", __func__, inode->i_ino);
|
|
|
|
switch (type) {
|
|
case ACL_TYPE_ACCESS:
|
|
xattr_name = XATTR_NAME_POSIX_ACL_ACCESS;
|
|
if (acl) {
|
|
err = posix_acl_equiv_mode(acl, &inode->i_mode);
|
|
if (err < 0)
|
|
return err;
|
|
}
|
|
err = 0;
|
|
break;
|
|
|
|
case ACL_TYPE_DEFAULT:
|
|
xattr_name = XATTR_NAME_POSIX_ACL_DEFAULT;
|
|
if (!S_ISDIR(inode->i_mode))
|
|
return acl ? -EACCES : 0;
|
|
break;
|
|
|
|
default:
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (acl) {
|
|
size = posix_acl_xattr_size(acl->a_count);
|
|
if (unlikely(size > HFSPLUS_MAX_INLINE_DATA_SIZE))
|
|
return -ENOMEM;
|
|
value = (char *)hfsplus_alloc_attr_entry();
|
|
if (unlikely(!value))
|
|
return -ENOMEM;
|
|
err = posix_acl_to_xattr(&init_user_ns, acl, value, size);
|
|
if (unlikely(err < 0))
|
|
goto end_set_acl;
|
|
}
|
|
|
|
err = __hfsplus_setxattr(inode, xattr_name, value, size, 0);
|
|
|
|
end_set_acl:
|
|
hfsplus_destroy_attr_entry((hfsplus_attr_entry *)value);
|
|
|
|
if (!err)
|
|
set_cached_acl(inode, type, acl);
|
|
|
|
return err;
|
|
}
|
|
|
|
int hfsplus_init_posix_acl(struct inode *inode, struct inode *dir)
|
|
{
|
|
int err = 0;
|
|
struct posix_acl *default_acl, *acl;
|
|
|
|
hfs_dbg(ACL_MOD,
|
|
"[%s]: ino %lu, dir->ino %lu\n",
|
|
__func__, inode->i_ino, dir->i_ino);
|
|
|
|
if (S_ISLNK(inode->i_mode))
|
|
return 0;
|
|
|
|
err = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
|
|
if (err)
|
|
return err;
|
|
|
|
if (default_acl) {
|
|
err = hfsplus_set_posix_acl(inode, default_acl,
|
|
ACL_TYPE_DEFAULT);
|
|
posix_acl_release(default_acl);
|
|
}
|
|
|
|
if (acl) {
|
|
if (!err)
|
|
err = hfsplus_set_posix_acl(inode, acl,
|
|
ACL_TYPE_ACCESS);
|
|
posix_acl_release(acl);
|
|
}
|
|
return err;
|
|
}
|