]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add support for landlock_create_ruleset (444), landlock_add_rule (445) and landlock_r...
authorPeter Seiderer <ps.report@gmx.net>
Mon, 8 Jul 2024 09:05:47 +0000 (11:05 +0200)
committerMark Wielaard <mark@klomp.org>
Mon, 25 Nov 2024 01:44:43 +0000 (02:44 +0100)
- add support for landlock_create_ruleset (444) syscall
- add support for landlock_add_rule (445) syscall
- add support for landlock_restrict_self (446) syscall

https://bugs.kde.org/show_bug.cgi?id=489913

Signed-off-by: Peter Seiderer <ps.report@gmx.net>
17 files changed:
NEWS
coregrind/m_syswrap/priv_syswrap-linux.h
coregrind/m_syswrap/syswrap-amd64-linux.c
coregrind/m_syswrap/syswrap-arm-linux.c
coregrind/m_syswrap/syswrap-arm64-linux.c
coregrind/m_syswrap/syswrap-linux.c
coregrind/m_syswrap/syswrap-mips32-linux.c
coregrind/m_syswrap/syswrap-mips64-linux.c
coregrind/m_syswrap/syswrap-nanomips-linux.c
coregrind/m_syswrap/syswrap-ppc32-linux.c
coregrind/m_syswrap/syswrap-ppc64-linux.c
coregrind/m_syswrap/syswrap-s390x-linux.c
coregrind/m_syswrap/syswrap-x86-linux.c
include/Makefile.am
include/pub_tool_vki.h
include/vki/vki-linux-landlock.h [new file with mode: 0644]
include/vki/vki-scnums-shared-linux.h

