Skip to content

Commit 651eaa3

Browse files
wangyufen316EvilAnsh
authored andcommitted
UPSTREAM: bpf, sockmap: Fix sk->sk_forward_alloc warn_on in sk_stream_kill_queues
commit d8616ee2affcff37c5d315310da557a694a3303d upstream. During TCP sockmap redirect pressure test, the following warning is triggered: WARNING: CPU: 3 PID: 2145 at net/core/stream.c:205 sk_stream_kill_queues+0xbc/0xd0 CPU: 3 PID: 2145 Comm: iperf Kdump: loaded Tainted: G W 5.10.0+ realme-mt6785-devs#9 Call Trace: inet_csk_destroy_sock+0x55/0x110 inet_csk_listen_stop+0xbb/0x380 tcp_close+0x41b/0x480 inet_release+0x42/0x80 __sock_release+0x3d/0xa0 sock_close+0x11/0x20 __fput+0x9d/0x240 task_work_run+0x62/0x90 exit_to_user_mode_prepare+0x110/0x120 syscall_exit_to_user_mode+0x27/0x190 entry_SYSCALL_64_after_hwframe+0x44/0xa9 The reason we observed is that: When the listener is closing, a connection may have completed the three-way handshake but not accepted, and the client has sent some packets. The child sks in accept queue release by inet_child_forget()->inet_csk_destroy_sock(), but psocks of child sks have not released. To fix, add sock_map_destroy to release psocks. Change-Id: I418e71cc25b80e143b963c2ef855b3063191989f Signed-off-by: Wang Yufen <wangyufen@huawei.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Acked-by: Jakub Sitnicki <jakub@cloudflare.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20220524075311.649153-1-wangyufen@huawei.com [ Conflict in include/linux/bpf.h due to function declaration position and remove non-existed sk_psock_stop helper from sock_map_destroy. ] Signed-off-by: Wen Gu <guwen@linux.alibaba.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Naveen <133593113+elohim-etz@users.noreply.github.com>
1 parent dc009e0 commit 651eaa3

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

include/linux/bpf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,7 @@ int sock_map_get_from_fd(const union bpf_attr *attr, struct bpf_prog *prog);
17661766
int sock_map_prog_detach(const union bpf_attr *attr, enum bpf_prog_type ptype);
17671767
int sock_map_update_elem_sys(struct bpf_map *map, void *key, void *value, u64 flags);
17681768
void sock_map_unhash(struct sock *sk);
1769+
void sock_map_destroy(struct sock *sk);
17691770
void sock_map_close(struct sock *sk, long timeout);
17701771
#else
17711772
static inline int sock_map_prog_update(struct bpf_map *map,

include/linux/skmsg.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ struct sk_psock {
9898
spinlock_t link_lock;
9999
refcount_t refcnt;
100100
void (*saved_unhash)(struct sock *sk);
101+
void (*saved_destroy)(struct sock *sk);
101102
void (*saved_close)(struct sock *sk, long timeout);
102103
void (*saved_write_space)(struct sock *sk);
103104
struct proto *sk_proto;

net/core/skmsg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@ struct sk_psock *sk_psock_init(struct sock *sk, int node)
490490

491491
psock->sk = sk;
492492
psock->eval = __SK_NONE;
493+
psock->saved_destroy = prot->destroy;
493494

494495
INIT_LIST_HEAD(&psock->link);
495496
spin_lock_init(&psock->link_lock);

net/core/sock_map.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,28 @@ void sock_map_unhash(struct sock *sk)
12411241
saved_unhash(sk);
12421242
}
12431243

1244+
void sock_map_destroy(struct sock *sk)
1245+
{
1246+
void (*saved_destroy)(struct sock *sk);
1247+
struct sk_psock *psock;
1248+
1249+
rcu_read_lock();
1250+
psock = sk_psock_get(sk);
1251+
if (unlikely(!psock)) {
1252+
rcu_read_unlock();
1253+
if (sk->sk_prot->destroy)
1254+
sk->sk_prot->destroy(sk);
1255+
return;
1256+
}
1257+
1258+
saved_destroy = psock->saved_destroy;
1259+
sock_map_remove_links(sk, psock);
1260+
rcu_read_unlock();
1261+
sk_psock_put(sk, psock);
1262+
saved_destroy(sk);
1263+
}
1264+
EXPORT_SYMBOL_GPL(sock_map_destroy);
1265+
12441266
void sock_map_close(struct sock *sk, long timeout)
12451267
{
12461268
void (*saved_close)(struct sock *sk, long timeout);

net/ipv4/tcp_bpf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,7 @@ static void tcp_bpf_rebuild_protos(struct proto prot[TCP_BPF_NUM_CFGS],
545545
{
546546
prot[TCP_BPF_BASE] = *base;
547547
prot[TCP_BPF_BASE].unhash = sock_map_unhash;
548+
prot[TCP_BPF_BASE].destroy = sock_map_destroy;
548549
prot[TCP_BPF_BASE].close = sock_map_close;
549550
prot[TCP_BPF_BASE].recvmsg = tcp_bpf_recvmsg;
550551
prot[TCP_BPF_BASE].stream_memory_read = tcp_bpf_stream_read;

0 commit comments

Comments
 (0)