public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: gregkh@linuxfoundation.org
Cc: linux-kernel@vger.kernel.org, ebiederm@xmission.com,
	kay@vrfy.org, Tejun Heo <tj@kernel.org>
Subject: [PATCH 2/6] kernfs: add REMOVED check to create and rename paths
Date: Wed, 11 Dec 2013 16:02:56 -0500	[thread overview]
Message-ID: <1386795780-23324-3-git-send-email-tj@kernel.org> (raw)
In-Reply-To: <1386795780-23324-1-git-send-email-tj@kernel.org>

kernfs currently assumes that the caller doesn't try to create a new
node under a removed parent, rename a removed node, or move a node
under a removed node.  While this works fine for sysfs, it'd be nice
to have protection against such cases especially given that kernfs is
planned to add support for mkdir, rmdir and rename requsts from
userland which may make race conditions more likely.

This patch updates create and rename paths to check REMOVED and fail
the operation with -ENOENT if performed on or towards removed nodes.
Note that remove path already has such check.

Signed-off-by: Tejun Heo <tj@kernel.org>
---
 fs/kernfs/dir.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index e55bb02..ba5f372 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -430,6 +430,9 @@ int kernfs_add_one(struct kernfs_addrm_cxt *acxt, struct kernfs_node *kn,
 	if (kernfs_type(parent) != KERNFS_DIR)
 		return -EINVAL;
 
+	if (parent->flags & KERNFS_REMOVED)
+		return -ENOENT;
+
 	kn->hash = kernfs_name_hash(kn->name, kn->ns);
 	kn->parent = parent;
 	kernfs_get(parent);
@@ -863,6 +866,10 @@ int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
 
 	mutex_lock(&kernfs_mutex);
 
+	error = -ENOENT;
+	if ((kn->flags | new_parent->flags) & KERNFS_REMOVED)
+		goto out;
+
 	error = 0;
 	if ((kn->parent == new_parent) && (kn->ns == new_ns) &&
 	    (strcmp(kn->name, new_name) == 0))
-- 
1.8.4.2


  parent reply	other threads:[~2013-12-11 21:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-11 21:02 [PATCHSET driver-core-next] kernfs: implement kernfs_dir_ops Tejun Heo
2013-12-11 21:02 ` [PATCH 1/6] kernfs: add @mode to kernfs_create_dir[_ns]() Tejun Heo
2013-12-11 21:02 ` Tejun Heo [this message]
2013-12-11 21:02 ` [PATCH 3/6] kernfs: mark static names with KERNFS_STATIC_NAME Tejun Heo
2013-12-11 21:02 ` [PATCH 4/6] kernfs: update kernfs_rename_ns() to consider KERNFS_STATIC_NAME Tejun Heo
2013-12-11 21:02 ` [PATCH 5/6] kernfs: allow negative dentries Tejun Heo
2013-12-11 21:03 ` [PATCH 6/6] kernfs: add kernfs_dir_ops Tejun Heo
2013-12-11 21:05 ` test-kernfs module Tejun Heo
2013-12-11 21:19 ` [PATCHSET driver-core-next] kernfs: implement kernfs_dir_ops Greg KH
2013-12-11 21:22   ` Tejun Heo

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=1386795780-23324-3-git-send-email-tj@kernel.org \
    --to=tj@kernel.org \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kay@vrfy.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