public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: "Mickaël Salaün" <mic@digikod.net>
To: Andrea Cervesato <andrea.cervesato@suse.com>
Cc: "Günther Noack" <gnoack@google.com>,
	ltp@lists.linux.it, landlock@lists.linux.dev
Subject: Re: [LTP] LTP landlock test is failing for all kernels <= 6.6
Date: Thu, 25 Jul 2024 11:06:46 +0200	[thread overview]
Message-ID: <20240725.Sohsez7coh2t@digikod.net> (raw)
In-Reply-To: <54317d90-ec53-49ff-bbff-15200f09c8d2@suse.com>

Hi Andrea,

On Thu, Jul 25, 2024 at 09:50:36AM +0200, Andrea Cervesato wrote:
> Hi all,
> 
> we are facing an issue with landlock support in kernels <=6.6. We have a
> test that takes in consideration all possible rules set and enable only one
> of them, checking that all the others are raising a permission error.
> The test can be found here:
> https://github.com/acerv/ltp/commit/9b1d6838592cebe3c89282a7339db543be2a00e7

There is definitely an issue in this commit.  ALL_RULES contains all
access right, mixing filesystem and network ones, which doesn't make
sense because they don't have the same "namespace".
LANDLOCK_ACCESS_NET_* and LANDLOCK_ACCESS_FS_* bits overlaps.
The tester_get_all_rules() function does the ABI checks and removes the
LANDLOCK_ACCESS_NET_{BIND,CONNECT}_TCP bits if they are not supported
(in the handled_access_net namespace), which is the same as removing
LANDLOCK_ACCESS_FS_{EXECUTE,WRITE_FILE} whereas they are supported (in
the handled_access_fs namespace).

> It work fine for all kernels >= 6.7.

LANDLOCK_ACCESS_NET_{BIND,CONNECT}_TCP were introduced with this kernel
(Landlock ABI 4), so I guess that's the issue.

> 
> Below you will find the discussion in the LTP mailing list. Can you please
> give any help with this?
> 
> Regards,
> Andrea
> 
> 
> 
> -------- Forwarded Message --------
> Subject: 	Re: [LTP] [PATCH v3 09/11] Add landlock04 test
> Date: 	Thu, 25 Jul 2024 09:12:39 +0200
> From: 	Andrea Cervesato <andrea.cervesato@suse.com>
> To: 	Li Wang <liwang@redhat.com>, Petr Vorel <pvorel@suse.cz>
> CC: 	Andrea Cervesato <andrea.cervesato@suse.de>, ltp@lists.linux.it,
> Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
> 
> 
> 
> Hi!
> 
> it seems like the landlock() support in kernel 6.6 is different than the one
> in 6.7. The reason why we see that error in kernel <=6.6 is related to how
> landlock is handling the rules set according to the rule we want to enable.
> 
> Let's suppose we want to enable the execution for a file. What we should be
> able to do, is to consider __ALL__ the rules available for landlock, then to
> enable EXEC only for a specific file. Then, if we make any other operation
> that is not EXEC, we should have a permission error. This translates to:
> 
> - set ruleset_attr->handled_access_fs for all available LANDLOCK_ACCESS_FS_*
> rules
> - set path_beneath_attr->allowed_access to LANDLOCK_ACCESS_FS_EXEC |
> LANDLOCK_ACCESS_FS_READ (we need to read in order to execute) for a binary
> - enforce the rules inside a sandbox containing the binary
> - execute the binary will work
> - do any other operation inside the sandbox and obtain a permissions error
> - at this point, any new rule that is added, will update the list of
> landlock rules, enabling the sandbox permissions
> 
> For some reasons that I don't know (and this is evident from kselftests as
> well), if the initial rules set (ruleset_attr->handled_access_fs) is not
> identical to the rules we are going to enable
> (path_beneath_attr->allowed_access), landlock_add_rule() will fail with
> EINVAL. And this is our case for all kernels <=6.6.

path_beneath_attr->allowed_access needs to be a subset of
ruleset_attr->handled_access_fs, otherwise it doesn't make sense to
allow something which is not handled/denied.

