Skip to contentSkip to conversation

fsi: i2cr-scom: Return -EFAULT on usercopy failures

PATCH In review Karl Mehltretter 1 participant 2 messages Sep 14 – Oct 15 FSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fsi: i2cr-scom: Return -EFAULT on usercopy failures

copy_to_user() and copy_from_user() return the number of bytes that were not copied. i2cr_scom_read() and i2cr_scom_write() return that value directly, so a usercopy fault is reported as a successful short I/O.

Return -EFAULT when either copy fails.

A temporary KUnit test called i2cr_scom_write() with an invalid user pointer. The unmodified kernel returned 8. With this change it returned -EFAULT. Both versions were booted under QEMU.

Fixes c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
Assisted-by LLM
---
 drivers/fsi/i2cr-scom.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fsi/i2cr-scom.c +2 -2
index 83b3c03..7edd3e5 100644
@@ -46,7 +46,7 @@ static ssize_t i2cr_scom_read(struct file *filep, char __user *buf, size_t len,
 
 	ret = copy_to_user(buf, &data, len);
 	if (ret)
-		return ret;
+		return -EFAULT;
 
 	return len;
 }
@@ -63,7 +63,7 @@ static ssize_t i2cr_scom_write(struct file *filep, const char __user *buf, size_
 
 	ret = copy_from_user(&data, buf, len);
 	if (ret)
-		return ret;
+		return -EFAULT;
 
 	ret = fsi_master_i2cr_write(scom->i2cr, (u32)*offset, data);
 	if (ret)

base-commit: 22098763a10d9c1340827fcf6edab66f153b27f0

Signature · 1 line
2.53.0
#1 lore raw
Quoted 6 lines · Karl Mehltretter

copy_to_user() and copy_from_user() return the number of bytes that were not copied. i2cr_scom_read() and i2cr_scom_write() return that value directly, so a usercopy fault is reported as a successful short I/O.

Return -EFAULT when either copy fails.

Quoted 7 lines

A temporary KUnit test called i2cr_scom_write() with an invalid user pointer. The unmodified kernel returned 8. With this change it returned -EFAULT. Both versions were booted under QEMU.

Fixes c0b34bed0bbf ("fsi: Add I2C Responder SCOM driver")
Assisted-by LLM

A friendly ping on this usercopy error-handling fix.

Thanks,
Karl