Skip to contentSkip to conversation

landlock testing suite

PATCH In review Andrea Cervesato 4 participants 16 messages Aug 1, 2024 – Aug 13, 2024

lore
Share & tools
lore
#0 lore raw

v5 cover landlock testing suite

This testing suite is meant to test the following syscalls:

- landlock_create_ruleset
- landlock_add_rule
- landlock_restrict_self

Documentation can be found in kernel manuals and inside the official kernel documentation at

https://www.kernel.org/doc/html/latest/userspace-api/landlock.html

---
Changes in v5:
- landlock0[123]: remove minimum kernel check
- landlock04: cleanup/setup for sandbox folder, enforce_ruleset() inside the child, skip vfat and exfat for some tests, now working with -i >= 0
- landlock05: remove minimum kernel check
- landlock06: remove exfat from skip
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- landlock03: fix TBROK on -i usage
- landlock04: fix EINVAL caused by namespace sharing on kernel <=6.6
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- landlock01: 1 byte less when HAVE_STRUCT_LANDLOCK_RULESET_ATTR_HANDLED_ACCESS_NET is defined
- landlock04: dynamically assign read/exec permissions to dependences
- landlock05: estetic fix and skip exfat
- landlock06: estetic fix and skip exfat
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- remove -lc unused dependency from Makefile
- move SAFE_LANDLOCK_* macros in lapi/landlock.h
- define CAP_MKNOD in the lapi/capability.h
- fix landlock fallback in order to let LTP build properly
- fix landlock01 EINVAL test when "struct landlock_ruleset_attr" size is too small
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (6):
Get ABI version from landlock common library Add CAP_MKNOD fallback in lapi/capability.h Disable kernel version check in landlock tests Add landlock04 test
Add landlock05 test
Add landlock06 test

 include/lapi/capability.h                          |  12 +-
 runtest/syscalls                                   |   3 +
 testcases/kernel/syscalls/landlock/.gitignore      |   4 +
 testcases/kernel/syscalls/landlock/landlock01.c    |   1 -
 testcases/kernel/syscalls/landlock/landlock02.c    |   1 -
 testcases/kernel/syscalls/landlock/landlock03.c    |   1 -
 testcases/kernel/syscalls/landlock/landlock04.c    | 212 +++++++++++
 testcases/kernel/syscalls/landlock/landlock05.c    | 118 +++++++
 testcases/kernel/syscalls/landlock/landlock06.c    | 107 ++++++
 .../kernel/syscalls/landlock/landlock_common.h     |   4 +-
 testcases/kernel/syscalls/landlock/landlock_exec.c |   9 +
 .../kernel/syscalls/landlock/landlock_tester.h     | 393 +++++++++++++++++++++
 12 files changed, 857 insertions(+), 8 deletions(-)

---
base-commit: eee3b2dd6d9dae6120646bc14c30e460989d7df6
change-id: 20240617-landlock-c48a4623a447

Best regards,

Signature · 5 lines
Andrea Cervesato <[email protected]>


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v5 1/6 Get ABI version from landlock common library

From: Andrea Cervesato <[email protected]>

Return the ABI version when verify_landlock_is_enabled() is called.

---
 testcases/kernel/syscalls/landlock/landlock_common.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
testcases/kernel/syscalls/landlock/landlock_common.h +3 -1
index 66f8fd19a..1d3864934 100644
@@ -10,7 +10,7 @@
 #include "lapi/fcntl.h"
 #include "lapi/landlock.h"
 
-static inline void verify_landlock_is_enabled(void)
+static inline int verify_landlock_is_enabled(void)
 {
 	int abi;
 
@@ -28,6 +28,8 @@ static inline void verify_landlock_is_enabled(void)
 	}
 
 	tst_res(TINFO, "Landlock ABI v%d", abi);
