From: ebiederm@xmission.com (Eric W. Biederman)
To: Greg Kroah-Hartman <gregkh@suse.de>, David Miller <davem@davemloft.net>
Cc: <linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
Tejun Heo <htejun@gmail.com>, Jay Vosburgh <fubar@us.ibm.com>,
Andy Gospodarek <andy@greyhouse.net>
Subject: [PATCH 5/5] sysfs: Reject with a warning invalid uses of tagged directories.
Date: Thu, 13 Oct 2011 01:02:43 -0700 [thread overview]
Message-ID: <m1aa959v4s.fsf_-_@fess.ebiederm.org> (raw)
In-Reply-To: <m1ehyh9v6p.fsf_-_@fess.ebiederm.org> (Eric W. Biederman's message of "Thu, 13 Oct 2011 01:01:34 -0700")
sysfs is a core piece of ifrastructure that many people use and
few people have all of the rules in their head on how to use
it correctly. Add warnings for people using tagged directories
improperly to that any misuses can be caught and diagnosed quickly.
A single inexpensive test in sysfs_find_dirent is almost sufficient
to catch all possible misuses. An additional warning is needed
in sysfs_add_dirent so that we actually fail when attempting to
add an untagged dirent in a tagged directory.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
fs/sysfs/dir.c | 14 ++++++++++++++
fs/sysfs/file.c | 3 ---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 352d26d..26f370a 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -384,6 +384,13 @@ int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd)
{
struct sysfs_inode_attrs *ps_iattr;
+ if (!!sysfs_ns_type(acxt->parent_sd) != !!sd->s_ns) {
+ WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
+ sysfs_ns_type(acxt->parent_sd)? "required": "invalid",
+ acxt->parent_sd->s_name, sd->s_name);
+ return -EINVAL;
+ }
+
if (sysfs_find_dirent(acxt->parent_sd, sd->s_ns, sd->s_name))
return -EEXIST;
@@ -542,6 +549,13 @@ struct sysfs_dirent *sysfs_find_dirent(struct sysfs_dirent *parent_sd,
{
struct sysfs_dirent *sd;
+ if (!!sysfs_ns_type(parent_sd) != !!ns) {
+ WARN(1, KERN_WARNING "sysfs: ns %s in '%s' for '%s'\n",
+ sysfs_ns_type(parent_sd)? "required": "invalid",
+ parent_sd->s_name, name);
+ return NULL;
+ }
+
for (sd = parent_sd->s_dir.children; sd; sd = sd->s_sibling) {
if (sd->s_ns != ns)
continue;
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 07c1b4e..d4e6080 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -466,9 +466,6 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
mutex_lock(&sysfs_mutex);
if (sd && dir)
- /* Only directories are tagged, so no need to pass
- * a tag explicitly.
- */
sd = sysfs_find_dirent(sd, NULL, dir);
if (sd && attr)
sd = sysfs_find_dirent(sd, NULL, attr);
--
1.7.2.5
next prev parent reply other threads:[~2011-10-13 8:02 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-13 7:47 [PATCH 0/5] Better namespace handling for /sys/class/net/bonding_masters Eric W. Biederman
2011-10-13 7:53 ` [PATCH 1/5] sysfs: Implement support for tagged files in sysfs Eric W. Biederman
2011-10-13 7:55 ` [PATCH 2/5] class: Implement support for class attrs in tagged sysfs directories Eric W. Biederman
2011-10-13 7:56 ` [PATCH 3/5] bonding: Use a per netns implementation of /sys/class/net/bonding_masters Eric W. Biederman
2011-10-13 8:01 ` [PATCH 4/5] sysfs: Remove support for tagged directories with untagged members Eric W. Biederman
2011-10-13 8:02 ` Eric W. Biederman [this message]
2011-10-13 17:25 ` [PATCH 0/5] Better namespace handling for /sys/class/net/bonding_masters Greg KH
2011-10-19 4:09 ` David Miller
2011-10-19 13:27 ` Eric W. Biederman
2011-10-19 22:49 ` David Miller
2011-10-19 14:36 ` Greg KH
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=m1aa959v4s.fsf_-_@fess.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=andy@greyhouse.net \
--cc=davem@davemloft.net \
--cc=fubar@us.ibm.com \
--cc=gregkh@suse.de \
--cc=htejun@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@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