Skip to contentSkip to conversation

fs: Return -EFAULT if copy_to_user() fails

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

lore
Share & tools
lore

Wang Qing

author
#0 lore raw

PATCH 1/1 fs: 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.

---
 fs/select.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/select.c +1 -1
index 37aaa83..93cd35b
@@ -400,7 +400,7 @@ static inline unsigned long __must_check
 set_fd_set(unsigned long nr, void __user *ufdset, unsigned long *fdset)
 {
 	if (ufdset)
-		return __copy_to_user(ufdset, fdset, FDS_BYTES(nr));
+		return __copy_to_user(ufdset, fdset, FDS_BYTES(nr)) ? -EFAULT : 0;
 	return 0;
 }
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 2 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.

... which is done by the only caller.

        if (set_fd_set(n, inp, fds.res_in) ||
            set_fd_set(n, outp, fds.res_out) ||
            set_fd_set(n, exp, fds.res_ex))
                ret = -EFAULT;