Commit f8d6f10
committed
libbpf: Fix possible use-after-free for externs
JIRA: https://issues.redhat.com/browse/RHEL-110274
commit fa6f092
Author: Adin Scannell <amscanne@meta.com>
Date: Tue Jun 24 22:02:15 2025 -0700
libbpf: Fix possible use-after-free for externs
The `name` field in `obj->externs` points into the BTF data at initial
open time. However, some functions may invalidate this after opening and
before loading (e.g. `bpf_map__set_value_size`), which results in
pointers into freed memory and undefined behavior.
The simplest solution is to simply `strdup` these strings, similar to
the `essent_name`, and free them at the same time.
In order to test this path, the `global_map_resize` BPF selftest is
modified slightly to ensure the presence of an extern, which causes this
test to fail prior to the fix. Given there isn't an obvious API or error
to test against, I opted to add this to the existing test as an aspect
of the resizing feature rather than duplicate the test.
Fixes: 9d0a233 ("libbpf: Add capability for resizing datasec maps")
Signed-off-by: Adin Scannell <amscanne@meta.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250625050215.2777374-1-amscanne@meta.com
Signed-off-by: Viktor Malik <vmalik@redhat.com>1 parent 74b0ce4 commit f8d6f10
File tree
2 files changed
+23
-3
lines changed- tools
- lib/bpf
- testing/selftests/bpf/progs
2 files changed
+23
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
596 | 596 | | |
597 | 597 | | |
598 | 598 | | |
599 | | - | |
| 599 | + | |
600 | 600 | | |
601 | 601 | | |
602 | 602 | | |
| |||
4223 | 4223 | | |
4224 | 4224 | | |
4225 | 4225 | | |
4226 | | - | |
| 4226 | + | |
| 4227 | + | |
| 4228 | + | |
4227 | 4229 | | |
4228 | 4230 | | |
4229 | 4231 | | |
| |||
9062 | 9064 | | |
9063 | 9065 | | |
9064 | 9066 | | |
9065 | | - | |
| 9067 | + | |
| 9068 | + | |
9066 | 9069 | | |
| 9070 | + | |
9067 | 9071 | | |
9068 | 9072 | | |
9069 | 9073 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
35 | 45 | | |
36 | 46 | | |
37 | 47 | | |
| |||
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
47 | 60 | | |
48 | 61 | | |
49 | 62 | | |
| |||
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
62 | 78 | | |
63 | 79 | | |
64 | 80 | | |
| |||
0 commit comments