+
+	return abi;
 }
 
 static inline void apply_landlock_rule(
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v5 1/6
#2 lore raw

Re: [LTP] [PATCH v5 1/6] Get ABI version from landlock common library

Hi Andrea,

obviously correct, thanks!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

PATCH v5 2/6 Add CAP_MKNOD fallback in lapi/capability.h

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

---
 include/lapi/capability.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
include/lapi/capability.h +8 -4
index 2b593797c..0f317d6d7 100644
@@ -44,14 +44,18 @@
 # define CAP_SYS_TIME         25
 #endif
 
-#ifndef CAP_AUDIT_READ
-# define CAP_AUDIT_READ       37
-#endif
-
 #ifndef CAP_SYS_RESOURCE
 # define CAP_SYS_RESOURCE     24
 #endif
 
+#ifndef CAP_MKNOD
+# define CAP_MKNOD            27
+#endif
+
+#ifndef CAP_AUDIT_READ
+# define CAP_AUDIT_READ       37
+#endif
+
 #ifndef CAP_BPF
 # define CAP_BPF              39
 #endif
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v5 2/6
#4 lore raw

Re: [LTP] [PATCH v5 2/6] Add CAP_MKNOD fallback in lapi/capability.h

Hi Andrea,

(I added it already in v4)

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

PATCH v5 3/6 Disable kernel version check in landlock tests

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

The reason why we remove kernel version check is that we use verify_landlock_is_enabled() function in order to check if landlock is present in the system. This is really helpful when landlock support has been backported into old kernels.

---
 testcases/kernel/syscalls/landlock/landlock01.c | 1 -
 testcases/kernel/syscalls/landlock/landlock02.c | 1 -
 testcases/kernel/syscalls/landlock/landlock03.c | 1 -
 3 files changed, 3 deletions(-)
testcases/kernel/syscalls/landlock/landlock01.c +0 -1
index 0c50b55d8..db2ffe89b 100644
@@ -75,7 +75,6 @@ static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
-	.min_kver = "5.13",
 	.needs_root = 1,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_SECURITY_LANDLOCK=y",
testcases/kernel/syscalls/landlock/landlock02.c +0 -1
index c29ff1e83..2b3e31f69 100644
@@ -120,7 +120,6 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
-	.min_kver = "5.13",
 	.needs_root = 1,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_SECURITY_LANDLOCK=y",
testcases/kernel/syscalls/landlock/landlock03.c +0 -1
index 9bf358d1c..5661b6b29 100644
@@ -108,7 +108,6 @@ static struct tst_test test = {
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
-	.min_kver = "5.13",
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.forks_child = 1,
Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v5 3/6
#6 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

Hi Andrea,

Quoted 4 lines

The reason why we remove kernel version check is that we use verify_landlock_is_enabled() function in order to check if landlock is present in the system. This is really helpful when landlock support has been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

Hi!

I send 1 more patch to fix all tests removing CONFIG_SECURITY_LANDLOCK=y

Regards,
Andrea

Quoted 18 lines · Petr Vorel

Hi Andrea,

Quoted 4 lines

The reason why we remove kernel version check is that we use verify_landlock_is_enabled() function in order to check if landlock is present in the system. This is really helpful when landlock support has been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

In reply to Petr Vorel
Quoted 10 lines · Petr Vorel

is is really helpful when landlock support has

Quoted 1 line

been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

My understanding is that LTP only tests supported features to make sure they work as expected, if enabled. Is it correct?

I'm then wondering what is the purpose of needs_kconfigs. If there is no "needed" config, does that means that Landlock tests will always run and detect at run time if tests are skipped or not? If yes, it looks good to me.

Andrea's commit to remove needs_kconfig:
https://github.com/linux-test-project/ltp/commit/e7ebc637d0d99295490adf57660a3b3a177d65d3

Is there an online dashboard to see some tested kernels?

Quoted 8 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

Hi Meckael,

Quoted 8 lines · Mickaël Salaün
Quoted 7 lines · Petr Vorel

is is really helpful when landlock support has

Quoted 1 line

been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Quoted 4 lines
Quoted 2 lines

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

My understanding is that LTP only tests supported features to make sure they work as expected, if enabled. Is it correct?

Yes, landlock in particular can be a backported feature, so we need to remove CONFIG flags and kernel version, raising an error just in case we have ENOSYS.

Quoted 9 lines

I'm then wondering what is the purpose of needs_kconfigs. If there is no "needed" config, does that means that Landlock tests will always run and detect at run time if tests are skipped or not? If yes, it looks good to me.

Andrea's commit to remove needs_kconfig:
https://github.com/linux-test-project/ltp/commit/e7ebc637d0d99295490adf57660a3b3a177d65d3

Is there an online dashboard to see some tested kernels?

@Petr Vorel

Quoted 8 lines
Quoted 8 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp

Regards,
Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

Hi all,

Quoted 23 lines

Hi Meckael,

Quoted 8 lines · Mickaël Salaün
Quoted 6 lines · Petr Vorel

is is really helpful when landlock support has

Quoted 1 line

been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Quoted 4 lines
Quoted 2 lines

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

My understanding is that LTP only tests supported features to make sure they work as expected, if enabled. Is it correct?

Yes, landlock in particular can be a backported feature, so we need to remove CONFIG flags and kernel version, raising an error just in case we have ENOSYS.

Quoted 4 lines

I'm then wondering what is the purpose of needs_kconfigs. If there is no "needed" config, does that means that Landlock tests will always run and detect at run time if tests are skipped or not? If yes, it looks good to me.

Quoted 5 lines
Quoted 4 lines

Andrea's commit to remove needs_kconfig:
https://github.com/linux-test-project/ltp/commit/e7ebc637d0d99295490adf57660a3b3a177d65d3

Is there an online dashboard to see some tested kernels?

@Petr Vorel

I suppose folks at Linaro, Nikolai (CKI) or other companies which do public testing have some public logs.

We have openSUSE tests on 6.10.3-1 for various archs on [1] and [2]. Here is x86_64 [3][4] and riscv64 [5] failing on landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25).

# landlock06; echo "### TEST landlock06 COMPLETE >>> $?."
tst_buffers.c:57: TINFO: Test is using guarded buffers
tst_tmpdir.c:316: TINFO: Using /var/tmp/LTP_lan8lXtC5 as tmpdir (btrfs filesystem)
tst_device.c:96: TINFO: Found free device 0 '/dev/loop0'
tst_test.c:1807: TINFO: LTP version: 20240524
tst_test.c:1651: TINFO: Timeout per run is 0h 00m 30s
tst_supported_fs_types.c:97: TINFO: Kernel supports ext2
tst_supported_fs_types.c:62: TINFO: mkfs.ext2 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports ext3
tst_supported_fs_types.c:62: TINFO: mkfs.ext3 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports ext4
tst_supported_fs_types.c:62: TINFO: mkfs.ext4 does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports xfs
tst_supported_fs_types.c:62: TINFO: mkfs.xfs does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports btrfs
tst_supported_fs_types.c:62: TINFO: mkfs.btrfs does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports bcachefs
tst_supported_fs_types.c:62: TINFO: mkfs.bcachefs does exist
tst_supported_fs_types.c:169: TINFO: Skipping vfat as requested by the test
tst_supported_fs_types.c:97: TINFO: Kernel supports exfat
tst_supported_fs_types.c:62: TINFO: mkfs.exfat does exist
tst_supported_fs_types.c:132: TINFO: FUSE does support ntfs
tst_supported_fs_types.c:62: TINFO: mkfs.ntfs does exist
tst_supported_fs_types.c:97: TINFO: Kernel supports tmpfs
tst_supported_fs_types.c:49: TINFO: mkfs is not needed for tmpfs
tst_test.c:1747: TINFO: === Testing on ext2 ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with ext2 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=ext2 flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on ext3 ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with ext3 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=ext3 flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on ext4 ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with ext4 opts='' extra opts=''
mke2fs 1.47.0 (5-Feb-2023)
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=ext4 flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on xfs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with xfs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=xfs flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on btrfs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with btrfs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=btrfs flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on bcachefs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with bcachefs opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=bcachefs flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on exfat ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with exfat opts='' extra opts=''
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=exfat flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on ntfs ===
tst_test.c:1111: TINFO: Formatting /dev/loop0 with ntfs opts='' extra opts=''
The partition start sector was not specified for /dev/loop0 and it could not be obtained automatically. It has been set to 0. The number of sectors per track was not specified for /dev/loop0 and it could not be obtained automatically. It has been set to 0. The number of heads was not specified for /dev/loop0 and it could not be obtained automatically. It has been set to 0. To boot from a device, Windows needs the 'partition start sector', the 'sectors per track' and the 'number of heads' to be set. Windows will not be able to boot from this device.
tst_test.c:1123: TINFO: Mounting /dev/loop0 to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=ntfs flags=0 tst_test.c:1123: TINFO: Trying FUSE...
landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)
tst_test.c:1747: TINFO: === Testing on tmpfs ===
tst_test.c:1111: TINFO: Skipping mkfs for TMPFS filesystem
tst_test.c:1087: TINFO: Limiting tmpfs size to 32MB
tst_test.c:1123: TINFO: Mounting ltp-tmpfs to /var/tmp/LTP_lan8lXtC5/sandbox fstyp=tmpfs flags=0 landlock_common.h:31: TINFO: Landlock ABI v5
landlock06.c:55: TINFO: Applying LANDLOCK_ACCESS_FS_IOCTL_DEV
landlock06.c:34: TPASS: ioctl(file_fd, FIONREAD, &sz) passed
landlock06.c:35: TPASS: ioctl(dev_fd, FIOCLEX) passed
landlock06.c:36: TPASS: ioctl(dev_fd, FIONCLEX) passed
landlock06.c:37: TPASS: ioctl(dev_fd, FIONBIO, &flag) passed
landlock06.c:38: TFAIL: ioctl(dev_fd, FIOASYNC, &flag) failed: ENOTTY (25)

