Skip to content

Commit ac022c8

Browse files
ameryhungKernel Patches Daemon
authored andcommitted
libbpf: Fix out-of-bound read in bpf_linker__add_buf()
Fix a potential out-of-bound read in bpf_linker__add_buf() by advancing the buffer pointer and reducing the remaining buffer size passed to write() in each iteration. The bug is reported in [0]. [0]: libbpf/libbpf#945 Fixes: 6d5e5e5 ("libbpf: Extend linker API to support in-memory ELF files") Signed-off-by: Amery Hung <ameryhung@gmail.com> Acked-by: Jiri Olsa <jolsa@kernel.org>
1 parent e6d707e commit ac022c8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/lib/bpf/linker.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ int bpf_linker__add_buf(struct bpf_linker *linker, void *buf, size_t buf_sz,
581581

582582
written = 0;
583583
while (written < buf_sz) {
584-
ret = write(fd, buf, buf_sz);
584+
ret = write(fd, buf + written, buf_sz - written);
585585
if (ret < 0) {
586586
ret = -errno;
587587
pr_warn("failed to write '%s': %s\n", filename, errstr(ret));

0 commit comments

Comments
 (0)