From: Gwendal Grignou <gwendal@chromium.org>
To: jlbec@evilplan.org
Cc: drosen@google.com, linux-kernel@vger.kernel.org, jorgelo@chromium.org
Subject: [PATCH] configfs: inherit file and directory owners
Date: Fri, 13 Apr 2018 03:51:35 -0700 [thread overview]
Message-ID: <20180413105135.216944-1-gwendal@chromium.org> (raw)
In-Reply-To: <CAMHSBOX0sP5vnFJ8uzsRxoHi=cP874FZazp8uJs3UN8wu73ipw@mail.gmail.com>
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.
Signed-off-by: Daniel Rosenberg <drosen@google.com>
Signed-off-by: Gwendal Grignou <gwendal@chromium.org>
---
fs/configfs/inode.c | 38 +++++++++++++++++++++++++++++++-------
1 file changed, 31 insertions(+), 7 deletions(-)
diff --git a/fs/configfs/inode.c b/fs/configfs/inode.c
index ad718e5e37bb..1b55374de953 100644
--- a/fs/configfs/inode.c
+++ b/fs/configfs/inode.c
@@ -54,6 +54,28 @@ static const struct inode_operations configfs_inode_operations ={
.setattr = configfs_setattr,
};
+static struct iattr *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;
+ }
+ sd_iattr->ia_atime = sd_iattr->ia_mtime =
+ sd_iattr->ia_ctime = CURRENT_TIME;
+ return sd_iattr;
+}
+
int configfs_setattr(struct dentry * dentry, struct iattr * iattr)
{
struct inode * inode = d_inode(dentry);
@@ -68,15 +90,9 @@ int configfs_setattr(struct dentry * dentry, struct iattr * iattr)
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 = alloc_iattr(NULL, sd);
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 */
@@ -184,6 +200,7 @@ int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct in
struct inode *inode = NULL;
struct configfs_dirent *sd;
struct inode *p_inode;
+ struct dentry *parent;
if (!dentry)
return -ENOENT;
@@ -192,6 +209,13 @@ int configfs_create(struct dentry * dentry, umode_t mode, void (*init)(struct in
return -EEXIST;
sd = dentry->d_fsdata;
+ parent = dget_parent(dentry);
+ if (parent && !sd->s_iattr) {
+ sd->s_iattr = alloc_iattr(parent->d_fsdata, sd);
+ if (!sd->s_iattr)
+ return -ENOMEM;
+ }
+ dput(parent);
inode = configfs_new_inode(mode, sd, dentry->d_sb);
if (!inode)
return -ENOMEM;
--
2.17.0.484.g0c8726318c-goog
next prev parent reply other threads:[~2018-04-13 10:51 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 3:36 [PATCH] configfs: initialize inode with owner Gwendal Grignou
2018-03-08 0:11 ` Gwendal Grignou
2018-04-13 10:51 ` Gwendal Grignou [this message]
2018-04-13 21:01 ` [PATCH] configfs: inherit file and directory owners kbuild test robot
2018-04-13 22:35 ` kbuild test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180413105135.216944-1-gwendal@chromium.org \
--to=gwendal@chromium.org \
--cc=drosen@google.com \
--cc=jlbec@evilplan.org \
--cc=jorgelo@chromium.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®