mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 12:43:29 +02:00
selftests/landlock: Add hostfs tests
Add tests for the hostfs filesystems to make sure it has a consistent inode management, which is required for Landlock's file hierarchy identification. This adds 5 new tests for layout3_fs with the hostfs variant. Add hostfs to the new (architecture-specific) config.um file. The hostfs filesystem, only available for an User-Mode Linux kernel, is special because we cannot explicitly mount it. The layout3_fs.hostfs variant tests are skipped if the current test directory is not backed by this filesystem. The layout3_fs.hostfs.tag_inode_dir_child and layout3_fs.hostfs.tag_inode_file tests pass thanks to a previous commit fixing hostfs inode management. Without this fix, the deny-by-default policy would apply and all access requests would be denied. Link: https://lore.kernel.org/r/20230612191430.339153-7-mic@digikod.net Signed-off-by: Mickaël Salaün <mic@digikod.net>
This commit is contained in:
1
tools/testing/selftests/landlock/config.um
Normal file
1
tools/testing/selftests/landlock/config.um
Normal file
@@ -0,0 +1 @@
|
|||||||
|
CONFIG_HOSTFS=y
|
@@ -10,6 +10,7 @@
|
|||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <linux/landlock.h>
|
#include <linux/landlock.h>
|
||||||
|
#include <linux/magic.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -19,6 +20,7 @@
|
|||||||
#include <sys/sendfile.h>
|
#include <sys/sendfile.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
|
#include <sys/vfs.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
@@ -135,6 +137,19 @@ static bool supports_filesystem(const char *const filesystem)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool cwd_matches_fs(unsigned int fs_magic)
|
||||||
|
{
|
||||||
|
struct statfs statfs_buf;
|
||||||
|
|
||||||
|
if (!fs_magic)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if (statfs(".", &statfs_buf))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return statfs_buf.f_type == fs_magic;
|
||||||
|
}
|
||||||
|
|
||||||
static void mkdir_parents(struct __test_metadata *const _metadata,
|
static void mkdir_parents(struct __test_metadata *const _metadata,
|
||||||
const char *const path)
|
const char *const path)
|
||||||
{
|
{
|
||||||
@@ -4500,6 +4515,7 @@ FIXTURE_VARIANT(layout3_fs)
|
|||||||
{
|
{
|
||||||
const struct mnt_opt mnt;
|
const struct mnt_opt mnt;
|
||||||
const char *const file_path;
|
const char *const file_path;
|
||||||
|
unsigned int cwd_fs_magic;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* clang-format off */
|
/* clang-format off */
|
||||||
@@ -4538,13 +4554,23 @@ FIXTURE_VARIANT_ADD(layout3_fs, sysfs) {
|
|||||||
.file_path = TMP_DIR "/kernel/notes",
|
.file_path = TMP_DIR "/kernel/notes",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FIXTURE_VARIANT_ADD(layout3_fs, hostfs) {
|
||||||
|
.mnt = {
|
||||||
|
.source = TMP_DIR,
|
||||||
|
.flags = MS_BIND,
|
||||||
|
},
|
||||||
|
.file_path = TMP_DIR "/dir/file",
|
||||||
|
.cwd_fs_magic = HOSTFS_SUPER_MAGIC,
|
||||||
|
};
|
||||||
|
|
||||||
FIXTURE_SETUP(layout3_fs)
|
FIXTURE_SETUP(layout3_fs)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
const char *slash;
|
const char *slash;
|
||||||
size_t dir_len;
|
size_t dir_len;
|
||||||
|
|
||||||
if (!supports_filesystem(variant->mnt.type)) {
|
if (!supports_filesystem(variant->mnt.type) ||
|
||||||
|
!cwd_matches_fs(variant->cwd_fs_magic)) {
|
||||||
self->skip_test = true;
|
self->skip_test = true;
|
||||||
SKIP(return, "this filesystem is not supported (setup)");
|
SKIP(return, "this filesystem is not supported (setup)");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user