From: Tyler Hicks <tyhicks@canonical.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Tejun Heo <tj@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Stephen Hemminger <stephen@networkplumber.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
bridge@lists.linux-foundation.org,
Linux Containers <containers@lists.linux-foundation.org>
Subject: [PATCH net-next v2 4/7] driver core: set up ownership of class devices in sysfs
Date: Fri, 13 Jul 2018 16:05:46 +0000 [thread overview]
Message-ID: <1531497949-1766-5-git-send-email-tyhicks@canonical.com> (raw)
In-Reply-To: <1531497949-1766-1-git-send-email-tyhicks@canonical.com>
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Plumb in get_ownership() callback for devices belonging to a class so that
they can be created with uid/gid different from global root. This will
allow network devices in a container to belong to container's root and not
global root.
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Reviewed-by: Tyler Hicks <tyhicks@canonical.com>
---
drivers/base/core.c | 9 +++++++++
include/linux/device.h | 5 +++++
2 files changed, 14 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index df3e1a44707a..276c7e3f754c 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -866,10 +866,19 @@ static const void *device_namespace(struct kobject *kobj)
return ns;
}
+static void device_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid)
+{
+ struct device *dev = kobj_to_dev(kobj);
+
+ if (dev->class && dev->class->get_ownership)
+ dev->class->get_ownership(dev, uid, gid);
+}
+
static struct kobj_type device_ktype = {
.release = device_release,
.sysfs_ops = &dev_sysfs_ops,
.namespace = device_namespace,
+ .get_ownership = device_get_ownership,
};
diff --git a/include/linux/device.h b/include/linux/device.h
index 055a69dbcd18..fe6ccb6dc119 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -384,6 +384,9 @@ int subsys_virtual_register(struct bus_type *subsys,
* @shutdown_pre: Called at shut-down time before driver shutdown.
* @ns_type: Callbacks so sysfs can detemine namespaces.
* @namespace: Namespace of the device belongs to this class.
+ * @get_ownership: Allows class to specify uid/gid of the sysfs directories
+ * for the devices belonging to the class. Usually tied to
+ * device's namespace.
* @pm: The default device power management operations of this class.
* @p: The private data of the driver core, no one other than the
* driver core can touch this.
@@ -413,6 +416,8 @@ struct class {
const struct kobj_ns_type_operations *ns_type;
const void *(*namespace)(struct device *dev);
+ void (*get_ownership)(struct device *dev, kuid_t *uid, kgid_t *gid);
+
const struct dev_pm_ops *pm;
struct subsys_private *p;
--
2.7.4
next prev parent reply other threads:[~2018-07-13 16:08 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-13 16:05 [PATCH v2 net-next 0/7] Make /sys/class/net per net namespace objects belong to container Tyler Hicks
2018-07-13 16:05 ` [PATCH net-next v2 1/7] kernfs: allow creating kernfs objects with arbitrary uid/gid Tyler Hicks
2018-07-17 1:04 ` kbuild test robot
2018-07-13 16:05 ` [PATCH net-next v2 2/7] sysfs, kobject: allow creating kobject belonging to arbitrary users Tyler Hicks
2018-07-13 16:05 ` [PATCH net-next v2 3/7] kobject: kset_create_and_add() - fetch ownership info from parent Tyler Hicks
2018-07-13 16:05 ` Tyler Hicks [this message]
2018-07-13 16:05 ` [PATCH net-next v2 5/7] net-sysfs: make sure objects belong to contrainer's owner Tyler Hicks
2018-07-13 16:05 ` [PATCH net-next v2 6/7] net: Create reusable function for getting ownership info of sysfs inodes Tyler Hicks
2018-07-19 14:36 ` Christian Brauner
2018-07-20 21:58 ` Tyler Hicks
2018-07-13 16:05 ` [PATCH net-next v2 7/7] bridge: make sure objects belong to container's owner Tyler Hicks
2018-07-16 20:58 ` [PATCH v2 net-next 0/7] Make /sys/class/net per net namespace objects belong to container David Miller
2018-07-18 4:17 ` David Miller
2018-07-18 4:41 ` David Miller
2018-07-19 1:07 ` Tyler Hicks
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=1531497949-1766-5-git-send-email-tyhicks@canonical.com \
--to=tyhicks@canonical.com \
--cc=bridge@lists.linux-foundation.org \
--cc=containers@lists.linux-foundation.org \
--cc=davem@davemloft.net \
--cc=dmitry.torokhov@gmail.com \
--cc=ebiederm@xmission.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
--cc=tj@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;
as well as URLs for NNTP newsgroup(s).