Summary:

passed   36
failed   9
broken   0
skipped  0

warnings 0
### TEST landlock06 COMPLETE >>> 1.

dmesg [6]:

OpenQA::run_ltp.pm: Starting landlock06

[ 1050.979179][T110531] loop0: detected capacity change from 0 to 614400
[ 1050.998116][T110531] /dev/zero: Can't lookup blockdev
[ 1051.004764][T110531] /dev/zero: Can't lookup blockdev
[ 1051.010525][T110531] /dev/zero: Can't lookup blockdev
[ 1051.014325][T110531] /dev/zero: Can't lookup blockdev
[ 1051.021487][T110531] bcachefs (/dev/zero): error reading superblock: error opening /dev/zero: ENOTBLK
[ 1051.022857][T110531] bcachefs: bch2_mount() error: ENOTBLK
[ 1051.058671][T110531] /dev/zero: Can't lookup blockdev
[ 1051.105329][T110531] EXT4-fs (loop0): mounting ext2 file system using the ext4 subsystem
[ 1051.117949][T110531] EXT4-fs (loop0): mounted filesystem 2c8afdbf-6fa5-42e8-8fd4-28954bdde347 r/w without journal. Quota mode: none.
[ 1051.127872][T110531] EXT4-fs (loop0): unmounting filesystem 2c8afdbf-6fa5-42e8-8fd4-28954bdde347.
[ 1051.204843][T110531] EXT4-fs (loop0): mounting ext3 file system using the ext4 subsystem
[ 1051.213928][T110531] EXT4-fs (loop0): mounted filesystem d61f27f7-7dce-4f66-ad8e-70b4a33b9222 r/w with ordered data mode. Quota mode: none.
[ 1051.218709][T110531] EXT4-fs (loop0): unmounting filesystem d61f27f7-7dce-4f66-ad8e-70b4a33b9222.
[ 1051.251190][T110531] EXT4-fs (loop0): mounted filesystem b3d3c34a-d06b-4950-9317-facae9d51858 r/w with ordered data mode. Quota mode: none.
[ 1051.255995][T110531] EXT4-fs (loop0): unmounting filesystem b3d3c34a-d06b-4950-9317-facae9d51858.
[ 1051.287117][T110531] XFS (loop0): Mounting V5 Filesystem 8b3dafa3-3d09-42ad-974f-a4f6b64dbc21
[ 1051.292956][T110531] XFS (loop0): Ending clean mount
[ 1051.299264][T110531] XFS (loop0): Unmounting Filesystem 8b3dafa3-3d09-42ad-974f-a4f6b64dbc21
[ 1051.349548][T110531] BTRFS: device fsid 773dda9f-d706-4408-9de1-6cbf1aeb810c devid 1 transid 8 /dev/loop0 (7:0) scanned by landlock06 (110531)
[ 1051.356250][T110531] BTRFS info (device loop0): first mount of filesystem 773dda9f-d706-4408-9de1-6cbf1aeb810c
[ 1051.360300][T110531] BTRFS info (device loop0): using crc32c (crc32c-intel) checksum algorithm
[ 1051.361782][T110531] BTRFS info (device loop0): using free-space-tree
[ 1051.399193][T110531] BTRFS info (device loop0): checking UUID tree
[ 1051.403606][T110531] BTRFS info (device loop0): last unmount of filesystem 773dda9f-d706-4408-9de1-6cbf1aeb810c
[ 1051.470051][T110531] bcachefs (loop0): mounting version 1.7: mi_btree_bitmap
[ 1051.472754][T110531] bcachefs (loop0): initializing new filesystem
[ 1051.474263][T110531] bcachefs (loop0): going read-write
[ 1051.475613][T110531] bcachefs (loop0): initializing freespace
[ 1051.511331][T110531] bcachefs (loop0): shutdown complete, journal seq 7

They are not failing on aarch64 [7] and ppc64le [8].

We have 6.11.0-rc2 build, which also fails on x86_64 for the same reason [9]. There is also unique bcachefs related failure (which is probably not related to landlock):

tst_cmd.c:113: TBROK: failed to exec cmd 'mkfs.bcachefs' at tst_cmd.c:113

(also landlock04 and landlock05 fails with it).

Kind regards,
Petr

[1] https://openqa.opensuse.org/group_overview/32
[2] https://openqa.opensuse.org/group_overview/125
[3] https://openqa.opensuse.org/tests/4397937#step/landlock06/6
[4] https://openqa.opensuse.org/tests/4397937/file/serial_terminal.txt
[5] https://openqa.opensuse.org/tests/4398174#step/landlock06/6
[6] https://openqa.opensuse.org/tests/4397937/file/serial0.txt
[7] https://openqa.opensuse.org/tests/4397935#step/landlock06/8
[8] https://openqa.opensuse.org/tests/4397936#step/landlock06/8
[9] https://openqa.opensuse.org/tests/4394746#step/landlock06/8

Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp

Regards,
Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH v5 3/6] Disable kernel version check in landlock tests

In reply to Mickaël Salaün
Quoted 9 lines · Petr Vorel
Quoted 7 lines

is is really helpful when landlock support has

Quoted 1 line

been backported into old kernels.

Great, I'm glad you removed it from all landlock tests. It really did not make sense to guard correct version with 3 guards (kernel version, kernel config and ABI). Could you please remove also CONFIG_SECURITY_LANDLOCK=y, because you check EOPNOTSUPP in verify_landlock_is_enabled().

Quoted 5 lines
Quoted 2 lines

Anyway, feel free to merge these first 3 patches (ideally remove also CONFIG_SECURITY_LANDLOCK=y before merge).

My understanding is that LTP only tests supported features to make sure they work as expected, if enabled. Is it correct?

FYI LTP should skip the test if feature is not enabled (instead of false positive result). And LTP tries to support various kernels (mainline, stable/LTS, enterprise kernels), various glibc (and other libc) versions [1].

If possible (like in landlock case) it's best to avoid hardcoding minimal kernel version (features can be backported). Also, when not needed, it's better to avoid kernel config check (e.g. for landlock).

Kind regards,
Petr

[1] https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html

Quoted 18 lines

I'm then wondering what is the purpose of needs_kconfigs. If there is no "needed" config, does that means that Landlock tests will always run and detect at run time if tests are skipped or not? If yes, it looks good to me.

Andrea's commit to remove needs_kconfig:
https://github.com/linux-test-project/ltp/commit/e7ebc637d0d99295490adf57660a3b3a177d65d3

Is there an online dashboard to see some tested kernels?

Quoted 7 lines

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

PATCH v5 4/6 Add landlock04 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies that all landlock rules are working properly. The way we do it is to verify that all disabled syscalls are not working but the one we enabled via specifc landlock rules.

---
 runtest/syscalls                                   |   1 +
 testcases/kernel/syscalls/landlock/.gitignore      |   2 +
 testcases/kernel/syscalls/landlock/landlock04.c    | 212 +++++++++++
 testcases/kernel/syscalls/landlock/landlock_exec.c |   9 +
 .../kernel/syscalls/landlock/landlock_tester.h     | 393 +++++++++++++++++++++
 5 files changed, 617 insertions(+)
runtest/syscalls +1 -0
index 9b3cba667..67b2e2758 100644
@@ -699,6 +699,7 @@ kill13 kill13
 landlock01 landlock01
 landlock02 landlock02
 landlock03 landlock03
+landlock04 landlock04
 
 lchown01 lchown01
 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +2 -0
index f79cd090b..4fe8d7cba 100644
@@ -1,3 +1,5 @@
+landlock_exec
 landlock01
 landlock02
 landlock03
+landlock04
testcases/kernel/syscalls/landlock/landlock04.c new file +212 -0

212 lines not on this page · raw message

testcases/kernel/syscalls/landlock/landlock_exec.c new file +9 -0
new file mode 100644
index 000000000..aae5c76b2
@@ -0,0 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+int main(void)
+{
+	return 0;
+}
testcases/kernel/syscalls/landlock/landlock_tester.h new file +393 -0

393 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v5 5/6 Add landlock05 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies LANDLOCK_ACCESS_FS_REFER access in the landlock sandbox. The feature is available since kernel 5.19.

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/landlock/.gitignore   |   1 +
 testcases/kernel/syscalls/landlock/landlock05.c | 118 ++++++++++++++++++++++++
 3 files changed, 120 insertions(+)
runtest/syscalls +1 -0
index 67b2e2758..6522f5bc7 100644
@@ -700,6 +700,7 @@ landlock01 landlock01
 landlock02 landlock02
 landlock03 landlock03
 landlock04 landlock04
+landlock05 landlock05
 
 lchown01 lchown01
 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
index 4fe8d7cba..a7ea6be2e 100644
@@ -3,3 +3,4 @@ landlock01
 landlock02
 landlock03
 landlock04
+landlock05
testcases/kernel/syscalls/landlock/landlock05.c new file +118 -0

118 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v5 6/6 Add landlock06 test

In reply to Andrea Cervesato

From: Andrea Cervesato <[email protected]>

This test verifies LANDLOCK_ACCESS_FS_IOCTL_DEV access in the landlock sandbox by creating a pipe and testing that ioctl() can be executed on it. The test is also verifying that some of the I/O operations can be always executed no matter the sandbox rules. This feature is available since kernel 6.10.

