Should the return value of the copy_from_sockptr be checked?

Qianqiang Liu posted 1 patch 2 months, 2 weeks ago
Should the return value of the copy_from_sockptr be checked?
Posted by Qianqiang Liu 2 months, 2 weeks ago
Hi,

Should the return value of the copy_from_sockptr in net/socket.c be checked?
The following patch may solve this problem:

diff --git a/net/socket.c b/net/socket.c
index 0a2bd22ec105..6b9a414d01d5 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2370,8 +2370,11 @@ int do_sock_getsockopt(struct socket *sock, bool compat, int level,
 	if (err)
 		return err;
 
-	if (!compat)
-		copy_from_sockptr(&max_optlen, optlen, sizeof(int));
+	if (!compat) {
+		err = copy_from_sockptr(&max_optlen, optlen, sizeof(int));
+		if (err)
+			return -EFAULT;
+	}
 
 	ops = READ_ONCE(sock->ops);
 	if (level == SOL_SOCKET) {

-- 
Best,
Qianqiang Liu
Re: Should the return value of the copy_from_sockptr be checked?
Posted by Cong Wang 2 months, 2 weeks ago
On Wed, Sep 11, 2024 at 11:18:00AM +0800, Qianqiang Liu wrote:
> Hi,
> 
> Should the return value of the copy_from_sockptr in net/socket.c be checked?
> The following patch may solve this problem:

Yes, please submit a formal patch.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html

Thanks.