linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs
@ 2023-01-13  5:32 jeffxu
  2023-01-13  5:32 ` [PATCH v8 1/1] selftests/landlock: skip overlayfs test when not support jeffxu
  2023-01-13 19:58 ` [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs Mickaël Salaün
  0 siblings, 2 replies; 4+ messages in thread
From: jeffxu @ 2023-01-13  5:32 UTC (permalink / raw)
  To: mic; +Cc: jorgelo, keescook, linux-security-module, groeck, gnoack, Jeff Xu

From: Jeff Xu <jeffxu@google.com>

Overlayfs can be disabled in kernel config, causing related tests to
fail. Adding a check for overlayfs’s supportability at runtime,
so we can call SKIP() when needed.

Note: 
Below comments are raised during V7 discussion:

Currently SKIP() is applied to FIXTURE_SETUP, FIXTURE_TEARDOWN,
TEST_F_FORK, this is because SKIP() apply within the function 
scope, not the testcase.

We would like test infra to have a dedicated environment 
check hook (FIXTURE_ENV_CHECK) in test infra, called before 
FIXTURE_SETUP(). If the environment check fails, the remaining 
of the test will be skipped. The benefit of these are two:
1> if env check pass, in theory, the test should pass.
2> if env check fail, no need to call setup, so no need to cleanup
resource.

v8:
style change, no logic change.

v7:
https://lore.kernel.org/all/20221229211446.3154454-1-jeffxu@google.com/
Fix bug in supports_overlayfs().
Manual test with kernel with and without overlayfs.

v6: https://lore.kernel.org/all/20221229201215.3006512-1-jeffxu@google.com/
In v4, the SKIP() was applied at FIXTURE_SETUP() after mount() fail,
however, FIXTURE_TEARDOWN() will fail. It might be complicated 
for test infra or testcase itself to have cleanup code handing the
success/failure of steps in SETUP().

This patch changes the approach, it calls supports_overlay() and SKIP()
at the beginning of FIXTURE_SETUP(), FIX_TEARDOWN(), TEST_F_FORK().
Because no modification of system is done by the test, cleanup is not 
needed.

v4:
https://lore.kernel.org/all/20220823010216.2653012-1-jeffxu@google.com/


Jeff Xu (1):
  selftests/landlock: skip overlayfs test when not support

 tools/testing/selftests/landlock/fs_test.c | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)


base-commit: 963a70bee5880640d0fd83ed29dc1e7ec0d2bd4a
-- 
2.39.0.314.g84b9a713c41-goog


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v8 1/1] selftests/landlock: skip overlayfs test when not support
  2023-01-13  5:32 [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs jeffxu
@ 2023-01-13  5:32 ` jeffxu
  2023-01-13 19:58 ` [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs Mickaël Salaün
  1 sibling, 0 replies; 4+ messages in thread
From: jeffxu @ 2023-01-13  5:32 UTC (permalink / raw)
  To: mic; +Cc: jorgelo, keescook, linux-security-module, groeck, gnoack, Jeff Xu

From: Jeff Xu <jeffxu@google.com>

Overlayfs can be disabled in kernel config, causing related tests to
fail. Add check for overlayfs’s supportability at runtime,
so we can call SKIP() when needed.

Signed-off-by: Jeff Xu <jeffxu@google.com>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
---
 tools/testing/selftests/landlock/fs_test.c | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 21a2ce8fa739..b5bd5134c486 100644
--- a/tools/testing/selftests/landlock/fs_test.c
+++ b/tools/testing/selftests/landlock/fs_test.c
@@ -11,6 +11,7 @@
 #include <fcntl.h>
 #include <linux/landlock.h>
 #include <sched.h>
+#include <stdio.h>
 #include <string.h>
 #include <sys/capability.h>
 #include <sys/mount.h>
@@ -87,6 +88,41 @@ static const char dir_s3d3[] = TMP_DIR "/s3d1/s3d2/s3d3";
  *         └── s3d3
  */
 
+static bool fgrep(FILE *inf, const char *str)
+{
+	char line[32];
+	int slen = strlen(str);
+
+	while (!feof(inf)) {
+		if (!fgets(line, sizeof(line), inf))
+			break;
+		if (strncmp(line, str, slen))
+			continue;
+
+		return true;
+	}
+
+	return false;
+}
+
+static bool supports_overlayfs(void)
+{
+	bool res;
+	FILE *inf = fopen("/proc/filesystems", "r");
+
+	/*
+	 * If fopen failed, return supported.
+	 * This help detect missing file (shall not happen).
+	 */
+	if (!inf)
+		return true;
+
+	res = fgrep(inf, "nodev\toverlay\n");
+	fclose(inf);
+
+	return res;
+}
+
 static void mkdir_parents(struct __test_metadata *const _metadata,
 			  const char *const path)
 {
@@ -3404,6 +3440,9 @@ FIXTURE(layout2_overlay) {};
 
 FIXTURE_SETUP(layout2_overlay)
 {
+	if (!supports_overlayfs())
+		SKIP(return, "overlayfs is not supported");
+
 	prepare_layout(_metadata);
 
 	create_directory(_metadata, LOWER_BASE);
@@ -3440,6 +3479,9 @@ FIXTURE_SETUP(layout2_overlay)
 
 FIXTURE_TEARDOWN(layout2_overlay)
 {
+	if (!supports_overlayfs())
+		SKIP(return, "overlayfs is not supported");
+
 	EXPECT_EQ(0, remove_path(lower_do1_fl3));
 	EXPECT_EQ(0, remove_path(lower_dl1_fl2));
 	EXPECT_EQ(0, remove_path(lower_fl1));
@@ -3471,6 +3513,9 @@ FIXTURE_TEARDOWN(layout2_overlay)
 
 TEST_F_FORK(layout2_overlay, no_restriction)
 {
+	if (!supports_overlayfs())
+		SKIP(return, "overlayfs is not supported");
+
 	ASSERT_EQ(0, test_open(lower_fl1, O_RDONLY));
 	ASSERT_EQ(0, test_open(lower_dl1, O_RDONLY));
 	ASSERT_EQ(0, test_open(lower_dl1_fl2, O_RDONLY));
@@ -3634,6 +3679,9 @@ TEST_F_FORK(layout2_overlay, same_content_different_file)
 	size_t i;
 	const char *path_entry;
 
+	if (!supports_overlayfs())
+		SKIP(return, "overlayfs is not supported");
+
 	/* Sets rules on base directories (i.e. outside overlay scope). */
 	ruleset_fd = create_ruleset(_metadata, ACCESS_RW, layer1_base);
 	ASSERT_LE(0, ruleset_fd);
-- 
2.39.0.314.g84b9a713c41-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs
  2023-01-13  5:32 [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs jeffxu
  2023-01-13  5:32 ` [PATCH v8 1/1] selftests/landlock: skip overlayfs test when not support jeffxu
@ 2023-01-13 19:58 ` Mickaël Salaün
  2023-01-14  2:17   ` Jeff Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Mickaël Salaün @ 2023-01-13 19:58 UTC (permalink / raw)
  To: jeffxu; +Cc: jorgelo, keescook, linux-security-module, groeck, gnoack, Jeff Xu

Thanks Jeff! I pushed this patch in -next: 
https://git.kernel.org/pub/scm/linux/kernel/git/mic/linux.git/log/?h=next


On 13/01/2023 06:32, jeffxu@chromium.org wrote:
> From: Jeff Xu <jeffxu@google.com>
> 
> Overlayfs can be disabled in kernel config, causing related tests to
> fail. Adding a check for overlayfs’s supportability at runtime,
> so we can call SKIP() when needed.
> 
> Note:
> Below comments are raised during V7 discussion:
> 
> Currently SKIP() is applied to FIXTURE_SETUP, FIXTURE_TEARDOWN,
> TEST_F_FORK, this is because SKIP() apply within the function
> scope, not the testcase.
> 
> We would like test infra to have a dedicated environment
> check hook (FIXTURE_ENV_CHECK) in test infra, called before
> FIXTURE_SETUP(). If the environment check fails, the remaining
> of the test will be skipped. The benefit of these are two:
> 1> if env check pass, in theory, the test should pass.
> 2> if env check fail, no need to call setup, so no need to cleanup
> resource.
> 
> v8:
> style change, no logic change.
> 
> v7:
> https://lore.kernel.org/all/20221229211446.3154454-1-jeffxu@google.com/
> Fix bug in supports_overlayfs().
> Manual test with kernel with and without overlayfs.
> 
> v6: https://lore.kernel.org/all/20221229201215.3006512-1-jeffxu@google.com/
> In v4, the SKIP() was applied at FIXTURE_SETUP() after mount() fail,
> however, FIXTURE_TEARDOWN() will fail. It might be complicated
> for test infra or testcase itself to have cleanup code handing the
> success/failure of steps in SETUP().
> 
> This patch changes the approach, it calls supports_overlay() and SKIP()
> at the beginning of FIXTURE_SETUP(), FIX_TEARDOWN(), TEST_F_FORK().
> Because no modification of system is done by the test, cleanup is not
> needed.
> 
> v4:
> https://lore.kernel.org/all/20220823010216.2653012-1-jeffxu@google.com/
> 
> 
> Jeff Xu (1):
>    selftests/landlock: skip overlayfs test when not support
> 
>   tools/testing/selftests/landlock/fs_test.c | 48 ++++++++++++++++++++++
>   1 file changed, 48 insertions(+)
> 
> 
> base-commit: 963a70bee5880640d0fd83ed29dc1e7ec0d2bd4a

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs
  2023-01-13 19:58 ` [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs Mickaël Salaün
@ 2023-01-14  2:17   ` Jeff Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff Xu @ 2023-01-14  2:17 UTC (permalink / raw)
  To: Mickaël Salaün
  Cc: jeffxu, jorgelo, keescook, linux-security-module, groeck, gnoack

Awesome, thanks!

On Fri, Jan 13, 2023 at 11:58 AM Mickaël Salaün <mic@digikod.net> wrote:
>
> Thanks Jeff! I pushed this patch in -next:
> https://git.kernel.org/pub/scm/linux/kernel/git/mic/linux.git/log/?h=next
>
>
> On 13/01/2023 06:32, jeffxu@chromium.org wrote:
> > From: Jeff Xu <jeffxu@google.com>
> >
> > Overlayfs can be disabled in kernel config, causing related tests to
> > fail. Adding a check for overlayfs’s supportability at runtime,
> > so we can call SKIP() when needed.
> >
> > Note:
> > Below comments are raised during V7 discussion:
> >
> > Currently SKIP() is applied to FIXTURE_SETUP, FIXTURE_TEARDOWN,
> > TEST_F_FORK, this is because SKIP() apply within the function
> > scope, not the testcase.
> >
> > We would like test infra to have a dedicated environment
> > check hook (FIXTURE_ENV_CHECK) in test infra, called before
> > FIXTURE_SETUP(). If the environment check fails, the remaining
> > of the test will be skipped. The benefit of these are two:
> > 1> if env check pass, in theory, the test should pass.
> > 2> if env check fail, no need to call setup, so no need to cleanup
> > resource.
> >
> > v8:
> > style change, no logic change.
> >
> > v7:
> > https://lore.kernel.org/all/20221229211446.3154454-1-jeffxu@google.com/
> > Fix bug in supports_overlayfs().
> > Manual test with kernel with and without overlayfs.
> >
> > v6: https://lore.kernel.org/all/20221229201215.3006512-1-jeffxu@google.com/
> > In v4, the SKIP() was applied at FIXTURE_SETUP() after mount() fail,
> > however, FIXTURE_TEARDOWN() will fail. It might be complicated
> > for test infra or testcase itself to have cleanup code handing the
> > success/failure of steps in SETUP().
> >
> > This patch changes the approach, it calls supports_overlay() and SKIP()
> > at the beginning of FIXTURE_SETUP(), FIX_TEARDOWN(), TEST_F_FORK().
> > Because no modification of system is done by the test, cleanup is not
> > needed.
> >
> > v4:
> > https://lore.kernel.org/all/20220823010216.2653012-1-jeffxu@google.com/
> >
> >
> > Jeff Xu (1):
> >    selftests/landlock: skip overlayfs test when not support
> >
> >   tools/testing/selftests/landlock/fs_test.c | 48 ++++++++++++++++++++++
> >   1 file changed, 48 insertions(+)
> >
> >
> > base-commit: 963a70bee5880640d0fd83ed29dc1e7ec0d2bd4a

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-01-14  2:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-01-13  5:32 [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs jeffxu
2023-01-13  5:32 ` [PATCH v8 1/1] selftests/landlock: skip overlayfs test when not support jeffxu
2023-01-13 19:58 ` [PATCH v8 0/1] selftests/landlock: fix fs_tests when overlayfs Mickaël Salaün
2023-01-14  2:17   ` Jeff Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).