[PATCH net-next] net: Convert move_addr_to_user() to scoped user access

Christophe Leroy (CS GROUP) posted 1 patch 4 weeks, 1 day ago
net/socket.c | 28 +++++++++++-----------------
1 file changed, 11 insertions(+), 17 deletions(-)
[PATCH net-next] net: Convert move_addr_to_user() to scoped user access
Posted by Christophe Leroy (CS GROUP) 4 weeks, 1 day ago
move_addr_to_user() is a critical functions that was converted to
masked user access by commit 1fb0e471611d ("net: remove one stac/clac
pair from move_addr_to_user()")

Convert it to scoped user access to simplify the code.

Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
---
 net/socket.c | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)

diff --git a/net/socket.c b/net/socket.c
index 05952188127f..66eaf6d59941 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -280,23 +280,18 @@ static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
 
 	BUG_ON(klen > sizeof(struct sockaddr_storage));
 
-	if (can_do_masked_user_access())
-		ulen = masked_user_access_begin(ulen);
-	else if (!user_access_begin(ulen, 4))
-		return -EFAULT;
-
-	unsafe_get_user(len, ulen, efault_end);
-
-	if (len > klen)
-		len = klen;
-	/*
-	 *      "fromlen shall refer to the value before truncation.."
-	 *                      1003.1g
-	 */
-	if (len >= 0)
-		unsafe_put_user(klen, ulen, efault_end);
+	scoped_user_rw_access_size(ulen, 4, efault_end) {
+		unsafe_get_user(len, ulen, efault_end);
 
-	user_access_end();
+		if (len > klen)
+			len = klen;
+		/*
+		 *      "fromlen shall refer to the value before truncation.."
+		 *                      1003.1g
+		 */
+		if (len >= 0)
+			unsafe_put_user(klen, ulen, efault_end);
+	}
 
 	if (len) {
 		if (len < 0)
@@ -309,7 +304,6 @@ static int move_addr_to_user(struct sockaddr_storage *kaddr, int klen,
 	return 0;
 
 efault_end:
-	user_access_end();
 	return -EFAULT;
 }
 
-- 
2.49.0
Re: [PATCH net-next] net: Convert move_addr_to_user() to scoped user access
Posted by Eric Dumazet 4 weeks ago
On Tue, Mar 10, 2026 at 12:33 PM Christophe Leroy (CS GROUP)
<chleroy@kernel.org> wrote:
>
> move_addr_to_user() is a critical functions that was converted to
> masked user access by commit 1fb0e471611d ("net: remove one stac/clac
> pair from move_addr_to_user()")
>
> Convert it to scoped user access to simplify the code.
>
> Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
> Cc: Eric Dumazet <edumazet@google.com>

Reviewed-by: Eric Dumazet <edumazet@google.com>