lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <55bdec45.50ceb40a.3dcbf.fffff1b7@mx.google.com>
Date:	Sun, 2 Aug 2015 09:36:57 +0200
From:	Salvatore Mesoraca <s.mesoraca16@...il.com>
To:	linux-kernel@...r.kernel.org, linux-security-module@...r.kernel.org
Cc:	James Morris <james.l.morris@...cle.com>,
	Al Viro <viro@...iv.linux.org.uk>,
	Salvatore Mesoraca <s.mesoraca16@...il.com>
Subject: [PATCH] Adding return value to securityfs_remove.

"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@...il.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