Re: [PATCH bpf-next v3 1/5] net: Add __sys_connect_socket() helper

Song Liu <[email protected]> Tue, 4 Aug 2026 21:05:28 -0700
Newsgroups org.kernel.vger.bpf,org.kernel.vger.netdev
Message-ID <CAPhsuW5ZTqfzpxNf=S6JbmGxWf2m9qPZGberdzRdLuvv2-Xwgw@mail.gmail.com>
On Tue, Aug 4, 2026 at 9:47 AM Mahe Tardy <[email protected]> wrote:
>
> Add a helper that connects an existing socket while invoking the LSM
> hook. Reuse it in __sys_connect_file() to avoid duplicating the connect
> logic. Other socket operations have equivalent helpers that trigger the
> appropriate LSM hooks that can be reused, this one was the only one
> missing.
>
> Signed-off-by: Mahe Tardy <[email protected]>
> ---
>  include/linux/socket.h |  2 ++
>  net/socket.c           | 32 ++++++++++++++++++--------------
>  2 files changed, 20 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/socket.h b/include/linux/socket.h
> index 2a8d7b14f1d1..48f1eb8193de 100644
> --- a/include/linux/socket.h
> +++ b/include/linux/socket.h
> @@ -461,6 +461,8 @@ extern struct file *__sys_socket_file(int family, int type, int protocol);
>  extern int __sys_bind(int fd, struct sockaddr __user *umyaddr, int addrlen);
>  extern int __sys_bind_socket(struct socket *sock, struct sockaddr_storage *address,
>                              int addrlen);
> +extern int __sys_connect_socket(struct socket *sock, struct sockaddr_storage *addr,
> +                               int addrlen, int flags);

IIUC, __sys_ prefix is for functions behind syscalls. Do we really want this
prefix here?

Thanks,
Song

>  extern int __sys_connect_file(struct file *file, struct sockaddr_storage *addr,
>                               int addrlen, int file_flags);
>  extern int __sys_connect(int fd, struct sockaddr __user *uservaddr,
> diff --git a/net/socket.c b/net/socket.c
> index 63c69a0fa74e..c7427dd4dd52 100644
> --- a/net/socket.c
> +++ b/net/socket.c