diff options
author | Jia Tan <jiat0218@gmail.com> | 2024-02-26 23:02:06 +0800 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2024-02-28 18:31:04 +0200 |
commit | a100f9111c8cc7f5b5f0e4a5e8af3de7161c7975 (patch) | |
tree | b4eeeadacc883f3e2a60e06d8e9d960fe3ff8db8 /CMakeLists.txt | |
parent | Tests: Add test_microlzma to .gitignore and CMakeLists.txt. (diff) | |
download | xz-a100f9111c8cc7f5b5f0e4a5e8af3de7161c7975.tar.xz |
Build: Fix Linux Landlock feature test in Autotools and CMake builds.
The previous Linux Landlock feature test assumed that having the
linux/landlock.h header file was enough. The new feature tests also
requires that prctl() and the required Landlock system calls are
supported.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 76700591..d2b1af7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -901,10 +901,29 @@ endif() # Sandboxing: Landlock if(NOT SANDBOX_FOUND AND ENABLE_SANDBOX MATCHES "^ON$|^landlock$") - check_include_file(linux/landlock.h HAVE_LINUX_LANDLOCK_H) + # A compile check is done here because some systems have + # linux/landlock.h, but do not have the syscalls defined + # in order to actually use Linux Landlock. + check_c_source_compiles(" + #include <linux/landlock.h> + #include <sys/syscall.h> + #include <sys/prctl.h> +. + void my_sandbox(void) + { + (void)prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); + (void)SYS_landlock_create_ruleset; + (void)SYS_landlock_restrict_self; + (void)LANDLOCK_CREATE_RULESET_VERSION; + return; + } + + int main(void) { return 0; } + " + HAVE_LINUX_LANDLOCK) - if(HAVE_LINUX_LANDLOCK_H) - set(SANDBOX_COMPILE_DEFINITION "HAVE_LINUX_LANDLOCK_H") + if(HAVE_LINUX_LANDLOCK) + set(SANDBOX_COMPILE_DEFINITION "HAVE_LINUX_LANDLOCK") set(SANDBOX_FOUND ON) # Of our three sandbox methods, only Landlock is incompatible |