Reproducer for ghostlock
v6 cover Reproducer for ghostlock
Test for CVE-2026-43499 (GhostLock), a stack use-after-free in the rtmutex PI code, fixed in kernel v7.1:3bfdc63936dd ("rtmutex: Use waiter::task instead of current in remove_waiter()")
Reproducer based on the Nebula Security writeup and open-sourced PoC
(https://nebusec.ai/research/ionstack-part-2/, https://github.com/NebuSec/CyberMeowfia).
Beware, this test will crash the system on a vulnerable kernel.
Assisted by Kimi K3 for the analysis and written mostly with Gemini Pro 3.1 Max.
---
Changes in v6:
- drop const from sched_setattr() and safe_sched_setattr() prototypes to match glibc 2.41+
- add kernel-doc comment for SAFE_SCHED_SETATTR()
- fix struct prctl_mm_map fallback guard in lapi/prctl.h
- validate futex_wait_requeue_pi() outcome before waking spray checkpoint
- sort ghostlock entry in testcases/cve/.gitignore
- Link to v5: https://lore.kernel.org/[email protected]
Changes in v5:
- reduced synchronization checkpoints from 5 to 3
- introduced and used SAFE_SCHED_SETATTR() in lapi/sched.h
- dropped unused PR_SET_MM_MAP_SIZE probe in setup()
- fixed duplicated -pthread entry in Makefile
- fixed CVE numerical ordering in runtest/cve
- Link to v4: https://lore.kernel.org/[email protected]
Changes in v4:
- handle runtime inside the test
- increase futext wait so we don't TBROK before runtime
- comment prctl() syscall
- move static vars out of the run function
- Link to v3: https://lore.kernel.org/[email protected]
Changes in v3:
- improve sync mechanism
- fix lapi imports
- Link to v2: https://lore.kernel.org/[email protected]
Changes in v2:
- fix build
- fix 32bit run
- Link to v1: https://lore.kernel.org/[email protected]
---
Andrea Cervesato (3):
lapi/sched: add SAFE_SCHED_SETATTR()
lapi/prctl: add more fallback definitions
cve: add CVE-2026-43499 reproducer
configure.ac | 2 + include/lapi/prctl.h | 26 +++++ include/lapi/sched.h | 31 +++++- runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/Makefile | 2 +- testcases/cve/ghostlock.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 307 insertions(+), 2 deletions(-)
---
base-commit: 12724413534a6d4160ff9694ba6f09daa4ccb6bd
change-id: 20260801-cve-ghostlock-6ee4b2f69fd6
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/3 lapi/sched: add SAFE_SCHED_SETATTR()
From: Andrea Cervesato <[email protected]>
Add a safe variant of sched_setattr() that breaks the test with TBROK on failure, so tests such as the CVE-2026-43499 reproducer do not have to open-code the TEST() + tst_brk() error handling.
--- include/lapi/sched.h | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
include/lapi/sched.h +30 -1
@@ -34,7 +34,7 @@ struct sched_attr {uint64_t sched_period; }; -static inline int sched_setattr (pid_t pid,const struct sched_attr *attr, +static inline int sched_setattr (pid_t pid,struct sched_attr *attr,unsigned int flags) {return syscall (__NR_sched_setattr, pid, attr, flags);
@@ -169,4 +169,33 @@ static inline int getcpu(unsigned *cpu, unsigned *node)# define CLONE_INTO_CGROUP 0x200000000ULL#endif +static inline int safe_sched_setattr (const char *file,const int lineno, +pid_t pid,struct sched_attr *attr, +unsigned int flags) +{ +int ret; + + ret =sched_setattr (pid, attr, flags); + +if (ret ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"sched_setattr(%i) failed" , pid); + } + +return ret; +} + +/** +* SAFE_SCHED_SETATTR() - Safe wrapper for sched_setattr(). +* @pid: Target process or thread ID (0 for caller). +* @attr: Pointer to a sched_attr structure. +* @flags: Flags modifying the scheduling behavior. +* +* Calls sched_setattr() and breaks the test with TBROK | TERRNO on failure. +* +* Return: Zero on success. +*/ +#define SAFE_SCHED_SETATTR (pid, attr, flags)\ + safe_sched_setattr(__FILE__, __LINE__, (pid), (attr), (flags)) +#endif /* LAPI_SCHED_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/3] lapi/sched: add SAFE_SCHED_SETATTR()
Hi Cyril,
Quoted 29 lines
include/lapi/sched.h +21
-1-static inline int sched_setattr (pid_t pid,const struct sched_attr *attr, +static inline int sched_setattr (pid_t pid,struct sched_attr *attr,unsigned int flags) {return syscall (__NR_sched_setattr, pid, attr, flags);@@ -169,4 +169,33 @@ static inline int getcpu(unsigned *cpu, unsigned *node)# define CLONE_INTO_CGROUP 0x200000000ULL#endif +static inline int safe_sched_setattr (const char *file,const int lineno, +pid_t pid,struct sched_attr *attr, +unsigned int flags) +{ +int ret; + + ret =sched_setattr (pid, attr, flags); + +if (ret ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"sched_setattr(%i) failed" , pid); + } + +return ret; +} + +/** +* SAFE_SCHED_SETATTR() - Safe wrapper for sched_setattr(). +* @pid: Target process or thread ID (0 for caller). +* @attr: Pointer to a sched_attr structure.
include/lapi/sched.h static inline int getcpu(unsigned *cpu, unsigned *node) · line 201
Quoted 10 lines
include/lapi/sched.h +9
-0+* @flags: Flags modifying the scheduling behavior. +* +* Calls sched_setattr() and breaks the test with TBROK | TERRNO on failure. +* +* Return: Zero on success. +*/ +#define SAFE_SCHED_SETATTR (pid, attr, flags)\ + safe_sched_setattr(__FILE__, __LINE__, (pid), (attr), (flags)) +#endif /* LAPI_SCHED_H__ */
the header is used by sched_setattr01, so I can't include the SAFE_* definition in here, which is the right place, since we are trying to move them into the related headers. It causes a build failure due to the old vs. new API mix. I will send a new patch-set with the sched_setattr01 rewrite.
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] lapi/sched: add SAFE_SCHED_SETATTR()
In reply to Andrea CervesatoHi Andrea,
Quoted 1 line · Andrea Cervesato
lapi/sched: add
SAFE_SCHED_SETATTR()
--- [PATCH 1/3] ---
Quoted 1 line
+ *
SAFE_SCHED_SETATTR()- Safe wrapper forsched_setattr().
linuxdoc requires macro names without the function suffix. Use SAFE_SCHED_SETATTR - Safe wrapper for sched_setattr().
--- [PATCH 2/3] ---
Quoted 1 line
+struct
prctl_mm_map{
This new public structure needs a kernel-doc comment with a struct prctl_mm_map summary and entries for its members.
--- [PATCH 3/3] ---
Review
Quoted 3 lines
(quoted diff) +3
-0+ futex_lock_pi(&f_pi_chain); + + TST_CHECKPOINT_WAKE(CP_CHAIN_HELD);
FUTEX_LOCK_PI can return ENOSYS at runtime, after which this checkpoint incorrectly announces that the lock is held. Check all lock and unlock calls, report ENOSYS as TCONF, and abort on other unexpected errors.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its findings are genuine. If you find issues with the review, please comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 2/3 lapi/prctl: add more fallback definitions
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add the following fallback definitions:
- PR_SET_MM
- PR_SET_MM_MAP
- PR_SET_MM_MAP_SIZE
- struct prctl_mm_map
--- configure.ac | 2 ++ include/lapi/prctl.h | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+)
configure.ac +2 -0
@@ -286,6 +286,8 @@ AC_CHECK_TYPES([struct fsxattr],,,[#include <linux/fs.h>]) AC_CHECK_TYPES([struct logical_block_metadata_cap],,,[#include <linux/fs.h>]) +AC_CHECK_TYPES([struct prctl_mm_map],,,[#include <sys/prctl.h>]) + AC_CHECK_TYPES([struct sockaddr_vm],,,[ #include <sys/socket.h> #include <linux/vm_sockets.h>
include/lapi/prctl.h +26 -0
@@ -7,7 +7,9 @@#ifndef LAPI_PRCTL_H__ #define LAPI_PRCTL_H__ +#include <stdint.h> #include <sys/prctl.h> +#include "config.h" #ifndef PR_SET_NAME # define PR_SET_NAME 15
@@ -59,4 +61,28 @@# define PR_SET_SPECULATION_CTRL 53#endif +#ifndef PR_SET_MM +# define PR_SET_MM 35 +#endif +#ifndef PR_SET_MM_MAP +# define PR_SET_MM_MAP 14 +#endif +#ifndef PR_SET_MM_MAP_SIZE +# define PR_SET_MM_MAP_SIZE 15 +#endif + +#ifndef HAVE_STRUCT_PRCTL_MM_MAP +struct prctl_mm_map { +uint64_t start_code, end_code; +uint64_t start_data, end_data; +uint64_t start_brk, brk; +uint64_t start_stack; +uint64_t arg_start, arg_end; +uint64_t env_start, env_end; +uint64_t *auxv; +uint32_t auxv_size; +uint32_t exe_fd; +}; +#endif +#endif /* LAPI_PRCTL_H__ */
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 3/3 cve: add CVE-2026-43499 reproducer
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
Add "Ghostlock" reproducer for CVE-2026-43499.
Reproducer based on the Nebula Security writeup and open-sourced PoC
(https://nebusec.ai/research/ionstack-part-2/,
https://github.com/NebuSec/CyberMeowfia).
Beware, this test will crash the system on a vulnerable kernel.
--- runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/Makefile | 2 +- testcases/cve/ghostlock.c | 246 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+), 1 deletion(-)
runtest/cve +1 -0
@@ -88,6 +88,7 @@ cve-2023-1829 tcindex01 cve-2023-0461 setsockopt10 cve-2023-31248 nft02 cve-2023-52879 fanotify25 +cve-2026-43499 ghostlock cve-2026-53362 setsockopt11 cve-2026-64600 refluxfs # Tests below may cause kernel memory leak
testcases/cve/.gitignore +1 -0
@@ -16,5 +16,6 @@ tcindex01 cve-2025-38236 cve-2025-21756 cve-2026-46331 +ghostlock refluxfs sctphantom
testcases/cve/Makefile +1 -1
@@ -11,7 +11,7 @@ stack_clash: CFLAGS += -fno-optimize-sibling-calls -Wno-infinite-recursion cve-2016-7042: LDLIBS += $(KEYUTILS_LIBS) -cve-2014-0196 cve-2016-7117 cve-2017-2671 cve-2017-17052 cve-2017-17053 refluxfs: CFLAGS += -pthread +cve-2014-0196 cve-2016-7117 cve-2017-2671 cve-2017-17052 cve-2017-17053 ghostlock refluxfs: CFLAGS += -pthread cve-2014-0196 cve-2016-7117 cve-2017-2671: LDLIBS += -lrt ifneq ($(ANDROID),1)
testcases/cve/ghostlock.c new file +246 -0
246 lines not on this page · raw message
Signature · 5 lines
2.51.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp