blob: 4c3d433ac751699785f398c6885e2e609ef50f50 [file] [log] [blame]
From b6e6bd806c56fc5488f339a019f8f69d5653c036 Mon Sep 17 00:00:00 2001
From: Tzung-Bi Shih <tzungbi@chromium.org>
Date: Wed, 9 Aug 2023 17:45:25 +0800
Subject: [PATCH] FIXUP: CHROMIUM: configfs: inherit file and directory owners
This is a partial revert of commit e5e090ca9760 ("CHROMIUM: configfs:
inherit file and directory owners").
Reason: configfs_setattr() calls configfs_alloc_iattr() always with NULL
`sd_parent` which suggests it doesn't need to inherit from anywhere.
Revert the change in configfs_setattr() to keep it intact. As a good
result, it reduces the footprint of the CHROMIUM patch.
Also inline configfs_alloc_iattr() into the only one caller
configfs_create().
BUG=b:291009612
TEST=chown 1000:1000 /sys/kernel/config/sdcardsfs/ &&
ls -l /sys/kernel/config/sdcardfs/ &&
mkdir -p /sys/kernel/config/sdcardfs/1 &&
ls -l /sys/kernel/config/sdcardfs/
Change-Id: I8242c464655b8c761b9fdd1ade85a265285dfab9
Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/kernel/+/4764193
Reviewed-by: Guenter Roeck <groeck@chromium.org>
---
fs/configfs/inode.c | 48 ++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 0fcc7be50b95ae5aadc9706e28deee60c2976fd5..026fbedf396e6dc13900d63bae34f4ad0a1c76de 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -32,28 +32,6 @@ static const struct inode_operations configfs_inode_operations ={
.setattr = configfs_setattr,
};
-static struct iattr *configfs_alloc_iattr(struct configfs_dirent *sd_parent,
- struct configfs_dirent *sd)
-{
- struct iattr *sd_iattr;
-
- sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
- if (!sd_iattr)
- return NULL;
- /* assign default attributes */
- sd_iattr->ia_mode = sd->s_mode;
- if (sd_parent && sd_parent->s_iattr) {
- sd_iattr->ia_uid = sd_parent->s_iattr->ia_uid;
- sd_iattr->ia_gid = sd_parent->s_iattr->ia_gid;
- } else {
- sd_iattr->ia_uid = GLOBAL_ROOT_UID;
- sd_iattr->ia_gid = GLOBAL_ROOT_GID;
- }
- ktime_get_coarse_real_ts64(&sd_iattr->ia_ctime);
- sd_iattr->ia_atime = sd_iattr->ia_mtime = sd_iattr->ia_ctime;
- return sd_iattr;
-}
-
int configfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
struct iattr *iattr)
{
@@ -69,9 +47,15 @@ int configfs_setattr(struct mnt_idmap *idmap, struct dentry *dentry,
sd_iattr = sd->s_iattr;
if (!sd_iattr) {
/* setting attributes for the first time, allocate now */
- sd_iattr = configfs_alloc_iattr(NULL, sd);
+ sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
if (!sd_iattr)
return -ENOMEM;
+ /* assign default attributes */
+ sd_iattr->ia_mode = sd->s_mode;
+ sd_iattr->ia_uid = GLOBAL_ROOT_UID;
+ sd_iattr->ia_gid = GLOBAL_ROOT_GID;
+ sd_iattr->ia_atime = sd_iattr->ia_mtime =
+ sd_iattr->ia_ctime = current_time(inode);
sd->s_iattr = sd_iattr;
}
/* attributes were changed atleast once in past */
@@ -186,11 +170,27 @@ struct inode *configfs_create(struct dentry *dentry, umode_t mode)
sd = dentry->d_fsdata;
parent = dget_parent(dentry);
if (parent && !sd->s_iattr) {
- sd->s_iattr = configfs_alloc_iattr(parent->d_fsdata, sd);
+ struct configfs_dirent *sd_parent = parent->d_fsdata;
+
+ sd->s_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
if (!sd->s_iattr) {
dput(parent);
return ERR_PTR(-ENOMEM);
}
+
+ sd->s_iattr->ia_mode = sd->s_mode;
+ if (sd_parent && sd_parent->s_iattr) {
+ sd->s_iattr->ia_uid = sd_parent->s_iattr->ia_uid;
+ sd->s_iattr->ia_gid = sd_parent->s_iattr->ia_gid;
+ } else {
+ sd->s_iattr->ia_uid = GLOBAL_ROOT_UID;
+ sd->s_iattr->ia_gid = GLOBAL_ROOT_GID;
+ }
+ if (sd_parent->s_dentry && d_inode(sd_parent->s_dentry))
+ sd->s_iattr->ia_ctime = current_time(d_inode(sd_parent->s_dentry));
+ else
+ ktime_get_coarse_real_ts64(&sd->s_iattr->ia_ctime);
+ sd->s_iattr->ia_atime = sd->s_iattr->ia_mtime = sd->s_iattr->ia_ctime;
}
dput(parent);
inode = configfs_new_inode(mode, sd, dentry->d_sb);
--
2.34.1