Skip to content

Commit 579d6c6

Browse files
captain5050acmel
authored andcommitted
perf bpf: 8 byte align bpil data
bpil data is accessed assuming 64-bit alignment resulting in undefined behavior as the data is just byte aligned. With an -fsanitize=undefined build the following errors are observed: $ sudo perf record -a sleep 1 util/bpf-event.c:310:22: runtime error: load of misaligned address 0x55f61084520f for type '__u64', which requires 8 byte alignment 0x55f61084520f: note: pointer points here a8 fe ff ff 3c 51 d3 c0 ff ff ff ff 04 84 d3 c0 ff ff ff ff d8 aa d3 c0 ff ff ff ff a4 c0 d3 c0 ^ util/bpf-event.c:311:20: runtime error: load of misaligned address 0x55f61084522f for type '__u32', which requires 4 byte alignment 0x55f61084522f: note: pointer points here ff ff ff ff c7 17 00 00 f1 02 00 00 1f 04 00 00 58 04 00 00 00 00 00 00 0f 00 00 00 63 02 00 00 ^ util/bpf-event.c:198:33: runtime error: member access within misaligned address 0x55f61084523f for type 'const struct bpf_func_info', which requires 4 byte alignment 0x55f61084523f: note: pointer points here 58 04 00 00 00 00 00 00 0f 00 00 00 63 02 00 00 3b 00 00 00 ab 02 00 00 44 00 00 00 14 03 00 00 Correct this by rouding up the data sizes and aligning the pointers. Signed-off-by: Ian Rogers <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Dave Marchevsky <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: John Fastabend <[email protected]> Cc: KP Singh <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Quentin Monnet <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Yonghong Song <[email protected]> Cc: [email protected] Cc: [email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 117c495 commit 579d6c6

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

tools/perf/util/bpf-utils.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,10 @@ get_bpf_prog_info_linear(int fd, __u64 arrays)
149149
count = bpf_prog_info_read_offset_u32(&info, desc->count_offset);
150150
size = bpf_prog_info_read_offset_u32(&info, desc->size_offset);
151151

152-
data_len += count * size;
152+
data_len += roundup(count * size, sizeof(__u64));
153153
}
154154

155155
/* step 3: allocate continuous memory */
156-
data_len = roundup(data_len, sizeof(__u64));
157156
info_linear = malloc(sizeof(struct perf_bpil) + data_len);
158157
if (!info_linear)
159158
return ERR_PTR(-ENOMEM);
@@ -180,7 +179,7 @@ get_bpf_prog_info_linear(int fd, __u64 arrays)
180179
bpf_prog_info_set_offset_u64(&info_linear->info,
181180
desc->array_offset,
182181
ptr_to_u64(ptr));
183-
ptr += count * size;
182+
ptr += roundup(count * size, sizeof(__u64));
184183
}
185184

186185
/* step 5: call syscall again to get required arrays */

0 commit comments

Comments
 (0)