Skip to contentSkip to conversation

kernel/kexec.c: use vscnprintf() instead of vsnprintf() in vmcoreinfo_append_str()

PATCH New Chen Gang 1 participant 2 messages Oct 9, 2013

Subsystems (4)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 kernel/kexec.c: use vscnprintf() instead of vsnprintf() in vmcoreinfo_append_str()

vsnprintf() may let 'r' larger than sizeof(buf), in this case, if 'r' is also less than "vmcoreinfo_max_size - vmcoreinfo_size" (left size of destination buffer), next memcpy() will read the unexpected addresses.

---
 kernel/kexec.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/kexec.c +1 -1
index 2a74f30..0abcd68 100644
@@ -1533,7 +1533,7 @@ void vmcoreinfo_append_str(const char *fmt, ...)
 	size_t r;
 
 	va_start(args, fmt);
-	r = vsnprintf(buf, sizeof(buf), fmt, args);
+	r = vscnprintf(buf, sizeof(buf), fmt, args);
 	va_end(args);
 
 	r = min(r, vmcoreinfo_max_size - vmcoreinfo_size);
Signature · 1 line
1.7.7.6
author
#1 lore raw

PATCH 1/1 kernel/sysctl_binary.c: use scnprintf() instead of snprintf()

snprintf() will return the 'ideal' length which may be larger than real buffer length, if we only want to use real length, need use scnprintf() instead of.

---
 kernel/sysctl_binary.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
kernel/sysctl_binary.c +3 -3
index b609213..653cbbd 100644
@@ -1024,7 +1024,7 @@ static ssize_t bin_intvec(struct file *file,
 			if (get_user(value, vec + i))
 				goto out_kfree;
 
-			str += snprintf(str, end - str, "%lu\t", value);
+			str += scnprintf(str, end - str, "%lu\t", value);
 		}
 
 		result = kernel_write(file, buffer, str - buffer, 0);
@@ -1095,7 +1095,7 @@ static ssize_t bin_ulongvec(struct file *file,
 			if (get_user(value, vec + i))
 				goto out_kfree;
 
-			str += snprintf(str, end - str, "%lu\t", value);
+			str += scnprintf(str, end - str, "%lu\t", value);
 		}
 
 		result = kernel_write(file, buffer, str - buffer, 0);
@@ -1205,7 +1205,7 @@ static ssize_t bin_dn_node_address(struct file *file,
 		if (get_user(dnaddr, (__le16 __user *)newval))
 			goto out;
 
-		len = snprintf(buf, sizeof(buf), "%hu.%hu",
+		len = scnprintf(buf, sizeof(buf), "%hu.%hu",
 				le16_to_cpu(dnaddr) >> 10,
 				le16_to_cpu(dnaddr) & 0x3ff);
 
Signature · 1 line
1.7.7.6