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]
Message-ID: <48B6D2C6.4010703@kernel.org>
Date:	Thu, 28 Aug 2008 18:31:02 +0200
From:	Tejun Heo <tj@...nel.org>
To:	Greg KH <greg@...ah.com>,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>
Subject: [PATCH 2/2] uevent: handle duplicate uevent_var keys properly

add_uevent_var() appends the specified variable whether the new entry
has duplicate key or not.  This patch makes add_uevent_var() to
override the existing entry if an entry with the same key is added
later.  This will be used by CUSE (character device in userland) to
fake hotplug events.

Signed-off-by: Tejun Heo <tj@...nel.org>
---
 lib/kobject_uevent.c |   33 ++++++++++++++++++++++-----------
 1 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c
index ca215bc..64b1aaf 100644
--- a/lib/kobject_uevent.c
+++ b/lib/kobject_uevent.c
@@ -281,27 +281,38 @@ EXPORT_SYMBOL_GPL(kobject_uevent);
  */
 int add_uevent_var(struct kobj_uevent_env *env, const char *format, ...)
 {
+	char *buf = &env->buf[env->buflen];
+	size_t avail = sizeof(env->buf) - env->buflen;
 	va_list args;
-	int len;
+	int i, len, key_len;
 
-	if (env->envp_idx >= ARRAY_SIZE(env->envp)) {
-		WARN(1, KERN_ERR "add_uevent_var: too many keys\n");
+	va_start(args, format);
+	len = vsnprintf(buf, avail, format, args);
+	va_end(args);
+
+	if (len >= avail) {
+		printk(KERN_ERR "add_uevent_var: buffer size too small\n");
+		WARN_ON(1);
 		return -ENOMEM;
 	}
 
-	va_start(args, format);
-	len = vsnprintf(&env->buf[env->buflen],
-			sizeof(env->buf) - env->buflen,
-			format, args);
-	va_end(args);
+	key_len = strchr(buf, '=') - buf;
+
+	for (i = 0; i < env->envp_idx; i++)
+		if (key_len == strchr(env->envp[i], '=') - env->envp[i] &&
+		    !strncmp(buf, env->envp[i], key_len))
+			break;
 
-	if (len >= (sizeof(env->buf) - env->buflen)) {
-		WARN(1, KERN_ERR "add_uevent_var: buffer size too small\n");
+	if (i >= ARRAY_SIZE(env->envp)) {
+		printk(KERN_ERR "add_uevent_var: too many keys\n");
+		WARN_ON(1);
 		return -ENOMEM;
 	}
 
-	env->envp[env->envp_idx++] = &env->buf[env->buflen];
+	env->envp[i] = &env->buf[env->buflen];
 	env->buflen += len + 1;
+	if (i == env->envp_idx)
+		env->envp_idx++;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(add_uevent_var);
-- 
1.5.4.5

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