Skip to content

Commit dfccfc4

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent 7d1032d commit dfccfc4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

net/core/bpf_sk_storage.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)
161161

162162
RCU_INIT_POINTER(newsk->sk_bpf_storage, NULL);
163163

164+
migrate_disable();
164165
rcu_read_lock();
165166
sk_storage = rcu_dereference(sk->sk_bpf_storage);
166167

@@ -213,6 +214,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)
213214

214215
out:
215216
rcu_read_unlock();
217+
migrate_enable();
216218

217219
/* In case of an error, don't free anything explicitly here, the
218220
* caller is responsible to call bpf_sk_storage_free.

0 commit comments

Comments
 (0)