Skip to contentSkip to conversation

kernel: Return -EFAULT if copy_to_user() fails

PATCH In review Wang Qing 2 participants 2 messages Mar 1, 2021

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

PATCH 1/1 kernel: Return -EFAULT if copy_to_user() fails

The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete.

---
 kernel/sys.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/sys.c +1 -1
index 8bb46e5..d97a84a
@@ -1247,7 +1247,7 @@ static int override_release(char __user *release, size_t len)
 		copy = scnprintf(buf, copy, "2.6.%u%s", v, rest);
 		ret = copy_to_user(release, buf, copy + 1);
 	}
-	return ret;
+	return ret ? -EFAULT : 0;
 }
 
 SYSCALL_DEFINE1(newuname, struct new_utsname __user *, name)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 5 lines · Wang Qing

The copy_to_user() function returns the number of bytes remaining to be copied, but we want to return -EFAULT if the copy doesn't complete.

---

Hey Wang,

Thanks for the patch. It looks like override_release() is called in three places and all three places return -EFAULT correctly. They simply treat any as EFAULT. So not sure this change buys us anything.

Christian