blob: fdddbd84e0a6e8495dc999f61457a2616bc5336c [file] [log] [blame]
From 4fe7399523a82cd38831693d232084be35668710 Mon Sep 17 00:00:00 2001
From: Daniel Rosenberg <drosen@google.com>
Date: Thu, 15 Mar 2018 20:58:32 -0700
Subject: [PATCH] CHROMIUM: configfs: inherit file and directory owners
All entries in configfs are currently owned by root,
regardless of context. Instead, this preserves the
current ownership, allowing userspace to choose who
has permissions to configure the system through
any particular configfs subsystem.
This means anyone who can create a group will now
have the ability to create any groups inside of that
group.
Conflicts:
CURRENT_TIME is no longer defined, reworked
to use specified time granularity.
BUG=b:63876697
TEST=compilation, mkdir under configfs after chowning
Change-Id: I11087cdd58ff1560de72c9452f1ba13881f10cf6
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/965762
Tested-by: Gwendal Grignou <gwendal@google.com>
(cherry picked from commit fa9d2f446d10940f6e6bef4cd8c6d027e95cd0c4)
Reviewed-on: https://chromium-review.googlesource.com/1102012
Commit-Ready: Sarthak Kukreti <sarthakkukreti@chromium.org>
Tested-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
[rebase419(groeck): timebase -> timebase64 changes]
Signed-off-by: Guenter Roeck <groeck@chromium.org>
[rebase54(groeck):
Replace current_kernel_time64() with new API
configfs_create() returns an ERR_PTR on error
]
Signed-off-by: Guenter Roeck <groeck@chromium.org>
[rebase510(groeck):
fs/configfs/inode.c: timespec64_trunc() no longer exists
]
Signed-off-by: Guenter Roeck <groeck@chromium.org>
Change-Id: Ie486fdbda75565284203adc5dfc2d4ccc890ebdd
---
fs/configfs/inode.c | 39 ++++++++++++++++++++++++++++++++-------
1 file changed, 32 insertions(+), 7 deletions(-)
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index 42c348bb2903..0e87a222a1d8 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -40,6 +40,28 @@ 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, unsigned int s_time_gran)
+{
+ 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 user_namespace *mnt_userns, struct dentry *dentry,
struct iattr *iattr)
{
@@ -55,15 +77,9 @@ int configfs_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,
sd_iattr = sd->s_iattr;
if (!sd_iattr) {
/* setting attributes for the first time, allocate now */
- sd_iattr = kzalloc(sizeof(struct iattr), GFP_KERNEL);
+ sd_iattr = configfs_alloc_iattr(NULL, sd, inode->i_sb->s_time_gran);
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 */
@@ -167,6 +183,7 @@ struct inode *configfs_create(struct dentry *dentry, umode_t mode)
struct inode *inode = NULL;
struct configfs_dirent *sd;
struct inode *p_inode;
+ struct dentry *parent;
if (!dentry)
return ERR_PTR(-ENOENT);
@@ -175,6 +192,14 @@ struct inode *configfs_create(struct dentry *dentry, umode_t mode)
return ERR_PTR(-EEXIST);
sd = dentry->d_fsdata;
+ parent = dget_parent(dentry);
+ if (parent && !sd->s_iattr) {
+ sd->s_iattr = configfs_alloc_iattr(parent->d_fsdata, sd,
+ parent->d_sb->s_time_gran);
+ if (!sd->s_iattr)
+ return ERR_PTR(-ENOMEM);
+ }
+ dput(parent);
inode = configfs_new_inode(mode, sd, dentry->d_sb);
if (!inode)
return ERR_PTR(-ENOMEM);
--
2.17.1