diff --git a/NEWS b/NEWS
index ad5fa1a417effa773f1e7e3bc55aa071141c529f..e5a7345e17a0171828c4f5be6d44e83cba86a691 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -23,6 +23,7 @@ bugzilla (https://bugs.kde.org/enter_bug.cgi?product=valgrind) rather
 than mailing the developers (or mailing lists) directly -- bugs that
 are not entered into bugzilla tend to get forgotten about or ignored.
 
+489913  WARNING: unhandled amd64-linux syscall: 444 (landlock_create_ruleset)
 494327  Crash when running Helgrind built with #define TRACE_PTH_FNS 1
 494337  All threaded applications cause still holding lock errors
 495488  Add FreeBSD getrlimitusage syscall wrapper
index d50cdcc981b981984a04bd85ca983448fe7b2a85..221439a0ec339df806ad8376361ee7d4a0406bcf 100644 (file)
@@ -328,6 +328,11 @@ DECL_TEMPLATE(linux, sys_pidfd_open);
 DECL_TEMPLATE(linux, sys_close_range);
 DECL_TEMPLATE(linux, sys_openat2);
 
+// Linux-specific (new in Linux 5.13)
+DECL_TEMPLATE(linux, sys_landlock_create_ruleset)
+DECL_TEMPLATE(linux, sys_landlock_add_rule)
+DECL_TEMPLATE(linux, sys_landlock_restrict_self)
+
 // Linux-specific (new in Linux 5.14)
 DECL_TEMPLATE(linux, sys_memfd_secret);
 
index 2230baf772b00c902a08fee4c77fc9eb88a7a04b..9488d3090e8053463c75b5c2d2057c6f03c9a6cd 100644 (file)
@@ -887,6 +887,10 @@ static SyscallTableEntry syscall_table[] = {
 
    LINXY(__NR_epoll_pwait2,      sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINXY(__NR_memfd_secret,      sys_memfd_secret),      // 447
 
    LINX_(__NR_fchmodat2,         sys_fchmodat2),         // 452
index c8c23a928209076c4db4c24685e67abea62a46d3..5dac60f82145ef8c1e3d66b4ce170352f3955b66 100644 (file)
@@ -1063,6 +1063,10 @@ static SyscallTableEntry syscall_main_table[] = {
 
    LINXY(__NR_epoll_pwait2,      sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINX_(__NR_fchmodat2,         sys_fchmodat2),         // 452
 };
 
index 05e0e421fa6c5e3b1ebfc3afe14dbd638a398eef..151ae0640b1088afff8f4a1cc3eec1edd7972c42 100644 (file)
@@ -840,6 +840,10 @@ static SyscallTableEntry syscall_main_table[] = {
 
    LINXY(__NR_epoll_pwait2,      sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINXY(__NR_memfd_secret,      sys_memfd_secret),      // 447
 
    LINX_(__NR_fchmodat2,         sys_fchmodat2),         // 452
index 775fae75b220aa319cdbc03fbe2e298e329fd18f..5af84d739912959b047c02ed1763b166ca6773cb 100644 (file)
@@ -4163,6 +4163,54 @@ POST(sys_memfd_create)
    }
 }
 
+PRE(sys_landlock_create_ruleset)
+{
+   PRINT("sys_landlock_create_ruleset ( %#" FMT_REGWORD "x, %lu, %lu )",
+         ARG1, ARG2, ARG3);
+   PRE_REG_READ3(long, "landlock_create_ruleset",
+                 const struct vki_landlock_ruleset_attr*, attr,
+                 vki_size_t, size, vki_uint32_t, flags);
+   PRE_MEM_READ( "landlock_create_ruleset(value)", ARG1, ARG2 );
+
+   /* XXX Alternatively we could always fail with EOPNOTSUPP
+      since the rules might interfere with valgrind itself.  */
+}
+
+POST(sys_landlock_create_ruleset)
+{
+   /* Returns either the abi version or a file descriptor.  */
+   if (ARG3 != VKI_LANDLOCK_CREATE_RULESET_VERSION) {
+      if (!ML_(fd_allowed)(RES, "landlock_create_ruleset", tid, True)) {
+         VG_(close)(RES);
+         SET_STATUS_Failure( VKI_EMFILE );
+      } else {
+         if (VG_(clo_track_fds))
+            ML_(record_fd_open_nameless)(tid, RES);
+      }
+   }
+}
+
+PRE(sys_landlock_add_rule)
+{
+   PRINT("sys_landlock_add_rule ( %ld, %lu, %#" FMT_REGWORD "x, %lu )",
+         SARG1, ARG2, ARG3, ARG4);
+   PRE_REG_READ4(long, "landlock_add_rule",
+                 int, ruleset_fd, enum vki_landlock_rule_type, rule_type,
+                 const void*, rule_attr, vki_uint32_t, flags);
+   if (!ML_(fd_allowed)(ARG1, "landlock_add_rule", tid, False))
+      SET_STATUS_Failure(VKI_EBADF);
+   /* XXX Depending on rule_type we should also check the given rule_attr.  */
+}
+
+PRE(sys_landlock_restrict_self)
+{
+   PRINT("sys_landlock_restrict_self ( %ld, %lu )", SARG1, ARG2);
+   PRE_REG_READ2(long, "landlock_create_ruleset",
+                 int, ruleset_fd, vki_uint32_t, flags);
+   if (!ML_(fd_allowed)(ARG1, "landlock_restrict_self", tid, False))
+      SET_STATUS_Failure(VKI_EBADF);
+}
+
 PRE(sys_memfd_secret)
 {
    PRINT("sys_memfd_secret ( %#" FMT_REGWORD "x )", ARG1);
index 42134421367618efa347d4b9b05d8b97ed5f4312..757b637ba9864845314b1eb97fa61696e4df1d84 100644 (file)
@@ -1147,6 +1147,10 @@ static SyscallTableEntry syscall_main_table[] = {
 
    LINXY(__NR_epoll_pwait2,      sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINX_(__NR_fchmodat2,               sys_fchmodat2),               // 452
 };
 
index e9bb5c54c59ccdde873c93e4eb450f1b05dbefba..f0c5f7e04f4e68f1a000473aee00c973fdb4da7c 100644 (file)
@@ -824,7 +824,10 @@ static SyscallTableEntry syscall_main_table[] = {
    LINXY (__NR_openat2, sys_openat2),
    LINXY (__NR_pidfd_getfd, sys_pidfd_getfd),
    LINX_ (__NR_faccessat2, sys_faccessat2),
-   LINXY(__NR_epoll_pwait2, sys_epoll_pwait2),
+   LINXY (__NR_epoll_pwait2, sys_epoll_pwait2),
+   LINXY (__NR_landlock_create_ruleset, sys_landlock_create_ruleset),
+   LINX_ (__NR_landlock_add_rule, sys_landlock_add_rule),
+   LINX_ (__NR_landlock_restrict_self, sys_landlock_restrict_self),
    LINX_ (__NR_fchmodat2, sys_fchmodat2),
 };
 
index 36a5c0ca002d5061cafeedf1aa7df6f90b8e35fd..f466aca147e04d9747e20acbb9f95c7615d69521 100644 (file)
@@ -831,6 +831,9 @@ static SyscallTableEntry syscall_main_table[] = {
    LINXY(__NR_pidfd_getfd,             sys_pidfd_getfd),
    LINX_ (__NR_faccessat2,             sys_faccessat2),
    LINXY (__NR_epoll_pwait2,           sys_epoll_pwait2),
+   LINXY (__NR_landlock_create_ruleset,sys_landlock_create_ruleset),
+   LINX_ (__NR_landlock_add_rule,      sys_landlock_add_rule),
+   LINX_ (__NR_landlock_restrict_self, sys_landlock_restrict_self),
    LINX_ (__NR_fchmodat2,              sys_fchmodat2),
 };
 
index f7a90c753060909a91553f77fb4e590fa83f9802..634f288ce0d166877353e08a237a0c9c19dad156 100644 (file)
@@ -1069,6 +1069,10 @@ static SyscallTableEntry syscall_table[] = {
 
    LINXY (__NR_epoll_pwait2,     sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINX_ (__NR_fchmodat2,        sys_fchmodat2),         // 452
 };
 
index 8de95624fa7caf867bfd6b3842568f0a3940f622..2c2def330ad7df99afc1f7fac35b1ff80cdbfde5 100644 (file)
@@ -1035,6 +1035,10 @@ static SyscallTableEntry syscall_table[] = {
 
    LINXY (__NR_epoll_pwait2,     sys_epoll_pwait2),      // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINX_ (__NR_fchmodat2,        sys_fchmodat2),         // 452
 };
 
index 8a1be8cbef54b5ce05a076ad8cd6164afc30a5c0..ca571f0f1a7cc681de87c4eba0beeff4f8d0498d 100644 (file)
@@ -875,6 +875,10 @@ static SyscallTableEntry syscall_table[] = {
 
    LINXY(__NR_epoll_pwait2, sys_epoll_pwait2),                        // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset),  // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),        // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),   // 446
+
    LINXY(__NR_memfd_secret, sys_memfd_secret),                        // 447
 
    LINX_ (__NR_fchmodat2, sys_fchmodat2),                             // 452
index 31243a0db3739d6ecbd5bd5254e5d2617789d70b..a23743743abea20f987a0e670434a58f1cdb8ef7 100644 (file)
@@ -1656,6 +1656,10 @@ static SyscallTableEntry syscall_table[] = {
 
    LINXY(__NR_epoll_pwait2,      sys_epoll_pwait2),     // 441
 
+   LINXY(__NR_landlock_create_ruleset, sys_landlock_create_ruleset), // 444
+   LINX_(__NR_landlock_add_rule,       sys_landlock_add_rule),       // 445
+   LINX_(__NR_landlock_restrict_self,  sys_landlock_restrict_self),  // 446
+
    LINXY(__NR_memfd_secret,      sys_memfd_secret),      // 447
 
    LINX_(__NR_fchmodat2,         sys_fchmodat2),         // 452
index 8012d73749b3fd0409acf0079a0206e60eb2c720..5d5162a46eb6e7d8142468a1f44ee2c30f2cf34d 100644 (file)
@@ -107,4 +107,5 @@ nobase_pkginclude_HEADERS = \
        vki/vki-xen-xsm.h               \
        vki/vki-xen-x86.h               \
        vki/vki-linux-drm.h             \
-       vki/vki-linux-io_uring.h
+       vki/vki-linux-io_uring.h        \
+       vki/vki-linux-landlock.h
index 24f99cc09f1682e2e3b1a178a7865b0b4518ef7e..7b6e71e11eb4d5ce36936500e2bdad35d786ff05 100644 (file)
@@ -47,6 +47,7 @@
 #  include "vki/vki-linux.h"
 #  include "vki/vki-linux-drm.h"
 #  include "vki/vki-linux-io_uring.h"
+#  include "vki/vki-linux-landlock.h"
 #elif defined(VGO_darwin)
 #  include "vki/vki-darwin.h"
 #elif defined(VGO_solaris)
diff --git a/include/vki/vki-linux-landlock.h b/include/vki/vki-linux-landlock.h
new file mode 100644 (file)
index 0000000..e549ae9
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+   This file is part of Valgrind, a dynamic binary instrumentation framework.
+
+   Copyright (C) 2024 Peter Seiderer <ps.report@gmx.net>
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+   The GNU General Public License is contained in the file COPYING.
+*/
+#ifndef __VKI_LANDLOCK_H
+#define __VKI_LANDLOCK_H
+
+// Derived from linux-6.9.7/include/uapi/linux/landlock.h
+struct vki_landlock_ruleset_attr {
+       __vki_u64 handled_access_fs;
+       __vki_u64 handled_access_net;
+};
+
+enum vki_landlock_rule_type {
+       VKI_LANDLOCK_RULE_PATH_BENEATH = 1,
+       VKI_LANDLOCK_RULE_NET_PORT,
+};
+
+#define VKI_LANDLOCK_CREATE_RULESET_VERSION 1
+
+#endif
index 068a2cd12bd6f57ecbb97c1c187624e2a565c9fd..20346ca716785386362798626da745ebcdb59244 100644 (file)
 
 #define __NR_epoll_pwait2              441
 
+#define __NR_landlock_create_ruleset   444
+#define __NR_landlock_add_rule         445
+#define __NR_landlock_restrict_self    446
+
 #define __NR_memfd_secret              447
 
 #define __NR_fchmodat2         452