libseccomp: fix seccomp_export_bpf_mem out-of-bounds read
PATCH 1/2 libseccomp: fix seccomp_export_bpf_mem out-of-bounds read
Fixes segfaults in ptests on musl
Failed ptests:
{'libseccomp': ['11-basic-basic_errors%%001-00001_11-basic-basic_errors_rc=139']}
--- ...mp_export_bpf_mem-out-of-bounds-read.patch | 37 +++++++++++++++++++ .../libseccomp/libseccomp_2.6.0.bb | 1 + 2 files changed, 38 insertions(+) create mode 100644 meta/recipes-support/libseccomp/files/0001-api-fix-seccomp_export_bpf_mem-out-of-bounds-read.patch
meta/recipes-support/libseccomp/files/0001-api-fix-seccomp_export_bpf_mem-out-of-bounds-read.patch new file +37 -0
@@ -0,0 +1,37 @@ +From 83a56d74482ef6b6cc9311b14bf9ea23573f5d4e Mon Sep 17 00:00:00 2001 +From: Alyssa Ross <[email protected]> +Date: Thu, 13 Feb 2025 12:05:17 +0100 +Subject: [PATCH] api: fix seccomp_export_bpf_mem out-of-bounds read + +*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"). + +Upstream-Status: Backport [https://github.com/seccomp/libseccomp/commit/dd759e8c4f5685b526638fba9ec4fc24c37c9aec] +Signed-off-by: Alyssa Ross <[email protected]> +Acked-by: Tom Hromatka <[email protected]> +Signed-off-by: Paul Moore <[email protected]> +(imported from commit e8dbc6b555fb936bdfb8ab86f9a45fda96a8b7a2) +Signed-off-by: Khem Raj <[email protected]> +--- + src/api.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/src/api.c b/src/api.c +index adccef3..65a277a 100644 +--- a/src/api.c ++++ b/src/api.c +@@ -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); +
meta/recipes-support/libseccomp/libseccomp_2.6.0.bb +1 -0
@@ -10,6 +10,7 @@ DEPENDS += "gperf-native" SRCREV = "c7c0caed1d04292500ed4b9bb386566053eb9775" SRC_URI = "git://github.com/seccomp/libseccomp.git;branch=release-2.6;protocol=https \ + file://0001-api-fix-seccomp_export_bpf_mem-out-of-bounds-read.patch \ file://run-ptest \ "
PATCH 2/2 lttng-tools: fix unix socket high FD count test
Fixes ptest failure on musl
'ERROR: Exited from signal Killed (9)\n' 'DURATION: 663\n'}
--- .../lttng/lttng-tools/test.patch | 22 +++++++++++++++++++ .../lttng/lttng-tools_2.14.0.bb | 1 + 2 files changed, 23 insertions(+) create mode 100644 meta/recipes-kernel/lttng/lttng-tools/test.patch
meta/recipes-kernel/lttng/lttng-tools/test.patch new file +22 -0
@@ -0,0 +1,22 @@ +tests: fix unix socket high FD count test off-by-one + +The HIGH_FD_COUNT macro in test_unix_socket.cpp was set equal to +LTTCOMM_MAX_SEND_FDS, which could cause the test to exceed the +maximum allowed number of file descriptors. Adjust it to +LTTCOMM_MAX_SEND_FDS - 1 to avoid hitting the limit and ensure the +test remains valid. + +Upstream-Status: Inappropriate [Musl-specific] +Signed-off-by: Khem Raj <[email protected]> + +--- a/tests/unit/test_unix_socket.cpp ++++ b/tests/unit/test_unix_socket.cpp +@@ -25,7 +25,7 @@ + #include <tap/tap.h> + #include <unistd.h> + +-#define HIGH_FD_COUNT LTTCOMM_MAX_SEND_FDS ++#define HIGH_FD_COUNT LTTCOMM_MAX_SEND_FDS - 1 + #define MESSAGE_COUNT 4 + #define LARGE_PAYLOAD_SIZE (4 * 1024) + #define LARGE_PAYLOAD_RECV_SIZE 100
meta/recipes-kernel/lttng/lttng-tools_2.14.0.bb +1 -0
@@ -54,6 +54,7 @@ SRC_URI = "https://lttng.org/files/lttng-tools/lttng-tools-${PV}.tar.bz2 \ file://disable-tests2.patch \ file://0001-liblttng-ctl-drop-index-allocator-symbols-from-versi.patch \ file://libc++.patch \ + file://test.patch \ " SRC_URI[sha256sum] = "d8c39c26cec13b7bd82551cd52a22efc358b888e36ebcf9c1b60ef1c3a3c2fd3"
Re: [OE-core] [PATCH 2/2] lttng-tools: fix unix socket high FD count test
meta/recipes-kernel/lttng/lttng-tools/test.patch line 9
Quoted 7 lines · Khem Raj via lists.openembedded.org
meta/recipes-kernel/lttng/lttng-tools/test.patch new file +7
-0+The HIGH_FD_COUNT macro in test_unix_socket.cpp was set equal to +LTTCOMM_MAX_SEND_FDS, which could cause the test to exceed the +maximum allowed number of file descriptors. Adjust it to +LTTCOMM_MAX_SEND_FDS - 1 to avoid hitting the limit and ensure the +test remains valid. + +Upstream-Status: Inappropriate [Musl-specific]
This needs an upstream ticket.
Alex
Re: [OE-core] [PATCH 2/2] lttng-tools: fix unix socket high FD count test
In reply to Khem RajQuoted 1 line · Khem Raj via lists.openembedded.org
+tests: fix unix socket high FD count test off-by-one
Is this an off-by-one in the test suite (in which case it should be upstreamed), in musl, or in glibc?
Someone has a bug and we should endeavour to fix it at source.
Ross
Re: [OE-core] [PATCH 2/2] lttng-tools: fix unix socket high FD count test
Quoted 6 lines · Ross Burton
Quoted 1 line · Khem Raj via lists.openembedded.org
+tests: fix unix socket high FD count test off-by-one
Is this an off-by-one in the test suite (in which case it should be upstreamed), in musl, or in glibc?
I saw it on musl and this machine was running a lot of parallel tests, but it's not happening all the time. It's fine to drop this patch
Quoted 3 lines
Someone has a bug and we should endeavour to fix it at source.
Ross