On 8/28/25 6:00 PM, Kuniyuki Iwashima wrote:
static int sol_socket_sockopt(struct sock *sk, int optname,
char *optval, int *optlen,
bool getopt)
@@ -5284,6 +5313,7 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
case SO_BINDTOIFINDEX:
case SO_TXREHASH:
case SK_BPF_CB_FLAGS:
+ case SK_BPF_MEMCG_FLAGS:
if (*optlen != sizeof(int))
return -EINVAL;
break;
@@ -5293,8 +5323,15 @@ static int sol_socket_sockopt(struct sock *sk, int optname,
return -EINVAL;
}
- if (optname == SK_BPF_CB_FLAGS)
+ switch (optname) {
+ case SK_BPF_CB_FLAGS:
return sk_bpf_set_get_cb_flags(sk, optval, getopt);
+ case SK_BPF_MEMCG_FLAGS:
I would remove the getsockopt only support from the other hooks that cannot do
the setsockopt. There are other ways for them to read sk->sk_memcg if it is
really needed.
+ if (!IS_ENABLED(CONFIG_MEMCG) || !getopt)
+ return -EOPNOTSUPP;
+
+ return sk_bpf_get_memcg_flags(sk, optval);
Instead, do this only in bpf_sock_create_getsockopt.