Commit e245c00
bpf: Unconditionally take socket references in lookup helpers
Lookup helpers gate whether to acquire a socket reference on
sk_is_refcounted(), a check re-evaluated at release. An established socket
refcounted at acquire time can gain SOCK_RCU_FREE via
connect(AF_UNSPEC)+listen() before release runs; the release-side re-check
then reads sk_is_refcounted() == false and skips the put. The reference
leaks.
Make acquire and release unconditional and symmetric: always take a
reference, always put it. Adapt sk_select_reuseport().
Fixes: 6acc9b4 ("bpf: Add helper to retrieve socket in BPF")
Fixes: 64d8529 ("bpf: Allow bpf_map_lookup_elem for SOCKMAP and SOCKHASH")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://lore.kernel.org/bpf/20260701235552.2B0AA1F00A3F@smtp.kernel.org/
Signed-off-by: Michal Luczaj <mhal@rbox.co>
Reviewed-by: Emil Tsalapatis <emil@etsalapatis.com>1 parent 690b74d commit e245c00
2 files changed
Lines changed: 20 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7032 | 7032 | | |
7033 | 7033 | | |
7034 | 7034 | | |
| 7035 | + | |
| 7036 | + | |
| 7037 | + | |
| 7038 | + | |
| 7039 | + | |
| 7040 | + | |
| 7041 | + | |
| 7042 | + | |
7035 | 7043 | | |
7036 | 7044 | | |
7037 | 7045 | | |
| |||
7090 | 7098 | | |
7091 | 7099 | | |
7092 | 7100 | | |
7093 | | - | |
7094 | 7101 | | |
7095 | 7102 | | |
7096 | 7103 | | |
7097 | 7104 | | |
| 7105 | + | |
| 7106 | + | |
| 7107 | + | |
| 7108 | + | |
| 7109 | + | |
| 7110 | + | |
7098 | 7111 | | |
7099 | 7112 | | |
7100 | 7113 | | |
| |||
7279 | 7292 | | |
7280 | 7293 | | |
7281 | 7294 | | |
7282 | | - | |
| 7295 | + | |
7283 | 7296 | | |
7284 | 7297 | | |
7285 | 7298 | | |
| |||
11571 | 11584 | | |
11572 | 11585 | | |
11573 | 11586 | | |
11574 | | - | |
| 11587 | + | |
11575 | 11588 | | |
11576 | 11589 | | |
11577 | 11590 | | |
11578 | 11591 | | |
| 11592 | + | |
| 11593 | + | |
11579 | 11594 | | |
11580 | 11595 | | |
11581 | 11596 | | |
| |||
11605 | 11620 | | |
11606 | 11621 | | |
11607 | 11622 | | |
11608 | | - | |
11609 | | - | |
11610 | 11623 | | |
11611 | | - | |
11612 | | - | |
11613 | | - | |
11614 | | - | |
11615 | 11624 | | |
11616 | 11625 | | |
11617 | 11626 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
395 | | - | |
| 395 | + | |
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
| |||
1218 | 1218 | | |
1219 | 1219 | | |
1220 | 1220 | | |
1221 | | - | |
| 1221 | + | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | 1224 | | |
| |||
0 commit comments