From 052e796c33523c1a4bfba56f12d3b7857a42af89 Mon Sep 17 00:00:00 2001 From: Jiri Slaby Date: Apr 20 2023 11:00:22 +0000 Subject: bpf: tcp: Use sock_gen_put instead of sock_put in bpf_iter_tcp (bsc#1012628). --- diff --git a/patches.kernel.org/6.2.12-042-bpf-tcp-Use-sock_gen_put-instead-of-sock_put-i.patch b/patches.kernel.org/6.2.12-042-bpf-tcp-Use-sock_gen_put-instead-of-sock_put-i.patch new file mode 100644 index 0000000..ef32ef9 --- /dev/null +++ b/patches.kernel.org/6.2.12-042-bpf-tcp-Use-sock_gen_put-instead-of-sock_put-i.patch @@ -0,0 +1,51 @@ +From: Martin KaFai Lau +Date: Mon, 27 Mar 2023 17:42:32 -0700 +Subject: [PATCH] bpf: tcp: Use sock_gen_put instead of sock_put in + bpf_iter_tcp +References: bsc#1012628 +Patch-mainline: 6.2.12 +Git-commit: 580031ff9952b7dbf48dedba6b56a100ae002bef + +[ Upstream commit 580031ff9952b7dbf48dedba6b56a100ae002bef ] + +While reviewing the udp-iter batching patches, noticed the bpf_iter_tcp +calling sock_put() is incorrect. It should call sock_gen_put instead +because bpf_iter_tcp is iterating the ehash table which has the req sk +and tw sk. This patch replaces all sock_put with sock_gen_put in the +bpf_iter_tcp codepath. + +Fixes: 04c7820b776f ("bpf: tcp: Bpf iter batching and lock_sock") +Signed-off-by: Martin KaFai Lau +Signed-off-by: Daniel Borkmann +Link: https://lore.kernel.org/bpf/20230328004232.2134233-1-martin.lau@linux.dev +Signed-off-by: Sasha Levin +Signed-off-by: Jiri Slaby +--- + net/ipv4/tcp_ipv4.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c +index 8320d0ec..339a9cea 100644 +--- a/net/ipv4/tcp_ipv4.c ++++ b/net/ipv4/tcp_ipv4.c +@@ -2779,7 +2779,7 @@ static int tcp_prog_seq_show(struct bpf_prog *prog, struct bpf_iter_meta *meta, + static void bpf_iter_tcp_put_batch(struct bpf_tcp_iter_state *iter) + { + while (iter->cur_sk < iter->end_sk) +- sock_put(iter->batch[iter->cur_sk++]); ++ sock_gen_put(iter->batch[iter->cur_sk++]); + } + + static int bpf_iter_tcp_realloc_batch(struct bpf_tcp_iter_state *iter, +@@ -2940,7 +2940,7 @@ static void *bpf_iter_tcp_seq_next(struct seq_file *seq, void *v, loff_t *pos) + * st->bucket. See tcp_seek_last_pos(). + */ + st->offset++; +- sock_put(iter->batch[iter->cur_sk++]); ++ sock_gen_put(iter->batch[iter->cur_sk++]); + } + + if (iter->cur_sk < iter->end_sk) +-- +2.35.3 + diff --git a/series.conf b/series.conf index b46dcbf..932551f 100644 --- a/series.conf +++ b/series.conf @@ -2269,6 +2269,7 @@ patches.kernel.org/6.2.12-039-RDMA-erdma-Defer-probing-if-netdevice-can-not-.patch patches.kernel.org/6.2.12-040-clk-rs9-Fix-suspend-resume.patch patches.kernel.org/6.2.12-041-RDMA-cma-Allow-UD-qp_type-to-join-multicast-on.patch + patches.kernel.org/6.2.12-042-bpf-tcp-Use-sock_gen_put-instead-of-sock_put-i.patch ######################################################## # Build fixes that apply to the vanilla kernel too.