Re: Example code instructions
Mickaël Salaün <[email protected]> Mon, 19 Sep 2022 17:34:06 +0200
| Newsgroups | dev.linux.lists.landlock |
|---|---|
| Message-ID | <[email protected]> |
Hi, On 19/09/2022 16:44, devnull wrote: > I am trying to figure out how to use landlock to implement into userspace applications and came across this example code > https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/samples/landlock/sandboxer.c > > However, I find myself unable to successfully build the example code The simple solution to build this sample is to run `make samples/landlock/` in the Linux source directory or simply `make` in the sample directory. You need to download the whole kernel source though. > > Perhaps this is an obvious issue for any full time C developer, but it would help increase the use of landlock if there is an example code with step by step instruction on how to actually build it. Two external C header files are needed: - an up-to-date unistd.h with the appropriate __NR_landlock_* declarations; - an up-to-date linux/landlock.h with all the LANDLOCK_ACCESS_* declarations. These files should be in sync with the kernel provided by your distro. If it is not the case, you should report this issue. Otherwise, you can still use your own header files, preferably provided by a dedicated package (e.g. linux-libc-dev_*.deb or kernel-headers-*.rpm). These files are in the include/uapi/ directory from the kernel source. > > So far, any attempt to compile the example "sandboxer.c" (using clang or gcc) will result in the following error: > > sandboxer.c:163:9: error: ‘LANDLOCK_ACCESS_FS_REFER’ undeclared (first use in this function) This means that the landlock.h file used by the compiler doesn't have this declaration, which was added with Linux 5.19 . > > > The affected system is running linux 5.19.8 with landlock enabled. Are you using a custom kernel or one provided by your distro? You may be missing a related header/dev package. > > There may just be a missing compile flag to get it working but I have not found any documentation about it. > Any hints would be appreciated, thank you >