Reproducer for the landlock houdini bug
v4 cover Reproducer for the landlock houdini bug
More information at:
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-42318
---
Changes in v4:
- fix compilation errors
- Link to v3: https://patchwork.ozlabs.org/project/ltp/list/?series=420318
Changes in v3:
- verify return value of keyctl() according with manual
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- add SAFE_KEYCTL macro
- verify in setup that landlock is activated
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Andrea Cervesato (2):
Add SAFE_KEYCTL macro
Add landlock07 test
include/lapi/keyctl.h | 73 ++++++++++++++++ runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/Makefile | 3 + testcases/kernel/syscalls/landlock/landlock07.c | 108 ++++++++++++++++++++++++ 5 files changed, 186 insertions(+)
---
base-commit: 3e8fd5de333bb437b35a00d7557bbf367f5da344
change-id: 20240822-landlock_houdini-7df576807e3f
Best regards,
Signature · 5 lines
Andrea Cervesato <[email protected]> -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/2 Add SAFE_KEYCTL macro
From: Andrea Cervesato <[email protected]>
--- include/lapi/keyctl.h | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+)
include/lapi/keyctl.h +73 -0
@@ -116,6 +116,10 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {# define KEYCTL_SETPERM 5#endif +#ifndef KEYCTL_DESCRIBE +# define KEYCTL_DESCRIBE 6 +#endif +#ifndef KEYCTL_CLEAR # define KEYCTL_CLEAR 7#endif
@@ -124,6 +128,10 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {# define KEYCTL_UNLINK 9#endif +#ifndef KEYCTL_SEARCH +# define KEYCTL_SEARCH 10 +#endif +#ifndef KEYCTL_READ # define KEYCTL_READ 11#endif
@@ -136,10 +144,26 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {# define KEYCTL_SET_TIMEOUT 15#endif +#ifndef KEYCTL_ASSUME_AUTHORITY +# define KEYCTL_ASSUME_AUTHORITY 16 +#endif + +#ifndef KEYCTL_GET_SECURITY +# define KEYCTL_GET_SECURITY 17 +#endif +#ifndef KEYCTL_INVALIDATE # define KEYCTL_INVALIDATE 21#endif +#ifndef KEYCTL_GET_PERSISTENT +# define KEYCTL_GET_PERSISTENT 22 +#endif + +#ifndef KEYCTL_DH_COMPUTE +# define KEYCTL_DH_COMPUTE 23 +#endif +#ifndef KEYCTL_WATCH_KEY # define KEYCTL_WATCH_KEY 32#endif
@@ -179,4 +203,53 @@ static inline key_serial_t keyctl_join_session_keyring(const char *name) {# define KEY_OTH_ALL 0x0000003f#endif /* !KEY_POS_VIEW */ +static inline long safe_keyctl (const char *file,const int lineno, +int cmd,unsigned long arg2,unsigned long arg3, +unsigned long arg4,unsigned long arg5) +{ +long rval; +int failure =0 ; + + rval =keyctl (cmd, arg2, arg3, arg4, arg5); +if (rval ==-1 ) { +tst_brk_ (file, lineno,TBROK |TERRNO , +"keyctl(%d, %lu, %lu, %lu, %lu)" , + cmd, arg2, arg3, arg4, arg5); + } + +switch (cmd) { +case KEYCTL_GET_KEYRING_ID : +case KEYCTL_JOIN_SESSION_KEYRING : +case KEYCTL_DESCRIBE : +case KEYCTL_SEARCH : +case KEYCTL_READ : +case KEYCTL_SET_REQKEY_KEYRING : +case KEYCTL_GET_SECURITY : +case KEYCTL_GET_PERSISTENT : +case KEYCTL_DH_COMPUTE : +if (rval <0 ) + failure =1 ; +break ; +case KEYCTL_ASSUME_AUTHORITY : +if ((!arg2 && rval) || (arg2 && rval <0 )) + failure =1 ; +break ; +default : +if (rval) + failure =1 ; +break ; + } + +if (failure) { +tst_brk_ (file, lineno,TBROK , +"keyctl(%d, %lu, %lu, %lu, %lu) returned %ld" , + cmd, arg2, arg3, arg4, arg5, rval); + } + +return rval; +} +#define SAFE_KEYCTL (cmd, arg2, arg3, arg4, arg5) \ + safe_keyctl(__FILE__, __LINE__, \ + (cmd), (arg2), (arg3), (arg4), (arg5)) +#endif /* LAPI_KEYCTL_H__ */
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 2/2 Add landlock07 test
In reply to Andrea CervesatoFrom: Andrea Cervesato <[email protected]>
This test is a reproducer for the CVE-2024-42318 bug, also known as landlock Houdini.
More information at:
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-42318
--- runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/Makefile | 3 + testcases/kernel/syscalls/landlock/landlock07.c | 108 ++++++++++++++++++++++++ 4 files changed, 113 insertions(+)
runtest/syscalls +1 -0
@@ -706,6 +706,7 @@ landlock03 landlock03 landlock04 landlock04 landlock05 landlock05 landlock06 landlock06 +landlock07 landlock07 lchown01 lchown01 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
@@ -5,3 +5,4 @@ landlock03 landlock04 landlock05 landlock06 +landlock07
testcases/kernel/syscalls/landlock/Makefile +3 -0
@@ -4,4 +4,7 @@ top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk + +landlock07: LDLIBS += $(KEYUTILS_LIBS) + include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/landlock/landlock07.c new file +108 -0
108 lines not on this page · raw message
Signature · 5 lines
2.43.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
This version fixes the compile errors, so I will submit it:
https://github.com/acerv/ltp/actions/runs/10506068964
Andrea
Quoted 36 lines · Andrea Cervesato
More information at:
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2024-42318Signed-off-by Andrea Cervesato <[email protected]>---
Changes in v4:
- fix compilation errors
- Link to v3: https://patchwork.ozlabs.org/project/ltp/list/?series=420318Changes in v3:
- verify return value ofkeyctl()according with manual
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- addSAFE_KEYCTLmacro
- verify in setup that landlock is activated
- Link to v1: https://lore.kernel.org/r/[email protected]Signed-off-by Andrea Cervesato <[email protected]>---
Andrea Cervesato (2):
AddSAFE_KEYCTLmacro
Add landlock07 testinclude/lapi/keyctl.h | 73 ++++++++++++++++ runtest/syscalls | 1 + testcases/kernel/syscalls/landlock/.gitignore | 1 + testcases/kernel/syscalls/landlock/Makefile | 3 + testcases/kernel/syscalls/landlock/landlock07.c | 108 ++++++++++++++++++++++++ 5 files changed, 186 insertions(+)---
base-commit:3e8fd5de333bb437b35a00d7557bbf367f5da344
change-id: 20240822-landlock_houdini-7df576807e3fBest regards,
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp