public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: Li Wang <liwang@redhat.com>, Andrea Cervesato <andrea.cervesato@suse.de>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 09/10] Add landlock05 test
Date: Wed, 3 Jul 2024 09:36:54 +0200	[thread overview]
Message-ID: <eb9fffd4-2cca-40d6-b0f3-bca0ee5cfdba@suse.com> (raw)
In-Reply-To: <CAEemH2dWxNg317Fx+pvRM=3v6Ddh2mHWLe-1_VKPO9DFpGcuoA@mail.gmail.com>

On 7/3/24 09:32, Li Wang wrote:
>
>
> On Mon, Jul 1, 2024 at 11:45 PM Andrea Cervesato 
> <andrea.cervesato@suse.de> wrote:
>
>     From: Andrea Cervesato <andrea.cervesato@suse.com>
>
>     This test verifies LANDLOCK_ACCESS_FS_REFER access in the
>     landlock sandbox. The feature is available since kernel 5.19.
>
>     Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
>
>
> Reviewed-by: Li Wang <liwang@redhat.com>
>
>     ---
>      runtest/syscalls                                |   1 +
>      testcases/kernel/syscalls/landlock/.gitignore   |   1 +
>      testcases/kernel/syscalls/landlock/landlock05.c | 113
>     ++++++++++++++++++++++++
>      3 files changed, 115 insertions(+)
>
>     diff --git a/runtest/syscalls b/runtest/syscalls
>     index 9acdaf760..a3ade6dc1 100644
>     --- a/runtest/syscalls
>     +++ b/runtest/syscalls
>     @@ -688,6 +688,7 @@ landlock01 landlock01
>      landlock02 landlock02
>      landlock03 landlock03
>      landlock04 landlock04
>     +landlock05 landlock05
>
>      lchown01 lchown01
>      lchown01_16 lchown01_16
>     diff --git a/testcases/kernel/syscalls/landlock/.gitignore
>     b/testcases/kernel/syscalls/landlock/.gitignore
>     index 4fe8d7cba..a7ea6be2e 100644
>     --- a/testcases/kernel/syscalls/landlock/.gitignore
>     +++ b/testcases/kernel/syscalls/landlock/.gitignore
>     @@ -3,3 +3,4 @@ landlock01
>      landlock02
>      landlock03
>      landlock04
>     +landlock05
>     diff --git a/testcases/kernel/syscalls/landlock/landlock05.c
>     b/testcases/kernel/syscalls/landlock/landlock05.c
>     new file mode 100644
>     index 000000000..57ed67e9f
>     --- /dev/null
>     +++ b/testcases/kernel/syscalls/landlock/landlock05.c
>     @@ -0,0 +1,113 @@
>     +// SPDX-License-Identifier: GPL-2.0-or-later
>     +/*
>     + * Copyright (C) 2024 SUSE LLC Andrea Cervesato
>     <andrea.cervesato@suse.com>
>     + */
>     +
>     +/*\
>     + * [Description]
>     + *
>     + * This test verifies LANDLOCK_ACCESS_FS_REFER access in the
>     + * landlock sandbox.
>     + *
>     + * [Algorithm]
>     + *
>     + * - apply LANDLOCK_ACCESS_FS_REFER in the folder1
>     + * - apply LANDLOCK_ACCESS_FS_REFER in the folder2
>     + * - create folder3
>     + * - verify that file can be moved from folder1 to folder2
>     + * - verify that file can't be moved from folder1 to folder3
>     + */
>     +
>     +#include "landlock_common.h"
>     +
>     +#define MNTPOINT "sandbox"
>     +#define DIR1 MNTPOINT"/folder1"
>     +#define DIR2 MNTPOINT"/folder2"
>     +#define DIR3 MNTPOINT"/folder3"
>     +#define FILENAME1 DIR1"/file"
>     +#define FILENAME2 DIR2"/file"
>     +#define FILENAME3 DIR3"/file"
>     +
>     +static struct landlock_ruleset_attr *ruleset_attr;
>     +static struct landlock_path_beneath_attr *path_beneath_attr;
>     +
>     +static void run(void)
>     +{
>     +       if (!SAFE_FORK()) {
>
>
> Do we really need a fork and test in children here?
>
Yeah, the reason is that sandbox is activated for the entire process. 
That means temporary folder cleanup might be affected when we force 
read-only rule.
>
>     +               TST_EXP_PASS(rename(FILENAME1, FILENAME2));
>     +               if (TST_RET == -1)
>     +                       return;
>     +
>     +               TST_EXP_FAIL(rename(FILENAME2, FILENAME3), EXDEV);
>     +
>     +               _exit(0);
>     +       }
>     +}
>     +
>     +static void setup(void)
>     +{
>     +       int ruleset_fd;
>     +
>     +       verify_landlock_is_enabled();
>     +
>     +       SAFE_MKDIR(DIR1, 0640);
>     +       SAFE_MKDIR(DIR2, 0640);
>     +       SAFE_MKDIR(DIR3, 0640);
>     +       SAFE_TOUCH(FILENAME1, 0640, NULL);
>     +
>     +       tst_res(TINFO, "Applying LANDLOCK_ACCESS_FS_REFER");
>     +
>     +       ruleset_attr->handled_access_fs =
>     +               LANDLOCK_ACCESS_FS_READ_FILE |
>     +               LANDLOCK_ACCESS_FS_WRITE_FILE |
>     +               LANDLOCK_ACCESS_FS_REFER;
>     +
>     +       ruleset_fd = SAFE_LANDLOCK_CREATE_RULESET(
>     +               ruleset_attr, sizeof(struct
>     landlock_ruleset_attr), 0);
>     +
>     +       apply_landlock_rule(
>     +               path_beneath_attr,
>     +               ruleset_fd,
>     +               LANDLOCK_ACCESS_FS_REFER,
>     +               DIR1);
>     +
>     +       apply_landlock_rule(
>     +               path_beneath_attr,
>     +               ruleset_fd,
>     +               LANDLOCK_ACCESS_FS_REFER,
>     +               DIR2);
>     +
>     +       enforce_ruleset(ruleset_fd);
>     +
>     +       SAFE_CLOSE(ruleset_fd);
>     +}
>     +
>     +static struct tst_test test = {
>     +       .test_all = run,
>     +       .setup = setup,
>     +       .min_kver = "5.19",
>     +       .needs_tmpdir = 1,
>     +       .needs_root = 1,
>     +       .forks_child = 1,
>     +       .needs_kconfigs = (const char *[]) {
>     +               "CONFIG_SECURITY_LANDLOCK=y",
>     +               NULL
>     +       },
>     +       .bufs = (struct tst_buffers []) {
>     +               {&ruleset_attr, .size = sizeof(struct
>     landlock_ruleset_attr)},
>     +               {&path_beneath_attr, .size = sizeof(struct
>     landlock_path_beneath_attr)},
>     +               {},
>     +       },
>     +       .caps = (struct tst_cap []) {
>     +               TST_CAP(TST_CAP_REQ, CAP_SYS_ADMIN),
>     +               {}
>     +       },
>     +       .format_device = 1,
>     +       .mount_device = 1,
>     +       .mntpoint = MNTPOINT,
>     +       .all_filesystems = 1,
>     +       .skip_filesystems = (const char *[]) {
>     +               "vfat",
>     +               NULL
>     +       },
>     +};
>
>     -- 
>     2.43.0
>
>
>     -- 
>     Mailing list info: https://lists.linux.it/listinfo/ltp
>
>
>
> -- 
> Regards,
> Li Wang

Andrea

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-07-03  7:37 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-01 15:42 [LTP] [PATCH 00/10] landlock testing suite Andrea Cervesato
2024-07-01 15:42 ` [LTP] [PATCH 01/10] Add landlock syscalls definitions Andrea Cervesato
2024-07-02  7:30   ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 02/10] Add lapi/landlock.h fallback Andrea Cervesato
2024-07-02  7:32   ` Li Wang
2024-07-02  7:41     ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 03/10] Add landlock SAFE_* macros Andrea Cervesato
2024-07-02  7:47   ` Li Wang
2024-07-10 15:53   ` Petr Vorel
2024-07-10 17:53     ` Andrea Cervesato via ltp
2024-07-11  5:27       ` Petr Vorel
2024-07-11  6:30         ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 04/10] Add SAFE_PRCTL macro Andrea Cervesato
2024-07-02  7:52   ` Li Wang
2024-07-10 15:47   ` Petr Vorel
2024-07-01 15:42 ` [LTP] [PATCH 05/10] Add landlock01 test Andrea Cervesato
2024-07-02  8:34   ` Li Wang
2024-07-02  9:09     ` Li Wang
2024-07-02  9:20       ` Andrea Cervesato via ltp
2024-07-02  9:54         ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 06/10] Add landlock02 test Andrea Cervesato
2024-07-02  8:46   ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 07/10] Add landlock03 test Andrea Cervesato
2024-07-02 11:00   ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 08/10] Add landlock04 test Andrea Cervesato
2024-07-02  8:00   ` Li Wang
2024-07-02 12:22     ` Li Wang
2024-07-03 13:42       ` Andrea Cervesato via ltp
2024-07-04  1:53         ` Li Wang
2024-07-03  8:20   ` Li Wang
2024-07-03  9:22     ` Andrea Cervesato via ltp
2024-07-01 15:42 ` [LTP] [PATCH 09/10] Add landlock05 test Andrea Cervesato
2024-07-03  7:32   ` Li Wang
2024-07-03  7:36     ` Andrea Cervesato via ltp [this message]
2024-07-03  7:40       ` Li Wang
2024-07-01 15:42 ` [LTP] [PATCH 10/10] Add landlock06 test Andrea Cervesato
2024-07-03 13:29   ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eb9fffd4-2cca-40d6-b0f3-bca0ee5cfdba@suse.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@suse.com \
    --cc=andrea.cervesato@suse.de \
    --cc=liwang@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox