lksctp-tools: fix sctp_connectx() and ptests on musl
PATCH 1/2 lksctp-tools: fix sctp_connectx() and ptests on musl
Three func_tests failed on musl:
- test_1_to_1_sendmsg and test_1_to_1_recvmsg died with SIGSEGV. They pass (struct msghdr *)-1 and expect EFAULT, but on 64-bit musl the sendmsg()/recvmsg() wrappers copy the msghdr to clear its padding before making the syscall. Issue those two calls with syscall(2) so they test the kernel's handling of the bad pointer.
- test_connectx reported "Association id mismatch: connectx returned 3, notification returned:240". libsctp exports an unversioned sctp_connectx alias of the original API next to the VERS_1..VERS_3 versions. musl's dynamic linker does not implement symbol versioning and binds that alias, so every sctp_connectx() call on musl ran the old API, which never returns the association id. The alias only serves binaries linked before libsctp was versioned, so only emit it on glibc; sctp_connectx@@VERS_3 is then the one musl resolves.
Tested with meta-networking-image-ptest-lksctp-tools on qemux86-64 with
yoe-musl-systemd-wayland: TOTAL: 1 FAIL: 0.
AI-Generated: Uses Claude Code
--- ...invalid-msghdr-pointers-straight-to-.patch | 72 +++++++++++++++++++ ...port-the-unversioned-sctp_connectx-a.patch | 49 +++++++++++++ .../lksctp-tools/lksctp-tools_1.0.21.bb | 2 + 3 files changed, 123 insertions(+) create mode 100644 meta-networking/recipes-support/lksctp-tools/lksctp-tools/0002-func_tests-pass-invalid-msghdr-pointers-straight-to-.patch create mode 100644 meta-networking/recipes-support/lksctp-tools/lksctp-tools/0003-connectx-only-export-the-unversioned-sctp_connectx-a.patch
meta-networking/recipes-support/lksctp-tools/lksctp-tools/0002-func_tests-pass-invalid-msghdr-pointers-straight-to-.patch new file +72 -0
@@ -0,0 +1,72 @@ +From 5402bce533c3ba8dae022eded7c6ffe7967b7248 Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Sun, 27 Sep 2026 15:52:39 -0700 +Subject: [PATCH 2/3] func_tests: pass invalid msghdr pointers straight to the + kernel + +test_1_to_1_sendmsg TEST6 and test_1_to_1_recvmsg TEST4 hand +(struct msghdr *)-1 to sendmsg()/recvmsg() and expect EFAULT from the +kernel. Passing an invalid pointer to a libc function is undefined, and +on 64-bit musl both wrappers copy the msghdr first to clear its padding +fields, so the tests die with SIGSEGV before reaching the syscall. + +Use syscall(2) for these two cases so they test what they mean to: the +kernel's handling of a bad msghdr pointer. + +Upstream-Status: Pending +Signed-off-by: Khem Raj <[email protected]> +--- + src/func_tests/test_1_to_1_recvmsg.c | 7 ++++++- + src/func_tests/test_1_to_1_sendmsg.c | 7 ++++++- + 2 files changed, 12 insertions(+), 2 deletions(-) + +diff --git a/src/func_tests/test_1_to_1_recvmsg.c b/src/func_tests/test_1_to_1_recvmsg.c +index 962b7b5..0ccf087 100644 +--- a/src/func_tests/test_1_to_1_recvmsg.c ++++ b/src/func_tests/test_1_to_1_recvmsg.c +@@ -56,6 +56,7 @@ + #include <sys/uio.h> + #include <linux/socket.h> + #include <sctputil.h> ++#include <sys/syscall.h> + + char *TCID = __FILE__; + int TST_TOTAL = 8; +@@ -158,7 +159,11 @@ main(int argc, char *argv[]) + inmessage.msg_iov = &iov_rcv; + + /*recvmsg () TEST4: Invalid msghdr pointer EFAULT, Expected error*/ +- count = recvmsg(acpt_sk, (struct msghdr *)-1, flag); ++ /* Call the kernel directly: libc wrappers may read the msghdr ++ * themselves (musl copies it to clear padding on 64-bit), which ++ * crashes instead of returning EFAULT. ++ */ ++ count = syscall(SYS_recvmsg, acpt_sk, (struct msghdr *)-1, flag); + if (count != -1 || errno != EFAULT) + tst_brkm(TBROK, tst_exit, "recvmsg with invalid msghdr " + "pointer count:%d, errno:%d", count, errno); +diff --git a/src/func_tests/test_1_to_1_sendmsg.c b/src/func_tests/test_1_to_1_sendmsg.c +index f2949e7..4f46c78 100644 +--- a/src/func_tests/test_1_to_1_sendmsg.c ++++ b/src/func_tests/test_1_to_1_sendmsg.c +@@ -63,6 +63,7 @@ + #include <sys/uio.h> + #include <linux/socket.h> + #include <sctputil.h> ++#include <sys/syscall.h> + + char *TCID = __FILE__; + int TST_TOTAL = 14; +@@ -200,7 +201,11 @@ main(int argc, char *argv[]) + outmessage.msg_iovlen = 1; + + /*sendmsg () TEST6: Invalid msghdr pointer EFAULT, Expected error*/ +- count = sendmsg(sk, (struct msghdr *)-1, flag); ++ /* Call the kernel directly: libc wrappers may read the msghdr ++ * themselves (musl copies it to clear padding on 64-bit), which ++ * crashes instead of returning EFAULT. ++ */ ++ count = syscall(SYS_sendmsg, sk, (struct msghdr *)-1, flag); + if (count != -1 || errno != EFAULT) + tst_brkm(TBROK, tst_exit, "sendmsg with invalid msghdr " + "pointer count:%d, errno:%d", count, errno);
meta-networking/recipes-support/lksctp-tools/lksctp-tools/0003-connectx-only-export-the-unversioned-sctp_connectx-a.patch new file +49 -0
49 lines not on this page · raw message
meta-networking/recipes-support/lksctp-tools/lksctp-tools_1.0.21.bb +2 -0
@@ -13,6 +13,8 @@ SRCREV = "37d5f1225573b91d706a5e547d081f79963a9deb" SRC_URI = " \ git://github.com/sctp/lksctp-tools.git;branch=master;protocol=https \ file://0001-func_tests-disable-FORTIFY_SOURCE-for-test_1_to_1_re.patch \ + file://0002-func_tests-pass-invalid-msghdr-pointers-straight-to-.patch \ + file://0003-connectx-only-export-the-unversioned-sctp_connectx-a.patch \ file://run-ptest \ file://v4test.sh \ file://v6test.sh \
PATCH 2/2 python3-scapy: fix libpcap loading and ptests on musl
- ctypes.util.find_library() relies on "ldconfig -p", gcc or ld, none of which exist on a musl target, so find_library("pcap") returns None and scapy raises "Cannot find libpcap.so library" even with libpcap installed. That disabled conf.use_pcap and BPF filter compilation and failed ten ptests (offline sniff() with filters, tcpdump(), tdecode(), traceroute). Fall back to loading libpcap.so.1/libpcap.so by name.
- The NetBSD read_routes6() test compares IPv4-compatible IPv6 prefixes as strings, but musl's inet_ntop() prints ::127.0.0.0 as ::7f00:0. Normalise the expected values with in6_ptop().
Tested with meta-networking-image-ptest-python3-scapy on qemux86-64 with yoe-musl-systemd-wayland: TOTAL: 1 FAIL: 0.
AI-Generated: Uses Claude Code
--- ...pcap-even-when-find_library-cannot-l.patch | 52 +++++++++++++++++++ ...d-on-libc-formatting-of-IPv4-compati.patch | 37 +++++++++++++ .../python/python3-scapy_2.7.0.bb | 2 + 3 files changed, 91 insertions(+) create mode 100644 meta-networking/recipes-devtools/python/python3-scapy/0003-libpcap-load-libpcap-even-when-find_library-cannot-l.patch create mode 100644 meta-networking/recipes-devtools/python/python3-scapy/0004-test-don-t-depend-on-libc-formatting-of-IPv4-compati.patch
meta-networking/recipes-devtools/python/python3-scapy/0003-libpcap-load-libpcap-even-when-find_library-cannot-l.patch new file +52 -0
@@ -0,0 +1,52 @@ +From 6ee4ddc1b53f792d4e2a7826d65cebeeb9d9eb79 Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Sun, 27 Sep 2026 15:54:57 -0700 +Subject: [PATCH 3/4] libpcap: load libpcap even when find_library() cannot + locate it + +ctypes.util.find_library() finds libraries through "ldconfig -p", gcc +or ld. A target system may have none of them; on musl-based systems +there is no ldconfig cache at all, so find_library("pcap") returns None +even with libpcap installed, and scapy reports + + OSError: Cannot find libpcap.so library + +which disables conf.use_pcap and BPF filter compilation (sniff() with a +filter, tcpdump(), tdecode(), ...). Fall back to loading libpcap.so.1 or +libpcap.so by name and let the dynamic loader search its default paths. + +Upstream-Status: Pending +Signed-off-by: Khem Raj <[email protected]> +--- + scapy/libs/winpcapy.py | 18 +++++++++++++++--- + 1 file changed, 15 insertions(+), 3 deletions(-) + +diff --git a/scapy/libs/winpcapy.py b/scapy/libs/winpcapy.py +index 42bfa850..c537b22b 100644 +--- a/scapy/libs/winpcapy.py ++++ b/scapy/libs/winpcapy.py +@@ -36,9 +36,21 @@ else: + # Try to load libpcap + SOCKET = c_int + _lib_name = find_library("pcap") +- if not _lib_name: +- raise OSError("Cannot find libpcap.so library") +- _lib = CDLL(_lib_name) ++ if _lib_name: ++ _lib = CDLL(_lib_name) ++ else: ++ # ctypes.util.find_library() relies on ldconfig, gcc or ld to ++ # locate libraries, none of which may exist on the target (e.g. ++ # musl-based systems have no "ldconfig -p"). Fall back to letting ++ # the dynamic loader search its default paths. ++ for _lib_name in ("libpcap.so.1", "libpcap.so"): ++ try: ++ _lib = CDLL(_lib_name) ++ break ++ except OSError: ++ pass ++ else: ++ raise OSError("Cannot find libpcap.so library") + + + ##
meta-networking/recipes-devtools/python/python3-scapy/0004-test-don-t-depend-on-libc-formatting-of-IPv4-compati.patch new file +37 -0
@@ -0,0 +1,37 @@ +From 7602260f82f54cf9b179549c5b03866ec16f68d5 Mon Sep 17 00:00:00 2001 +From: Khem Raj <[email protected]> +Date: Sun, 27 Sep 2026 15:54:57 -0700 +Subject: [PATCH 4/4] test: don't depend on libc formatting of IPv4-compatible + addresses + +The NetBSD read_routes6() test compares route prefixes such as +::127.0.0.0 as strings, but scapy formats them with the libc's +inet_ntop(). glibc prints IPv4-compatible addresses in dotted form, +while musl only does so for IPv4-mapped (::ffff:a.b.c.d) addresses and +prints ::7f00:0, ::e000:0 and ::ff00:0, so the test fails on musl. +Both forms denote the same address; normalise the expected values with +in6_ptop() so they match whatever the libc produces. + +Upstream-Status: Pending +Signed-off-by: Khem Raj <[email protected]> +--- + test/regression.uts | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/test/regression.uts b/test/regression.uts +index 4c972fa1..b6bb9d6e 100644 +--- a/test/regression.uts ++++ b/test/regression.uts +@@ -3134,9 +3134,9 @@ assert routes == [ + ('::', 104, '::1', 'lo0', ['::1'], 1), + ('::', 96, '::1', 'lo0', ['::1'], 1), + ('::1', 128, '::', 'lo0', ['::1'], 1), +- ('::127.0.0.0', 104, '::1', 'lo0', ['::1'], 1), +- ('::224.0.0.0', 100, '::1', 'lo0', ['::1'], 1), +- ('::255.0.0.0', 104, '::1', 'lo0', ['::1'], 1), ++ (in6_ptop('::127.0.0.0'), 104, '::1', 'lo0', ['::1'], 1), ++ (in6_ptop('::224.0.0.0'), 100, '::1', 'lo0', ['::1'], 1), ++ (in6_ptop('::255.0.0.0'), 104, '::1', 'lo0', ['::1'], 1), + ('::ffff:0.0.0.0', 96, '::1', 'lo0', ['::1'], 1), + ('2001:db8::', 32, '::1', 'lo0', ['::1'], 1), + ('2002::', 24, '::1', 'lo0', ['::1'], 1),
meta-networking/recipes-devtools/python/python3-scapy_2.7.0.bb +2 -0
@@ -20,6 +20,8 @@ SRCREV = "1de09fe85fe5c9d60ea5c6de130374e170b5bc28" SRC_URI = "git://github.com/secdev/scapy.git;branch=master;protocol=https;tag=v${PV} \ file://0001-python3-scapy-skip-ICMP-regression-tests-in-ptest.patch \ file://0002-main-initialize-banner-for-the-default-Python-shell.patch \ + file://0003-libpcap-load-libpcap-even-when-find_library-cannot-l.patch \ + file://0004-test-don-t-depend-on-libc-formatting-of-IPv4-compati.patch \ file://run-ptest" UPSTREAM_CHECK_COMMITS = "1"