lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAAVpQUAPrmDH6-ZiEioJ_sohbQ-kBu1MFBssPVzY34FRnsnz0w@mail.gmail.com>
Date: Fri, 21 Nov 2025 18:15:50 -0800
From: Kuniyuki Iwashima <kuniyu@...gle.com>
To: Gabriel Krisman Bertazi <krisman@...e.de>
Cc: Jens Axboe <axboe@...nel.dk>, 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>, Paolo Abeni <pabeni@...hat.com>, 
	Willem de Bruijn <willemb@...gle.com>, Simon Horman <horms@...nel.org>
Subject: Re: [PATCH v2 2/3] socket: Split out a getsockname helper for io_uring

On Fri, Nov 21, 2025 at 8:10 AM Gabriel Krisman Bertazi <krisman@...e.de> wrote:
>
> 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>
> ---
>  include/linux/socket.h |  2 ++
>  net/socket.c           | 34 +++++++++++++++++++---------------
>  2 files changed, 21 insertions(+), 15 deletions(-)
>
> diff --git a/include/linux/socket.h b/include/linux/socket.h
> index 937fe331ff1e..5afb5ef2990c 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, struct sockaddr_storage *address,
> +                         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 ee438b9425da..9c110b529cdd 100644
> --- a/net/socket.c
> +++ b/net/socket.c
> @@ -2127,6 +2127,24 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
>         return __sys_connect(fd, uservaddr, addrlen);
>  }
>
> +int do_getsockname(struct socket *sock, struct sockaddr_storage *address, int peer,
> +                  struct sockaddr __user *usockaddr, int __user *usockaddr_len)
> +{
> +       int err;
> +
> +       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 address (remote or local ('name')) of a socket object. Move the
>   *     obtained name to user space.
> @@ -2137,27 +2155,13 @@ int __sys_getsockname(int fd, struct sockaddr __user *usockaddr,
>         struct socket *sock;
>         struct sockaddr_storage address;

Could you move this to do_getsockname() ?

The patch 3 also does not need to define it.


>         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);
> +       return do_getsockname(sock, &address, peer, usockaddr, usockaddr_len);
>  }
>
>  SYSCALL_DEFINE3(getsockname, int, fd, struct sockaddr __user *, usockaddr,
> --
> 2.51.0
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