fsi: i2cr-scom: Return -EFAULT on usercopy failures
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.
--- drivers/fsi/i2cr-scom.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/fsi/i2cr-scom.c +2 -2
@@ -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
Quoted 6 lines · Karl Mehltretter
copy_to_user()andcopy_from_user()return the number of bytes that were not copied.i2cr_scom_read()andi2cr_scom_write()return that value directly, so a usercopy fault is reported as a successful short I/O.Return
-EFAULTwhen 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 LLMSigned-off-by Karl Mehltretter <[email protected]>
A friendly ping on this usercopy error-handling fix.
Thanks,
Karl