[PATCH 2/4] sparc: led: reject zero-length proc writes

Pengpeng Hou <[email protected]>
Newsgroups gmane.linux.ports.sparc,gmane.linux.kernel
Message-ID <[email protected]>
led_proc_write() passes count straight through memdup_user_nul() and then
unconditionally inspects buf[count - 1] to strip a trailing newline. A
zero-length write therefore dereferences one byte before the allocated
buffer.

Reject empty writes before touching buf[count - 1].

Fixes: ee1858d3122d ("[SPARC]: Add sun4m LED driver.")
Signed-off-by: Pengpeng Hou <[email protected]>
---
 arch/sparc/kernel/led.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/arch/sparc/kernel/led.c b/arch/sparc/kernel/led.c
index f4fb82b019bb..b9758fdbc054 100644
--- a/arch/sparc/kernel/led.c
+++ b/arch/sparc/kernel/led.c
@@ -70,6 +70,9 @@ static ssize_t led_proc_write(struct file *file, const char __user *buffer,
 {
 	char *buf = NULL;
 
+	if (!count)
+		return -EINVAL;
+
 	if (count > LED_MAX_LENGTH)
 		count = LED_MAX_LENGTH;
 
-- 
2.50.1 (Apple Git-155)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.