Commit d0a3b3d
bpf: Fix bpf_sk_select_reuseport() memory leak
[ Upstream commit b3af609 ]
As pointed out in the original comment, lookup in sockmap can return a TCP
ESTABLISHED socket. Such TCP socket may have had SO_ATTACH_REUSEPORT_EBPF
set before it was ESTABLISHED. In other words, a non-NULL sk_reuseport_cb
does not imply a non-refcounted socket.
Drop sk's reference in both error paths.
unreferenced object 0xffff888101911800 (size 2048):
comm "test_progs", pid 44109, jiffies 4297131437
hex dump (first 32 bytes):
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
80 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace (crc 9336483b):
__kmalloc_noprof+0x3bf/0x560
__reuseport_alloc+0x1d/0x40
reuseport_alloc+0xca/0x150
reuseport_attach_prog+0x87/0x140
sk_reuseport_attach_bpf+0xc8/0x100
sk_setsockopt+0x1181/0x1990
do_sock_setsockopt+0x12b/0x160
__sys_setsockopt+0x7b/0xc0
__x64_sys_setsockopt+0x1b/0x30
do_syscall_64+0x93/0x180
entry_SYSCALL_64_after_hwframe+0x76/0x7e
Fixes: 64d8529 ("bpf: Allow bpf_map_lookup_elem for SOCKMAP and SOCKHASH")
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Martin KaFai Lau <martin.lau@kernel.org>
Link: https://patch.msgid.link/20250110-reuseport-memleak-v1-1-fa1ddab0adfe@rbox.co
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>1 parent 0752481 commit d0a3b3d
1 file changed
Lines changed: 18 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11109 | 11109 | | |
11110 | 11110 | | |
11111 | 11111 | | |
| 11112 | + | |
11112 | 11113 | | |
11113 | 11114 | | |
11114 | 11115 | | |
11115 | 11116 | | |
11116 | 11117 | | |
11117 | 11118 | | |
11118 | 11119 | | |
11119 | | - | |
11120 | | - | |
11121 | | - | |
11122 | | - | |
11123 | 11120 | | |
11124 | 11121 | | |
11125 | 11122 | | |
11126 | 11123 | | |
11127 | 11124 | | |
11128 | 11125 | | |
11129 | 11126 | | |
11130 | | - | |
| 11127 | + | |
| 11128 | + | |
11131 | 11129 | | |
11132 | 11130 | | |
11133 | 11131 | | |
11134 | 11132 | | |
11135 | 11133 | | |
11136 | | - | |
11137 | | - | |
11138 | | - | |
11139 | | - | |
11140 | | - | |
11141 | | - | |
11142 | | - | |
| 11134 | + | |
| 11135 | + | |
| 11136 | + | |
| 11137 | + | |
| 11138 | + | |
| 11139 | + | |
| 11140 | + | |
| 11141 | + | |
| 11142 | + | |
11143 | 11143 | | |
11144 | 11144 | | |
11145 | 11145 | | |
11146 | 11146 | | |
11147 | 11147 | | |
| 11148 | + | |
| 11149 | + | |
| 11150 | + | |
| 11151 | + | |
| 11152 | + | |
| 11153 | + | |
11148 | 11154 | | |
11149 | 11155 | | |
11150 | 11156 | | |
| |||
0 commit comments