From: Hou Tao Date: Wed, 8 Jan 2025 01:07:20 +0000 (+0800) Subject: bpf: Disable migration when cloning sock storage X-Git-Tag: v6.14-rc1~133^2~18^2~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dfccfc47bde53f5df5bf42486d12a8a2ecdcea60;p=thirdparty%2Flinux.git bpf: Disable migration when cloning sock storage bpf_sk_storage_clone() will call bpf_selem_free() to free the clone element when the allocation of new sock storage fails. bpf_selem_free() will call check_and_free_fields() to free the special fields in the element. Since the allocated element is not visible to bpf syscall or bpf program when bpf_local_storage_alloc() fails, these special fields in the element must be all zero when invoking bpf_selem_free(). To be uniform with other callers of bpf_selem_free(), disabling migration when cloning sock storage. Adding migrate_{disable|enable} pair also benefits the potential switching from kzalloc to bpf memory allocator for sock storage. Signed-off-by: Hou Tao Link: https://lore.kernel.org/r/20250108010728.207536-9-houtao@huaweicloud.com Signed-off-by: Alexei Starovoitov --- diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index aa536ecd5d390..7d41cde1bcca6 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -161,6 +161,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk) RCU_INIT_POINTER(newsk->sk_bpf_storage, NULL); + migrate_disable(); rcu_read_lock(); sk_storage = rcu_dereference(sk->sk_bpf_storage); @@ -213,6 +214,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk) out: rcu_read_unlock(); + migrate_enable(); /* In case of an error, don't free anything explicitly here, the * caller is responsible to call bpf_sk_storage_free.