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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230510153858.84877-1-kuniyu@amazon.com>
Date:   Wed, 10 May 2023 08:38:58 -0700
From:   Kuniyuki Iwashima <kuniyu@...zon.com>
To:     <aleksandr.mikhalitsyn@...onical.com>
CC:     <ast@...nel.org>, <bpf@...r.kernel.org>, <brauner@...nel.org>,
        <daniel@...earbox.net>, <davem@...emloft.net>,
        <edumazet@...gle.com>, <kuba@...nel.org>, <kuniyu@...zon.com>,
        <linux-kernel@...r.kernel.org>, <netdev@...r.kernel.org>,
        <pabeni@...hat.com>, <sdf@...gle.com>
Subject: Re: [PATCH net-next] net: core: add SOL_SOCKET filter for bpf getsockopt hook

From: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
Date: Wed, 10 May 2023 17:22:16 +0200
> We have per struct proto ->bpf_bypass_getsockopt callback
> to filter out bpf socket cgroup getsockopt hook from being called.
> 
> It seems worthwhile to add analogical helper for SOL_SOCKET
> level socket options. First user will be SO_PEERPIDFD.

I think this patch should be posted within the series below as
there is no real user of sock_bpf_bypass_getsockopt() for now.

Thanks,
Kuniyuki


> 
> This patch was born as a result of discussion around a new SCM_PIDFD interface:
> https://lore.kernel.org/all/20230413133355.350571-3-aleksandr.mikhalitsyn@canonical.com/
> 
> Cc: Alexei Starovoitov <ast@...nel.org>
> Cc: Daniel Borkmann <daniel@...earbox.net>
> Cc: Christian Brauner <brauner@...nel.org>
> Cc: Stanislav Fomichev <sdf@...gle.com>
> Cc: "David S. Miller" <davem@...emloft.net>
> Cc: Eric Dumazet <edumazet@...gle.com>
> Cc: Jakub Kicinski <kuba@...nel.org>
> Cc: Paolo Abeni <pabeni@...hat.com>
> Cc: Kuniyuki Iwashima <kuniyu@...zon.com>
> Cc: linux-kernel@...r.kernel.org
> Cc: netdev@...r.kernel.org
> Cc: bpf@...r.kernel.org
> Signed-off-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.com>
> ---
>  include/linux/bpf-cgroup.h | 8 +++++---
>  include/net/sock.h         | 1 +
>  net/core/sock.c            | 5 +++++
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h
> index 57e9e109257e..97d8a49b35bf 100644
> --- a/include/linux/bpf-cgroup.h
> +++ b/include/linux/bpf-cgroup.h
> @@ -387,10 +387,12 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk,
>  	int __ret = retval;						       \
>  	if (cgroup_bpf_enabled(CGROUP_GETSOCKOPT) &&			       \
>  	    cgroup_bpf_sock_enabled(sock, CGROUP_GETSOCKOPT))		       \
> -		if (!(sock)->sk_prot->bpf_bypass_getsockopt ||		       \
> -		    !INDIRECT_CALL_INET_1((sock)->sk_prot->bpf_bypass_getsockopt, \
> +		if (((level != SOL_SOCKET) ||				       \
> +		     !sock_bpf_bypass_getsockopt(level, optname)) &&	       \
> +		    (!(sock)->sk_prot->bpf_bypass_getsockopt ||		       \
> +		     !INDIRECT_CALL_INET_1((sock)->sk_prot->bpf_bypass_getsockopt, \
>  					tcp_bpf_bypass_getsockopt,	       \
> -					level, optname))		       \
> +					level, optname)))		       \
>  			__ret = __cgroup_bpf_run_filter_getsockopt(	       \
>  				sock, level, optname, optval, optlen,	       \
>  				max_optlen, retval);			       \
> diff --git a/include/net/sock.h b/include/net/sock.h
> index 8b7ed7167243..530d6d22f42d 100644
> --- a/include/net/sock.h
> +++ b/include/net/sock.h
> @@ -1847,6 +1847,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,
>  		  sockptr_t optval, sockptr_t optlen);
>  int sock_getsockopt(struct socket *sock, int level, int op,
>  		    char __user *optval, int __user *optlen);
> +bool sock_bpf_bypass_getsockopt(int level, int optname);
>  int sock_gettstamp(struct socket *sock, void __user *userstamp,
>  		   bool timeval, bool time32);
>  struct sk_buff *sock_alloc_send_pskb(struct sock *sk, unsigned long header_len,
> diff --git a/net/core/sock.c b/net/core/sock.c
> index 5440e67bcfe3..194a423eb6e5 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1963,6 +1963,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
>  			     USER_SOCKPTR(optlen));
>  }
>  
> +bool sock_bpf_bypass_getsockopt(int level, int optname)
> +{
> +	return false;
> +}
> +
>  /*
>   * Initialize an sk_lock.
>   *
> -- 
> 2.34.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