> 
> I really have no idea why this happens and maybe we need to contact the
> landlock developers.

Feel free to Cc me and Günther for all Landlock-related patches.

> 
> Andrea
> 
> On 7/24/24 15:47, Andrea Cervesato wrote:
> > Hi Li,
> > 
> > thanks for checking. Mmmh I don't know if it's because they added
> > LANDLOCK_RULE_NET_PORT. It sounds strange to me, since that would break
> > all the other features.
> > 
> > Andrea
> > 
> > On 7/24/24 14:12, Li Wang wrote:
> > > Hi Petr, Andrea,
> > > 
> > > On Wed, Jul 17, 2024 at 1:27 AM Petr Vorel <pvorel@suse.cz> wrote:
> > > 
> > >     Hi Andrea,
> > > 
> > >     ...
> > >     > +static void enable_exec_libs(const int ruleset_fd)
> > >     > +{
> > >     > +     FILE *fp;
> > >     > +     char line[1024];
> > >     > +     char path[PATH_MAX];
> > >     > +     char dependency[8][PATH_MAX];
> > >     > +     int count = 0;
> > >     > +     int duplicate = 0;
> > >     > +
> > >     > +     fp = SAFE_FOPEN("/proc/self/maps", "r");
> > >     > +
> > >     > +     while (fgets(line, sizeof(line), fp)) {
> > >     > +             if (strstr(line, ".so") == NULL)
> > >     > +                     continue;
> > >     > +
> > >     > +             SAFE_SSCANF(line, "%*x-%*x %*s %*x %*s %*d %s",
> > >     path);
> > >     > +
> > >     > +             for (int i = 0; i < count; i++) {
> > >     > +                     if (strcmp(path, dependency[i]) == 0) {
> > >     > +                             duplicate = 1;
> > >     > +                             break;
> > >     > +                     }
> > >     > +             }
> > >     > +
> > >     > +             if (duplicate) {
> > >     > +                     duplicate = 0;
> > >     > +                     continue;
> > >     > +             }
> > >     > +
> > >     > +             strncpy(dependency[count], path, PATH_MAX);
> > >     > +             count++;
> > >     > +
> > >     > +             tst_res(TINFO, "Enable read/exec permissions for
> > >     %s", path);
> > >     > +
> > >     > +             path_beneath_attr->allowed_access =
> > >     > +                     LANDLOCK_ACCESS_FS_READ_FILE |
> > >     > +                     LANDLOCK_ACCESS_FS_EXECUTE;
> > >     > +             path_beneath_attr->parent_fd = SAFE_OPEN(path,
> > >     O_PATH | O_CLOEXEC);
> > >     > +
> > >     > +             SAFE_LANDLOCK_ADD_RULE(
> > >     > +                     ruleset_fd,
> > >     > +                     LANDLOCK_RULE_PATH_BENEATH,
> > >     > +                     path_beneath_attr,
> > >     > +                     0);
> > > 
> > >     Unfortunately, on 6.6.15-amd64 kernel (random Debian machine) it
> > >     fails (after
> > >     fresh boot) with:
> > > 
> > >     ...
> > >     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:1746: TINFO: === Testing on ext2 ===
> > >     tst_test.c:1111: TINFO: Formatting /dev/loop1 with ext2 opts=''
> > >     extra opts=''
> > >     mke2fs 1.47.0 (5-Feb-2023)
> > >     tst_test.c:1123: TINFO: Mounting /dev/loop1 to
> > >     /tmp/LTP_lant6WbKJ/sandbox fstyp=ext2 flags=0
> > >     landlock_common.h:30: TINFO: Landlock ABI v3
> > >     landlock04.c:151: TINFO: Testing LANDLOCK_ACCESS_FS_EXECUTE
> > >     landlock04.c:123: TINFO: Enable read/exec permissions for
> > >     /usr/lib/i386-linux-gnu/libc.so.6
> > >     landlock04.c:131: TBROK: landlock_add_rule(3, 1, 0xf7f13ff4, 0):
> > >     EINVAL (22)
> > > 
> > > 
> > > Possibly that's because the 'LANDLOCK_RULE_PATH_BENEATH'  was
> > > refactored from the v6.7 mainline kernel, so it can't add the rule
> > > correctly
> > > with older kernels.
> > > 
> > > commit 0e0fc7e8eb4a11bd9f89a9c74bc7c0e144c56203
> > > Author: Konstantin Meskhidze <konstantin.meskhidze@huawei.com>
> > > Date:   Thu Oct 26 09:47:46 2023 +0800
> > > 
> > >     landlock: Refactor landlock_add_rule() syscall
> > > 
> > > But this is my guess (through reading the code), I didn't do more to
> > > verify that by installing such a kernel.
> > > 
> > > 
> > > -- 
> > > Regards,
> > > Li Wang
> > 
> > 
> 
> 

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

  parent reply	other threads:[~2024-07-25  9:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-11 11:18 [LTP] [PATCH v3 00/11] landlock testing suite Andrea Cervesato
2024-07-11 11:18 ` [LTP] [PATCH v3 01/11] Add landlock syscalls definitions Andrea Cervesato
2024-07-11 11:18 ` [LTP] [PATCH v3 02/11] Add lapi/landlock.h fallback Andrea Cervesato
2024-07-11 11:18 ` [LTP] [PATCH v3 03/11] Added three more SAFE_* macros for landlock sandbox: Andrea Cervesato
2024-07-11 11:18 ` [LTP] [PATCH v3 04/11] Add SAFE_PRCTL macro Andrea Cervesato
2024-07-11 20:06   ` Petr Vorel
2024-07-11 11:18 ` [LTP] [PATCH v3 05/11] Add landlock01 test Andrea Cervesato
2024-07-11 20:40   ` Petr Vorel
2024-07-12  2:11     ` Li Wang
2024-07-12  3:03       ` Li Wang
2024-07-12  7:57         ` Petr Vorel
2024-07-12  8:28           ` Li Wang
2024-07-12  9:22             ` Petr Vorel
2024-07-12  7:07       ` Petr Vorel
2024-07-11 11:18 ` [LTP] [PATCH v3 06/11] Add landlock02 test Andrea Cervesato
2024-07-11 20:32   ` Petr Vorel
2024-07-16 16:59     ` Petr Vorel
2024-07-11 11:18 ` [LTP] [PATCH v3 07/11] Add landlock03 test Andrea Cervesato
2024-07-16 17:15   ` Petr Vorel
2024-07-11 11:18 ` [LTP] [PATCH v3 08/11] Add CAP_MKNOD fallback in lapi/capability.h Andrea Cervesato
2024-07-12  7:49   ` Li Wang
2024-07-11 11:18 ` [LTP] [PATCH v3 09/11] Add landlock04 test Andrea Cervesato
2024-07-12  7:50   ` Li Wang
2024-07-16 17:27   ` Petr Vorel
2024-07-24 10:41     ` Andrea Cervesato via ltp
2024-07-24 12:12     ` Li Wang
2024-07-24 13:30       ` Petr Vorel
2024-07-24 13:37         ` Li Wang
2024-07-24 13:41           ` Petr Vorel
2024-07-24 13:41           ` Li Wang
2024-07-24 13:47       ` Andrea Cervesato via ltp
2024-07-25  7:12         ` Andrea Cervesato via ltp
     [not found]           ` <54317d90-ec53-49ff-bbff-15200f09c8d2@suse.com>
2024-07-25  9:06             ` Mickaël Salaün [this message]
2024-07-25  9:17               ` [LTP] LTP landlock test is failing for all kernels <= 6.6 Andrea Cervesato via ltp
2024-07-11 11:18 ` [LTP] [PATCH v3 10/11] Add landlock05 test Andrea Cervesato
2024-07-11 11:18 ` [LTP] [PATCH v3 11/11] Add landlock06 test Andrea Cervesato

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=20240725.Sohsez7coh2t@digikod.net \
    --to=mic@digikod.net \
    --cc=andrea.cervesato@suse.com \
    --cc=gnoack@google.com \
    --cc=landlock@lists.linux.dev \
    --cc=ltp@lists.linux.it \
    /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