Skip to content

Commit

Permalink
api: fix seccomp_export_bpf_mem out-of-bounds read
Browse files Browse the repository at this point in the history
*len is the length of the destination buffer, but program->blks is
probably not anywhere near that long.  It's already been checked above
that BPF_PGM_SIZE(program) is less than or equal to *len, so that's
the correct value to use here to avoid either reading or writing too
much.

I noticed this because tests/11-basic-basic_errors started failing on
musl after e797591 ("all: add seccomp_precompute() functionality").

Signed-off-by: Alyssa Ross <[email protected]>
  • Loading branch information
alyssais committed Feb 13, 2025
1 parent 7db46d7 commit 904e9de
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ API int seccomp_export_bpf_mem(const scmp_filter_ctx ctx, void *buf,
if (BPF_PGM_SIZE(program) > *len)
rc = _rc_filter(-ERANGE);
else
memcpy(buf, program->blks, *len);
memcpy(buf, program->blks, BPF_PGM_SIZE(program));
}
*len = BPF_PGM_SIZE(program);

Expand Down

0 comments on commit 904e9de

Please sign in to comment.