All of lore.kernel.org
 help / color / mirror / Atom feed
From: Salvatore Mesoraca <s.mesoraca16@gmail.com>
To: linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org
Cc: James Morris <james.l.morris@oracle.com>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Salvatore Mesoraca <s.mesoraca16@gmail.com>
Subject: [PATCH] Adding return value to securityfs_remove.
Date: Sun, 2 Aug 2015 09:36:57 +0200	[thread overview]
Message-ID: <55bdec45.50ceb40a.3dcbf.fffff1b7@mx.google.com> (raw)

"securityfs_remove" can fail if it tries to remove a non-empty directory.
This can happen, for example, if it tries to remove a file and its
parent directory while the file is busy: the file removal will be
delayed and the directory removal will fail.
This patch adds a return value to "securityfs_remove" so that the caller
knows if it succeeded or not.

Signed-off-by: Salvatore Mesoraca <s.mesoraca16@gmail.com>
---
 include/linux/security.h |  4 ++--
 security/inode.c         | 14 +++++++++-----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/include/linux/security.h b/include/linux/security.h
index 79d85dd..ff022fc 100644
--- a/include/linux/security.h
+++ b/include/linux/security.h
@@ -1590,7 +1590,7 @@ extern struct dentry *securityfs_create_file(const char *name, umode_t mode,
 					     struct dentry *parent, void *data,
 					     const struct file_operations *fops);
 extern struct dentry *securityfs_create_dir(const char *name, struct dentry *parent);
-extern void securityfs_remove(struct dentry *dentry);
+extern int securityfs_remove(struct dentry *dentry);

 #else /* CONFIG_SECURITYFS */

@@ -1609,7 +1609,7 @@ static inline struct dentry *securityfs_create_file(const char *name,
 	return ERR_PTR(-ENODEV);
 }

-static inline void securityfs_remove(struct dentry *dentry)
+static inline int securityfs_remove(struct dentry *dentry)
 {}

 #endif
diff --git a/security/inode.c b/security/inode.c
index 16622ae..41f42ea 100644
--- a/security/inode.c
+++ b/security/inode.c
@@ -183,28 +183,32 @@ EXPORT_SYMBOL_GPL(securityfs_create_dir);
  * This function is required to be called in order for the file to be
  * removed. No automatic cleanup of files will happen when a module is
  * removed; you are responsible here.
+ *
+ * Returns 0 if the remove succeeds, -errno on error.
  */
-void securityfs_remove(struct dentry *dentry)
+int securityfs_remove(struct dentry *dentry)
 {
+	int ret = -EINVAL;
 	struct dentry *parent;

 	if (!dentry || IS_ERR(dentry))
-		return;
+		return ret;

 	parent = dentry->d_parent;
 	if (!parent || d_really_is_negative(parent))
-		return;
+		return ret;

 	mutex_lock(&d_inode(parent)->i_mutex);
 	if (simple_positive(dentry)) {
 		if (d_is_dir(dentry))
-			simple_rmdir(d_inode(parent), dentry);
+			ret = simple_rmdir(d_inode(parent), dentry);
 		else
-			simple_unlink(d_inode(parent), dentry);
+			ret = simple_unlink(d_inode(parent), dentry);
 		dput(dentry);
 	}
 	mutex_unlock(&d_inode(parent)->i_mutex);
 	simple_release_fs(&mount, &mount_count);
+	return ret;
 }
 EXPORT_SYMBOL_GPL(securityfs_remove);

--
2.3.6


                 reply	other threads:[~2015-08-02 10:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=55bdec45.50ceb40a.3dcbf.fffff1b7@mx.google.com \
    --to=s.mesoraca16@gmail.com \
    --cc=james.l.morris@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.