---
 runtest/syscalls                                |   1 +
 testcases/kernel/syscalls/landlock/.gitignore   |   1 +
 testcases/kernel/syscalls/landlock/landlock06.c | 107 ++++++++++++++++++++++++
 3 files changed, 109 insertions(+)
runtest/syscalls +1 -0
index 6522f5bc7..7ebdb41d8 100644
@@ -701,6 +701,7 @@ landlock02 landlock02
 landlock03 landlock03
 landlock04 landlock04
 landlock05 landlock05
+landlock06 landlock06
 
 lchown01 lchown01
 lchown01_16 lchown01_16
testcases/kernel/syscalls/landlock/.gitignore +1 -0
index a7ea6be2e..315ac1dca 100644
@@ -4,3 +4,4 @@ landlock02
 landlock03
 landlock04
 landlock05
+landlock06
testcases/kernel/syscalls/landlock/landlock06.c new file +107 -0

107 lines not on this page · raw message

Signature · 5 lines
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw
In reply to Andrea Cervesato

Pushed with https://github.com/linux-test-project/ltp/commit/e7ebc637d0d99295490adf57660a3b3a177d65d3 on top of it, in order to remove CONFIG_SECURITY_LANDLOCK from all landlock tests.

Best regards,
Andrea

Quoted 70 lines · Andrea Cervesato

This testing suite is meant to test the following syscalls:

- landlock_create_ruleset
- landlock_add_rule
- landlock_restrict_self

Documentation can be found in kernel manuals and inside the official kernel documentation at

https://www.kernel.org/doc/html/latest/userspace-api/landlock.html

---
Changes in v5:
- landlock0[123]: remove minimum kernel check
- landlock04: cleanup/setup for sandbox folder, enforce_ruleset() inside the child, skip vfat and exfat for some tests, now working with -i >= 0
- landlock05: remove minimum kernel check
- landlock06: remove exfat from skip
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- landlock03: fix TBROK on -i usage
- landlock04: fix EINVAL caused by namespace sharing on kernel <=6.6
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- landlock01: 1 byte less when HAVE_STRUCT_LANDLOCK_RULESET_ATTR_HANDLED_ACCESS_NET is defined
- landlock04: dynamically assign read/exec permissions to dependences
- landlock05: estetic fix and skip exfat
- landlock06: estetic fix and skip exfat
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- remove -lc unused dependency from Makefile
- move SAFE_LANDLOCK_* macros in lapi/landlock.h
- define CAP_MKNOD in the lapi/capability.h
- fix landlock fallback in order to let LTP build properly
- fix landlock01 EINVAL test when "struct landlock_ruleset_attr" size is too small
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrea Cervesato (6):
Get ABI version from landlock common library Add CAP_MKNOD fallback in lapi/capability.h Disable kernel version check in landlock tests Add landlock04 test
Add landlock05 test
Add landlock06 test

  include/lapi/capability.h                          |  12 +-
  runtest/syscalls                                   |   3 +
  testcases/kernel/syscalls/landlock/.gitignore      |   4 +
  testcases/kernel/syscalls/landlock/landlock01.c    |   1 -
  testcases/kernel/syscalls/landlock/landlock02.c    |   1 -
  testcases/kernel/syscalls/landlock/landlock03.c    |   1 -
  testcases/kernel/syscalls/landlock/landlock04.c    | 212 +++++++++++
  testcases/kernel/syscalls/landlock/landlock05.c    | 118 +++++++
  testcases/kernel/syscalls/landlock/landlock06.c    | 107 ++++++
  .../kernel/syscalls/landlock/landlock_common.h     |   4 +-
  testcases/kernel/syscalls/landlock/landlock_exec.c |   9 +
  .../kernel/syscalls/landlock/landlock_tester.h     | 393 +++++++++++++++++++++
  12 files changed, 857 insertions(+), 8 deletions(-)

---
base-commit: eee3b2dd6d9dae6120646bc14c30e460989d7df6
change-id: 20240617-landlock-c48a4623a447

Best regards,

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp