* [PATCH v2] selftests/landlock: skip overlayfs test when kernel not support it
@ 2022-08-22 16:25 jeffxu
2022-08-22 16:36 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: jeffxu @ 2022-08-22 16:25 UTC (permalink / raw)
To: mic; +Cc: jorgelo, keescook, linux-security-module, groeck, Jeff Xu, 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@chromium.org>
Change-Id: Ica94d677d6c11e8f2460e07d1b432be077946324
---
tools/testing/selftests/landlock/fs_test.c | 62 ++++++++++++++++++++--
1 file changed, 58 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
index 21a2ce8fa739..3a4c52619b46 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>
@@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";
static const char dir_s3d2[] = TMP_DIR "/s3d1/s3d2";
static const char dir_s3d3[] = TMP_DIR "/s3d1/s3d2/s3d3";
+static const char proc_filesystems[] = "/proc/filesystems";
/*
* layout1 hierarchy:
*
@@ -169,6 +171,49 @@ static int remove_path(const char *const path)
return err;
}
+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)
+{
+ char *res;
+ bool ret = false;
+ FILE *inf = fopen(proc_filesystems, "r");
+
+ /*
+ * If fopen failed, return supported.
+ * This help detect missing file (shall not
+ * happen).
+ */
+ if (!inf)
+ return true;
+
+ ret = fgrep(inf, "nodev\toverlay\n");
+
+ if (res) {
+ free(res);
+ }
+
+ fclose(inf);
+
+ return ret;
+}
+
+
static void prepare_layout(struct __test_metadata *const _metadata)
{
disable_caps(_metadata);
@@ -3397,13 +3442,14 @@ static const char (*merge_sub_files[])[] = {
* └── work
* └── work
*/
-
/* clang-format off */
FIXTURE(layout2_overlay) {};
/* clang-format on */
FIXTURE_SETUP(layout2_overlay)
{
+ int rc;
+
prepare_layout(_metadata);
create_directory(_metadata, LOWER_BASE);
@@ -3431,11 +3477,19 @@ FIXTURE_SETUP(layout2_overlay)
create_directory(_metadata, MERGE_DATA);
set_cap(_metadata, CAP_SYS_ADMIN);
set_cap(_metadata, CAP_DAC_OVERRIDE);
- ASSERT_EQ(0, mount("overlay", MERGE_DATA, "overlay", 0,
- "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
- ",workdir=" UPPER_WORK));
+
+ rc = mount("overlay", MERGE_DATA, "overlay", 0,
+ "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
+ ",workdir=" UPPER_WORK);
clear_cap(_metadata, CAP_DAC_OVERRIDE);
clear_cap(_metadata, CAP_SYS_ADMIN);
+
+ if (rc < 0) {
+ ASSERT_EQ(ENODEV, errno);
+ ASSERT_FALSE(supports_overlayfs());
+ SKIP(return, "overlayfs is not supported");
+ }
+
}
FIXTURE_TEARDOWN(layout2_overlay)
base-commit: 50cd95ac46548429e5bba7ca75cc97d11a697947
--
2.37.1.595.g718a3a8f04-goog
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests/landlock: skip overlayfs test when kernel not support it
2022-08-22 16:25 [PATCH v2] selftests/landlock: skip overlayfs test when kernel not support it jeffxu
@ 2022-08-22 16:36 ` Guenter Roeck
2022-08-22 17:01 ` Jeff Xu
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2022-08-22 16:36 UTC (permalink / raw)
To: Jeff Xu
Cc: Mickaël Salaün, Jorge Lucangeli Obes, Kees Cook,
linux-security-module, Guenter Roeck, Jeff Xu
On Mon, Aug 22, 2022 at 9:25 AM <jeffxu@google.com> wrote:
>
> 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@chromium.org>
> Change-Id: Ica94d677d6c11e8f2460e07d1b432be077946324
No Change-Id in upstream patches
> ---
> tools/testing/selftests/landlock/fs_test.c | 62 ++++++++++++++++++++--
> 1 file changed, 58 insertions(+), 4 deletions(-)
>
> diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> index 21a2ce8fa739..3a4c52619b46 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>
> @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";
> static const char dir_s3d2[] = TMP_DIR "/s3d1/s3d2";
> static const char dir_s3d3[] = TMP_DIR "/s3d1/s3d2/s3d3";
>
> +static const char proc_filesystems[] = "/proc/filesystems";
> /*
> * layout1 hierarchy:
> *
> @@ -169,6 +171,49 @@ static int remove_path(const char *const path)
> return err;
> }
>
> +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)
> +{
> + char *res;
> + bool ret = false;
> + FILE *inf = fopen(proc_filesystems, "r");
> +
> + /*
> + * If fopen failed, return supported.
> + * This help detect missing file (shall not
> + * happen).
> + */
> + if (!inf)
> + return true;
> +
> + ret = fgrep(inf, "nodev\toverlay\n");
> +
> + if (res) {
> + free(res);
> + }
I don't see where res is allocated or used.
> +
> + fclose(inf);
> +
> + return ret;
> +}
> +
> +
> static void prepare_layout(struct __test_metadata *const _metadata)
> {
> disable_caps(_metadata);
> @@ -3397,13 +3442,14 @@ static const char (*merge_sub_files[])[] = {
> * └── work
> * └── work
> */
> -
> /* clang-format off */
> FIXTURE(layout2_overlay) {};
> /* clang-format on */
>
> FIXTURE_SETUP(layout2_overlay)
> {
> + int rc;
> +
> prepare_layout(_metadata);
>
> create_directory(_metadata, LOWER_BASE);
> @@ -3431,11 +3477,19 @@ FIXTURE_SETUP(layout2_overlay)
> create_directory(_metadata, MERGE_DATA);
> set_cap(_metadata, CAP_SYS_ADMIN);
> set_cap(_metadata, CAP_DAC_OVERRIDE);
> - ASSERT_EQ(0, mount("overlay", MERGE_DATA, "overlay", 0,
> - "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
> - ",workdir=" UPPER_WORK));
> +
> + rc = mount("overlay", MERGE_DATA, "overlay", 0,
> + "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
> + ",workdir=" UPPER_WORK);
> clear_cap(_metadata, CAP_DAC_OVERRIDE);
> clear_cap(_metadata, CAP_SYS_ADMIN);
> +
> + if (rc < 0) {
> + ASSERT_EQ(ENODEV, errno);
> + ASSERT_FALSE(supports_overlayfs());
> + SKIP(return, "overlayfs is not supported");
> + }
> +
> }
>
> FIXTURE_TEARDOWN(layout2_overlay)
>
> base-commit: 50cd95ac46548429e5bba7ca75cc97d11a697947
> --
> 2.37.1.595.g718a3a8f04-goog
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] selftests/landlock: skip overlayfs test when kernel not support it
2022-08-22 16:36 ` Guenter Roeck
@ 2022-08-22 17:01 ` Jeff Xu
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Xu @ 2022-08-22 17:01 UTC (permalink / raw)
To: Guenter Roeck
Cc: Mickaël Salaün, Jorge Lucangeli Obes, Kees Cook,
linux-security-module, Guenter Roeck, Jeff Xu
> No Change-Id in upstream patches
>
> I don't see where res is allocated or used.
Thank you for catching this. Sent out V3 patch
On Mon, Aug 22, 2022 at 9:37 AM Guenter Roeck <groeck@google.com> wrote:
>
> On Mon, Aug 22, 2022 at 9:25 AM <jeffxu@google.com> wrote:
> >
> > 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@chromium.org>
> > Change-Id: Ica94d677d6c11e8f2460e07d1b432be077946324
>
> No Change-Id in upstream patches
>
> > ---
> > tools/testing/selftests/landlock/fs_test.c | 62 ++++++++++++++++++++--
> > 1 file changed, 58 insertions(+), 4 deletions(-)
> >
> > diff --git a/tools/testing/selftests/landlock/fs_test.c b/tools/testing/selftests/landlock/fs_test.c
> > index 21a2ce8fa739..3a4c52619b46 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>
> > @@ -62,6 +63,7 @@ static const char dir_s3d1[] = TMP_DIR "/s3d1";
> > static const char dir_s3d2[] = TMP_DIR "/s3d1/s3d2";
> > static const char dir_s3d3[] = TMP_DIR "/s3d1/s3d2/s3d3";
> >
> > +static const char proc_filesystems[] = "/proc/filesystems";
> > /*
> > * layout1 hierarchy:
> > *
> > @@ -169,6 +171,49 @@ static int remove_path(const char *const path)
> > return err;
> > }
> >
> > +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)
> > +{
> > + char *res;
> > + bool ret = false;
> > + FILE *inf = fopen(proc_filesystems, "r");
> > +
> > + /*
> > + * If fopen failed, return supported.
> > + * This help detect missing file (shall not
> > + * happen).
> > + */
> > + if (!inf)
> > + return true;
> > +
> > + ret = fgrep(inf, "nodev\toverlay\n");
> > +
> > + if (res) {
> > + free(res);
> > + }
>
> I don't see where res is allocated or used.
>
> > +
> > + fclose(inf);
> > +
> > + return ret;
> > +}
> > +
> > +
> > static void prepare_layout(struct __test_metadata *const _metadata)
> > {
> > disable_caps(_metadata);
> > @@ -3397,13 +3442,14 @@ static const char (*merge_sub_files[])[] = {
> > * └── work
> > * └── work
> > */
> > -
> > /* clang-format off */
> > FIXTURE(layout2_overlay) {};
> > /* clang-format on */
> >
> > FIXTURE_SETUP(layout2_overlay)
> > {
> > + int rc;
> > +
> > prepare_layout(_metadata);
> >
> > create_directory(_metadata, LOWER_BASE);
> > @@ -3431,11 +3477,19 @@ FIXTURE_SETUP(layout2_overlay)
> > create_directory(_metadata, MERGE_DATA);
> > set_cap(_metadata, CAP_SYS_ADMIN);
> > set_cap(_metadata, CAP_DAC_OVERRIDE);
> > - ASSERT_EQ(0, mount("overlay", MERGE_DATA, "overlay", 0,
> > - "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
> > - ",workdir=" UPPER_WORK));
> > +
> > + rc = mount("overlay", MERGE_DATA, "overlay", 0,
> > + "lowerdir=" LOWER_DATA ",upperdir=" UPPER_DATA
> > + ",workdir=" UPPER_WORK);
> > clear_cap(_metadata, CAP_DAC_OVERRIDE);
> > clear_cap(_metadata, CAP_SYS_ADMIN);
> > +
> > + if (rc < 0) {
> > + ASSERT_EQ(ENODEV, errno);
> > + ASSERT_FALSE(supports_overlayfs());
> > + SKIP(return, "overlayfs is not supported");
> > + }
> > +
> > }
> >
> > FIXTURE_TEARDOWN(layout2_overlay)
> >
> > base-commit: 50cd95ac46548429e5bba7ca75cc97d11a697947
> > --
> > 2.37.1.595.g718a3a8f04-goog
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-22 17:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 16:25 [PATCH v2] selftests/landlock: skip overlayfs test when kernel not support it jeffxu
2022-08-22 16:36 ` Guenter Roeck
2022-08-22 17:01 ` Jeff Xu
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.