[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251125211806.2673912-3-krisman@suse.de>
Date: Tue, 25 Nov 2025 16:18:00 -0500
From: Gabriel Krisman Bertazi <krisman@...e.de>
To: Jens Axboe <axboe@...nel.dk>
Cc: Gabriel Krisman Bertazi <krisman@...e.de>,
netdev@...r.kernel.org,
io-uring@...r.kernel.org,
Jakub Kicinski <kuba@...nel.org>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Kuniyuki Iwashima <kuniyu@...gle.com>,
Paolo Abeni <pabeni@...hat.com>,
Willem de Bruijn <willemb@...gle.com>,
Simon Horman <horms@...nel.org>
Subject: [PATCH v4 2/3] socket: Split out a getsockname helper for io_uring
Similar to getsockopt, split out a helper to check security and issue
the operation from the main handler that can be used by io_uring.
Signed-off-by: Gabriel Krisman Bertazi <krisman@...e.de>
---
v2 -> v3:
- Move sockaddr_storage parameter into do_getsockname(Kuniyuki)
---
include/linux/socket.h | 2 ++
net/socket.c | 36 ++++++++++++++++++++----------------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/include/linux/socket.h b/include/linux/socket.h
index 937fe331ff1e..8d580074ddea 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -453,6 +453,8 @@ extern int __sys_connect(int fd, struct sockaddr __user *uservaddr,
int addrlen);
extern int __sys_listen(int fd, int backlog);
extern int __sys_listen_socket(struct socket *sock, int backlog);
+extern int do_getsockname(struct socket *sock, int peer,
+ struct sockaddr __user *usockaddr, int __user *usockaddr_len);
extern int __sys_getsockname(int fd, struct sockaddr __user *usockaddr,
int __user *usockaddr_len, int peer);
extern int __sys_socketpair(int family, int type, int protocol,
diff --git a/net/socket.c b/net/socket.c
index 208d92ccf0fb..89bac0a17e5a 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -2127,39 +2127,43 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
return __sys_connect(fd, uservaddr, addrlen);
}
-/*
- * Get the remote or local address ('name') of a socket object. Move the
- * obtained name to user space.
- */
-int __sys_getsockname(int fd, struct sockaddr __user *usockaddr,
- int __user *usockaddr_len, int peer)
+int do_getsockname(struct socket *sock, int peer,
+ struct sockaddr __user *usockaddr, int __user *usockaddr_len)
{
- struct socket *sock;
struct sockaddr_storage address;
- CLASS(fd, f)(fd);
int err;
- if (fd_empty(f))
- return -EBADF;
- sock = sock_from_file(fd_file(f));
- if (unlikely(!sock))
- return -ENOTSOCK;
-
if (peer)
err = security_socket_getpeername(sock);
else
err = security_socket_getsockname(sock);
if (err)
return err;
-
err = READ_ONCE(sock->ops)->getname(sock, (struct sockaddr *)&address, peer);
if (err < 0)
return err;
-
/* "err" is actually length in this case */
return move_addr_to_user(&address, err, usockaddr, usockaddr_len);
}
+/*
+ * Get the remote or local address ('name') of a socket object. Move the
+ * obtained name to user space.
+ */
+int __sys_getsockname(int fd, struct sockaddr __user *usockaddr,
+ int __user *usockaddr_len, int peer)
+{
+ struct socket *sock;
+ CLASS(fd, f)(fd);
+
+ if (fd_empty(f))
+ return -EBADF;
+ sock = sock_from_file(fd_file(f));
+ if (unlikely(!sock))
+ return -ENOTSOCK;
+ return do_getsockname(sock, peer, usockaddr, usockaddr_len);
+}
+
SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,
int __user *, usockaddr_len)
{
--
2.51.0
Powered by blists - more mailing lists