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>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Fri, 29 May 2009 13:19:36 -0700
From:	"Eric W. Biederman" <ebiederm@...ssion.com>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Greg Kroah-Hartman <gregkh@...e.de>
Cc:	<linux-kernel@...r.kernel.org>, Tejun Heo <tj@...nel.org>,
	Cornelia Huck <cornelia.huck@...ibm.com>,
	<linux-fsdevel@...r.kernel.org>,
	Kay Sievers <kay.sievers@...y.org>, Greg KH <greg@...ah.com>,
	"Eric W. Biederman" <ebiederm@...ssion.com>,
	"Eric W. Biederman" <ebiederm@...stanetworks.com>
Subject: [PATCH 26/26] sysfs: In sysfs_add_one fail if the targe directory has been removed.

From: Eric W. Biederman <ebiederm@...ssion.com>

If a bug in the upper layers results in someone attempting to add
to a sysfs directory that has already been removed, warn about it
and fail.

I don't believe this has ever happened, and it certainly never should
happen, but be strict to avoid errors creeping in.

Acked-by: Kay Sievers <kay.sievers@...y.org>
Acked-by: Tejun Heo <tj@...nel.org>
Signed-off-by: Eric W. Biederman <ebiederm@...stanetworks.com>
---
 fs/sysfs/dir.c |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
index 7da42fb..fda141d 100644
--- a/fs/sysfs/dir.c
+++ b/fs/sysfs/dir.c
@@ -394,21 +394,17 @@ static char *sysfs_pathname(struct sysfs_dirent *sd, char *path)
 int sysfs_add_one(struct sysfs_dirent *parent_sd, struct sysfs_dirent *sd)
 {
 	struct iattr *ps_iattr;
+	char *path;
+	int result;
 
 	mutex_lock(&sysfs_mutex);
-	if (sysfs_find_dirent(parent_sd, sd->s_name)) {
-		char *path;
-		mutex_unlock(&sysfs_mutex);
 
-		path = kzalloc(PATH_MAX, GFP_KERNEL);
-		WARN(1, KERN_WARNING
-		     "sysfs: cannot create duplicate filename '%s'\n",
-		     (path == NULL) ? sd->s_name :
-		     strcat(strcat(sysfs_pathname(parent_sd, path), "/"),
-		            sd->s_name));
-		kfree(path);
-		return -EEXIST;
-	}
+	result = -ENOENT;
+	if (parent_sd->s_flags & SYSFS_FLAG_REMOVED)
+		goto out_err;
+
+	if (sysfs_find_dirent(parent_sd, sd->s_name))
+		goto out_err;
 
 	sd->s_parent = sysfs_get(parent_sd);
 	sysfs_link_sibling(sd);
@@ -417,9 +413,22 @@ int sysfs_add_one(struct sysfs_dirent *parent_sd, struct sysfs_dirent *sd)
 	ps_iattr = parent_sd->s_iattr;
 	if (ps_iattr)
 		ps_iattr->ia_ctime = ps_iattr->ia_mtime = CURRENT_TIME;
-
 	mutex_unlock(&sysfs_mutex);
 	return 0;
+
+out_err:
+	mutex_unlock(&sysfs_mutex);
+
+	path = kzalloc(PATH_MAX, GFP_KERNEL);
+	WARN(1, KERN_WARNING "sysfs: cannot create '%s' %s\n",
+		(path == NULL) ? sd->s_name :
+		strcat(strcat(sysfs_pathname(parent_sd, path), "/"),
+		       sd->s_name),
+		(result == -EEXIST ? "duplicate filename" : "no such directory")
+		);
+	kfree(path);
+
+	return result;
 }
 
 /**
-- 
1.6.3.1.54.g99dd.dirty

--
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