Skip to contentSkip to conversation

eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write()

PATCH Superseded Dan Carpenter 2 participants 3 messages Jul 6, 2022 – Jul 7, 2022

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eeprom: idt_89hpesx: uninitialized data in idt_dbgfs_csr_write()

The simple_write_to_buffer() here is used to copy a string from the user. However the function call will succeed if it manages to read just one byte anywhere within the buffer while we need the whole string to be initialized to avoid using uninitialized data.

Fixes cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")
---
 drivers/misc/eeprom/idt_89hpesx.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
drivers/misc/eeprom/idt_89hpesx.c +6 -8
index b0cff4b152da..30e146b32205 100644
@@ -909,15 +909,13 @@ static ssize_t idt_dbgfs_csr_write(struct file *filep, const char __user *ubuf,
 	u32 csraddr, csrval;
 	char *buf;
 
-	/* Copy data from User-space */
-	buf = kmalloc(count + 1, GFP_KERNEL);
-	if (!buf)
-		return -ENOMEM;
+	if (*offp != 0)
+		return -EINVAL;
 
-	ret = simple_write_to_buffer(buf, count, offp, ubuf, count);
-	if (ret < 0)
-		goto free_buf;
-	buf[count] = 0;
+	/* Copy data from User-space */
+	buf = strndup_user(ubuf, count + 1);
+	if (IS_ERR(buf))
+		return PTR_ERR(buf);
 
 	/* Find position of colon in the buffer */
 	colon_ch = strnchr(buf, count, ':');
Signature · 1 line
2.35.1
#1 lore raw
Quoted 8 lines · Dan Carpenter

The simple_write_to_buffer() here is used to copy a string from the user. However the function call will succeed if it manages to read just one byte anywhere within the buffer while we need the whole string to be initialized to avoid using uninitialized data.

Fixes cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")

---

NAK. The strndup_user() function is too strict. I will resend this using memdup_user() instead.

regards,
dan carpenter

#2 lore raw

Hi Dan

Quoted 6 lines · Dan Carpenter
Quoted 5 lines · Dan Carpenter

The simple_write_to_buffer() here is used to copy a string from the user. However the function call will succeed if it manages to read just one byte anywhere within the buffer while we need the whole string to be initialized to avoid using uninitialized data.

Quoted 6 lines
Quoted 3 lines
Fixes cfad6425382e ("eeprom: Add IDT 89HPESx EEPROM/CSR driver")

---

NAK. The strndup_user() function is too strict. I will resend this using memdup_user() instead.

Thanks for the patch. Ok. I'll wait for v2 to review.

-Sergey

Quoted 4 lines

regards,
dan carpenter