Skip to contentSkip to conversation

Add trusted_for(2) (was O_MAYEXEC)

PATCH Superseded Mickaël Salaün 2 participants 6 messages Sep 24, 2020 – Sep 25, 2020

Subsystems (23)

v10 of 18 Superseded Latest is v18 →

lore
Share & tools
lore
#0 lore raw

v10 cover Add trusted_for(2) (was O_MAYEXEC)

Hi,

This tenth patch series renames the syscall from introspect_access(2) to trusted_for(2) and the sysctl from fs.introspect_policy to fs.trust_policy. Indeed, the final goal is to enable the kernel to be a global policy manager by entrusting processes with access control at their level. To reach this goal, two complementary parts are required:
* user space needs to be able to know if it can trust some file descriptor content for a specific usage;
* and the kernel needs to make available some part of the policy configured by the system administrator.

We removed the MAY_INTROSPECT_EXEC which was passed to inode_permission(). LSMs wishing to use this new syscall will need to implement such new flag.

Primary goal of trusted_for(2)
==============================

This new syscall enables user space to ask the kernel: is this file descriptor's content trusted to be used for this purpose? The set of usage currently only contains "execution", but other may follow (e.g. "configuration", "sensitive_data"). If the kernel identifies the file descriptor as trustworthy for this usage, user space should then take this information into account. The "execution" usage means that the content of the file descriptor is trusted according to the system policy to be executed by user space, which means that it interprets the content or (try to) maps it as executable memory.

A simple system-wide security policy can be enforced by the system administrator through a sysctl configuration consistent with the mount points or the file access rights. The documentation patch explains the prerequisites.

It is important to note that this can only enable to extend access control managed by the kernel. Hence it enables current access control mechanism to be extended and become a superset of what they can currently control. Indeed, the security policy could also be delegated to an LSM, either a MAC system or an integrity system. For instance, this is required to close a major IMA measurement/appraisal interpreter integrity gap by bringing the ability to check the use of scripts [1]. Other uses are expected, such as for magic-links [2], SGX integration [3], bpffs [4].

Complementary W^X protections can be brought by SELinux, IPE [5] and trampfd [6].

Prerequisite of its use
=======================

User space needs to adapt to take advantage of this new feature. For example, the PEP 578 [7] (Runtime Audit Hooks) enables Python 3.8 to be extended with policy enforcement points related to code interpretation, which can be used to align with the PowerShell audit features. Additional Python security improvements (e.g. a limited interpreter without -c, stdin piping of code) are on their way [8].

Examples
========

The initial idea comes from CLIP OS 4 and the original implementation has been used for more than 12 years:
https://github.com/clipos-archive/clipos4_doc
Chrome OS has a similar approach:
https://chromium.googlesource.com/chromiumos/docs/+/master/security/noexec_shell_scripts.md

Userland patches can be found here:
https://github.com/clipos-archive/clipos4_portage-overlay/search?q=O_MAYEXEC
Actually, there is more than the O_MAYEXEC changes (which matches this search) e.g., to prevent Python interactive execution. There are patches for Bash, Wine, Java (Icedtea), Busybox's ash, Perl and Python. There are also some related patches which do not directly rely on O_MAYEXEC but which restrict the use of browser plugins and extensions, which may be seen as scripts too:
https://github.com/clipos-archive/clipos4_portage-overlay/tree/master/www-client

An introduction to O_MAYEXEC was given at the Linux Security Summit Europe 2018 - Linux Kernel Security Contributions by ANSSI:
https://www.youtube.com/watch?v=chNjCRtPKQY&t=17m15s
The "write xor execute" principle was explained at Kernel Recipes 2018 - CLIP OS: a defense-in-depth OS:
https://www.youtube.com/watch?v=PjRE0uBtkHU&t=11m14s
See also an overview article: https://lwn.net/Articles/820000/

This patch series can be applied on top of v5.9-rc6 . This can be tested with CONFIG_SYSCTL. I would really appreciate constructive comments on this patch series.

Previous version:
https://lore.kernel.org/kernel-hardening/[email protected]/

[1] https://lore.kernel.org/lkml/[email protected]/
[2] https://lore.kernel.org/lkml/[email protected]/
[3] https://lore.kernel.org/lkml/CALCETrVovr8XNZSroey7pHF46O=kj_c5D9K8h=z2T_cNrpvMig@mail.gmail.com/
[4] https://lore.kernel.org/lkml/CALCETrVeZ0eufFXwfhtaG_j+AdvbzEWE0M3wjXMWVEO7pj+xkw@mail.gmail.com/
[5] https://lore.kernel.org/lkml/[email protected]/
[6] https://lore.kernel.org/lkml/[email protected]/
[7] https://www.python.org/dev/peps/pep-0578/
[8] https://lore.kernel.org/lkml/[email protected]/

Regards,

Mickaël Salaün (3):
fs: Add trusted_for(2) syscall implementation and related sysctl
arch: Wire up trusted_for(2)
selftest/interpreter: Add tests for trusted_for(2) policies

 Documentation/admin-guide/sysctl/fs.rst       |  50 +++
 arch/alpha/kernel/syscalls/syscall.tbl        |   1 +
 arch/arm/tools/syscall.tbl                    |   1 +
 arch/arm64/include/asm/unistd.h               |   2 +-
 arch/arm64/include/asm/unistd32.h             |   2 +
 arch/ia64/kernel/syscalls/syscall.tbl         |   1 +
 arch/m68k/kernel/syscalls/syscall.tbl         |   1 +
 arch/microblaze/kernel/syscalls/syscall.tbl   |   1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl     |   1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl     |   1 +
 arch/parisc/kernel/syscalls/syscall.tbl       |   1 +
 arch/powerpc/kernel/syscalls/syscall.tbl      |   1 +
 arch/s390/kernel/syscalls/syscall.tbl         |   1 +
 arch/sh/kernel/syscalls/syscall.tbl           |   1 +
 arch/sparc/kernel/syscalls/syscall.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_32.tbl        |   1 +
 arch/x86/entry/syscalls/syscall_64.tbl        |   1 +
 arch/xtensa/kernel/syscalls/syscall.tbl       |   1 +
 fs/open.c                                     |  77 ++++
 include/linux/fs.h                            |   1 +
 include/linux/syscalls.h                      |   1 +
 include/uapi/asm-generic/unistd.h             |   4 +-
 include/uapi/linux/trusted-for.h              |  18 +
 kernel/sysctl.c                               |  12 +-
 .../testing/selftests/interpreter/.gitignore  |   2 +
 tools/testing/selftests/interpreter/Makefile  |  21 +
 tools/testing/selftests/interpreter/config    |   1 +
 .../selftests/interpreter/trust_policy_test.c | 362 ++++++++++++++++++
 29 files changed, 565 insertions(+), 4 deletions(-)
 create mode 100644 include/uapi/linux/trusted-for.h
 create mode 100644 tools/testing/selftests/interpreter/.gitignore
 create mode 100644 tools/testing/selftests/interpreter/Makefile
 create mode 100644 tools/testing/selftests/interpreter/config
 create mode 100644 tools/testing/selftests/interpreter/trust_policy_test.c
Signature · 1 line
2.28.0
#1 lore raw

PATCH v10 1/3 fs: Add trusted_for(2) syscall implementation and related sysctl

From: Mickaël Salaün <[email protected]>

The trusted_for() syscall enables user space tasks to check that files are trusted to be executed or interpreted by user space. This may allow script interpreters to check execution permission before reading commands from a file, or dynamic linkers to allow shared object loading. This may be seen as a way for a trusted task (e.g. interpreter) to check the trustworthiness of files (e.g. scripts) before extending its control flow graph with new ones originating from these files.

The security policy is consistently managed by the kernel through the new sysctl: fs.trust_policy . This enables system administrators to enforce two complementary security policies according to the installed
system: enforce the noexec mount option, and enforce executable file permission. Indeed, because of compatibility with installed systems, only system administrators are able to check that this new enforcement is in line with the system mount points and file permissions.

For this to be possible, script interpreters must use trusted_for(2) with the TRUSTED_FOR_EXECUTION usage. To be fully effective, these interpreters also need to handle the other ways to execute code: command line parameters (e.g., option -e for Perl), module loading (e.g., option -m for Python), stdin, file sourcing, environment variables, configuration files, etc. According to the threat model, it may be acceptable to allow some script interpreters (e.g. Bash) to interpret commands from stdin, may it be a TTY or a pipe, because it may not be enough to (directly) perform syscalls.

Even without enforced security policy, user space interpreters can use this syscall to try as much as possible to enforce the system policy at their level, knowing that it will not break anything on running systems which do not care about this feature. However, on systems which want this feature enforced, there will be knowledgeable people (i.e. system administrator who configured fs.trust_policy deliberately) to manage it.

Because trusted_for(2) is a mean to enforce a system-wide security policy (but not application-centric policies), it does not make sense for user space to check the sysctl value. Indeed, this new flag only enables to extend the system ability to enforce a policy thanks to (some trusted) user space collaboration. Moreover, additional security policies could be managed by LSMs. This is a best-effort approach from the application developer point of view:
https://lore.kernel.org/lkml/[email protected]/

trusted_for(2) with TRUSTED_FOR_EXECUTION should not be confused with the O_EXEC flag (for open) which is intended for execute-only, which obviously doesn't work for scripts. However, a similar behavior could be implemented in user space with O_PATH:
https://lore.kernel.org/lkml/[email protected]/

Being able to restrict execution also enables to protect the kernel by restricting arbitrary syscalls that an attacker could perform with a crafted binary or certain script languages. It also improves multilevel isolation by reducing the ability of an attacker to use side channels with specific code. These restrictions can natively be enforced for ELF binaries (with the noexec mount option) but require this kernel extension to properly handle scripts (e.g. Python, Perl). To get a consistent execution policy, additional memory restrictions should also be enforced (e.g. thanks to SELinux).

This is a new implementation of a patch initially written by Vincent Strubel for CLIP OS 4:
https://github.com/clipos-archive/src_platform_clip-patches/blob/f5cb330d6b684752e403b4e41b39f7004d88e561/1901_open_mayexec.patch
This patch has been used for more than 12 years with customized script interpreters. Some examples (with the original O_MAYEXEC) can be found here:
https://github.com/clipos-archive/clipos4_portage-overlay/search?q=O_MAYEXEC

Cc Al Viro <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Jonathan Corbet <[email protected]>
Cc Kees Cook <[email protected]>
Cc Vincent Strubel <[email protected]>

---

Changes since v9:
* Rename the syscall to trusted_for(2) and the sysctl to fs.trust_policy
* Add a dedicated enum trusted_for_usage with include/uapi/linux/trusted-for.h
* Remove the extra MAY_INTROSPECTION_EXEC bit. LSMs can still implement this feature themselves.

Changes since v8:
* Add a dedicated syscall introspect_access() (requested by Al Viro).
* Rename MAY_INTERPRETED_EXEC to MAY_INTROSPECTION_EXEC .
* Rename the sysctl fs.interpreted_access to fs.introspection_policy .
* Update documentation.

Changes since v7:
* Replaces openat2/O_MAYEXEC with faccessat2/X_OK/AT_INTERPRETED . Switching to an FD-based syscall was suggested by Al Viro and Jann Horn.
* Handle special file descriptors.
* Add a compatibility mode for execute/read check.
* Move the sysctl policy from fs/namei.c to fs/open.c for the new faccessat2/AT_INTERPRETED.
* Rename the sysctl from fs.open_mayexec_enforce to fs.interpreted_access .
* Update documentation accordingly.

Changes since v6:
* Allow opening pipes, block devices and character devices with O_MAYEXEC when there is no enforced policy, but forbid any non-regular file opened with O_MAYEXEC otherwise (i.e. for any enforced policy).
* Add a paragraph about the non-regular files policy.
* Move path_noexec() calls out of the fast-path (suggested by Kees Cook).
* Do not set __FMODE_EXEC for now because of inconsistent behavior:
https://lore.kernel.org/lkml/202007160822.CCDB5478@keescook/
* Returns EISDIR when opening a directory with O_MAYEXEC.
* Removed Deven Bowers and Kees Cook Reviewed-by tags because of the current update.

Changes since v5:
* Remove the static enforcement configuration through Kconfig because it makes the code more simple like this, and because the current sysctl configuration can only be set with CAP_SYS_ADMIN, the same way mount options (i.e. noexec) can be set. If an harden distro wants to enforce a configuration, it should restrict capabilities or sysctl configuration. Furthermore, an LSM can easily leverage O_MAYEXEC to fit its need.
* Move checks from inode_permission() to may_open() and make the error codes more consistent according to file types (in line with a previous commit): opening a directory with O_MAYEXEC returns EISDIR and other non-regular file types may return EACCES.
* In may_open(), when OMAYEXEC_ENFORCE_FILE is set, replace explicit call to generic_permission() with an artificial MAY_EXEC to avoid double calls. This makes sense especially when an LSM policy forbids execution of a file.
* Replace the custom proc_omayexec() with proc_dointvec_minmax_sysadmin(), and then replace the CAP_MAC_ADMIN check with a CAP_SYS_ADMIN one (suggested by Kees Cook and Stephen Smalley).
* Use BIT() (suggested by Kees Cook).
* Rename variables (suggested by Kees Cook).
* Reword the kconfig help.
* Import the documentation patch (suggested by Kees Cook):
https://lore.kernel.org/lkml/[email protected]/
* Update documentation and add LWN.net article.

Changes since v4:
* Add kernel configuration options to enforce O_MAYEXEC at build time, and disable the sysctl in such case (requested by James Morris).
* Reword commit message.

Changes since v3:
* Switch back to O_MAYEXEC, but only handle it with openat2(2) which checks unknown flags (suggested by Aleksa Sarai). Cf.
https://lore.kernel.org/lkml/[email protected]/

Changes since v2:
* Replace O_MAYEXEC with RESOLVE_MAYEXEC from openat2(2). This change enables to not break existing application using bogus O_* flags that may be ignored by current kernels by using a new dedicated flag, only usable through openat2(2) (suggested by Jeff Layton). Using this flag will results in an error if the running kernel does not support it. User space needs to manage this case, as with other RESOLVE_* flags. The best effort approach to security (for most common distros) will simply consists of ignoring such an error and retry without RESOLVE_MAYEXEC. However, a fully controlled system may which to error out if such an inconsistency is detected.
* Cosmetic changes.

Changes since v1:
* Set __FMODE_EXEC when using O_MAYEXEC to make this information available through the new fanotify/FAN_OPEN_EXEC event (suggested by Jan Kara and Matthew Bobrowski):
https://lore.kernel.org/lkml/[email protected]/
* Move code from Yama to the FS subsystem (suggested by Kees Cook).
* Make omayexec_inode_permission() static (suggested by Jann Horn).
* Use mode 0600 for the sysctl.
* Only match regular files (not directories nor other types), which follows the same semantic as commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files during execve()").

---
 Documentation/admin-guide/sysctl/fs.rst | 50 ++++++++++++++++
 fs/open.c                               | 77 +++++++++++++++++++++++++
 include/linux/fs.h                      |  1 +
 include/linux/syscalls.h                |  1 +
 include/uapi/linux/trusted-for.h        | 18 ++++++
 kernel/sysctl.c                         | 12 +++-
 6 files changed, 157 insertions(+), 2 deletions(-)
 create mode 100644 include/uapi/linux/trusted-for.h
Documentation/admin-guide/sysctl/fs.rst +50 -0
index f48277a0a850..c163ae050bdd 100644
@@ -48,6 +48,7 @@ Currently, these files are in /proc/sys/fs:
 - suid_dumpable
 - super-max
 - super-nr
+- trust_policy
 
 
 aio-nr & aio-max-nr
@@ -382,3 +383,52 @@ Each "watch" costs roughly 90 bytes on a 32bit kernel, and roughly 160 bytes
 on a 64bit one.
 The current default value for  max_user_watches  is the 1/32 of the available
 low memory, divided for the "watch" cost in bytes.
+
+
+trust_policy
+------------
+
+An interpreter can call :manpage:`trusted_for(2)` with a
+``TRUSTED_FOR_EXECUTION`` usage to check that opened regular files are expected
+to be executable.  If the file is not identified as executable, then the
+syscall returns -EACCES.  This may allow a script interpreter to check
+executable permission before reading commands from a file, or a dynamic linker
+to only load executable shared objects.  One interesting use case is to enforce
+a "write xor execute" policy through interpreters.
+
+The ability to restrict code execution must be thought as a system-wide policy,
+which first starts by restricting mount points with the ``noexec`` option.
+This option is also automatically applied to special filesystems such as /proc .
+This prevents files on such mount points to be directly executed by the kernel
+or mapped as executable memory (e.g. libraries).  With script interpreters
+using :manpage:`trusted_for(2)`, the executable permission can then be checked
+before reading commands from files.  This makes it possible to enforce the
+``noexec`` at the interpreter level, and thus propagates this security policy
+to scripts.  To be fully effective, these interpreters also need to handle the
+other ways to execute code: command line parameters (e.g., option ``-e`` for
+Perl), module loading (e.g., option ``-m`` for Python), stdin, file sourcing,
+environment variables, configuration files, etc.  According to the threat
+model, it may be acceptable to allow some script interpreters (e.g.  Bash) to
+interpret commands from stdin, may it be a TTY or a pipe, because it may not be
+enough to (directly) perform syscalls.
+
+There are two complementary security policies: enforce the ``noexec`` mount
+option, and enforce executable file permission.  These policies are handled by
+the ``fs.trust_policy`` sysctl (writable only with ``CAP_SYS_ADMIN``) as a
+bitmask:
+
+1 - Mount restriction: checks that the mount options for the underlying VFS
+    mount do not prevent execution.
+
+2 - File permission restriction: checks that the file is marked as
+    executable for the current process (e.g., POSIX permissions, ACLs).
+
+Note that as long as a policy is enforced, checking any non-regular file with
+:manpage:`trusted_for(2)` returns -EACCES (e.g. TTYs, pipe), even when such a
+file is marked as executable or is on an executable mount point.
+
+Code samples can be found in
+tools/testing/selftests/interpreter/trust_policy_test.c and interpreter patches
+(for the original O_MAYEXEC) are available at
+https://github.com/clipos-archive/clipos4_portage-overlay/search?q=O_MAYEXEC .
+See also an overview article: https://lwn.net/Articles/820000/ .
fs/open.c +77 -0

89 lines not on this page · raw message

include/linux/fs.h +1 -0
index 7519ae003a08..a9b25674b128 100644
@@ -83,6 +83,7 @@ extern int sysctl_protected_symlinks;
 extern int sysctl_protected_hardlinks;
 extern int sysctl_protected_fifos;
 extern int sysctl_protected_regular;
+extern int sysctl_trust_policy;
 
 typedef __kernel_rwf_t rwf_t;
 
include/linux/syscalls.h +1 -0
index 75ac7f8ae93c..55367f9670b1 100644
@@ -429,6 +429,7 @@ asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
 asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
 asmlinkage long sys_faccessat2(int dfd, const char __user *filename, int mode,
 			       int flags);
+asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
 asmlinkage long sys_chdir(const char __user *filename);
 asmlinkage long sys_fchdir(unsigned int fd);
 asmlinkage long sys_chroot(const char __user *filename);
include/uapi/linux/trusted-for.h new file +18 -0
new file mode 100644
index 000000000000..cc4f030c5103
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_TRUSTED_FOR_H
+#define _UAPI_LINUX_TRUSTED_FOR_H
+
+/**
+ * enum trusted_for_usage - Usage for which a file descriptor is trusted
+ *
+ * Argument of trusted_for(2).
+ */
+enum trusted_for_usage {
+	/**
+	 * @TRUSTED_FOR_EXECUTION: Check that the data read from a file
+	 * descriptor is trusted to be executed or interpreted (e.g. scripts).
+	 */
+	TRUSTED_FOR_EXECUTION = 1,
+};
+
+#endif /* _UAPI_LINUX_TRUSTED_FOR_H */
kernel/sysctl.c +10 -2
index afad085960b8..b33b63a8388c 100644
@@ -113,6 +113,7 @@ static int sixty = 60;
 
 static int __maybe_unused neg_one = -1;
 static int __maybe_unused two = 2;
+static int __maybe_unused three = 3;
 static int __maybe_unused four = 4;
 static unsigned long zero_ul;
 static unsigned long one_ul = 1;
@@ -887,7 +888,6 @@ static int proc_taint(struct ctl_table *table, int write,
 	return err;
 }
 
-#ifdef CONFIG_PRINTK
 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
 				void *buffer, size_t *lenp, loff_t *ppos)
 {
@@ -896,7 +896,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
 
 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
 }
-#endif
 
 /**
  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
@@ -3301,6 +3300,15 @@ static struct ctl_table fs_table[] = {
 		.extra1		= SYSCTL_ZERO,
 		.extra2		= &two,
 	},
+	{
+		.procname       = "trust_policy",
+		.data           = &sysctl_trust_policy,
+		.maxlen         = sizeof(int),
+		.mode           = 0600,
+		.proc_handler	= proc_dointvec_minmax_sysadmin,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &three,
+	},
 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
 	{
 		.procname	= "binfmt_misc",
Signature · 1 line
2.28.0
#2 lore raw

Re: [PATCH v10 1/3] fs: Add trusted_for(2) syscall implementation and related sysctl

Thank you for the patch! Perhaps something to improve:

Hi "Mickaël,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on tip/x86/asm kselftest/next linus/master v5.9-rc6 next-20200924] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Micka-l-Sala-n/Add-trusted_for-2-was-O_MAYEXEC/20200924-234005
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: mips-randconfig-r024-20200923 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c32e69b2ce7abfb151a87ba363ac9e25abf7d417)

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install mips cross compiling tool for clang build
# apt-get install binutils-mips-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from fs//autofs/dev-ioctl.c:9:

>> include/linux/syscalls.h:432:46: warning: declaration of 'enum trusted_for_usage' will not be visible outside of this function [-Wvisibility]
   asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
                                                ^
   1 warning generated.
--
   In file included from drivers/char/random.c:335:
>> include/linux/syscalls.h:432:46: warning: declaration of 'enum trusted_for_usage' will not be visible outside of this function [-Wvisibility]
   asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
                                                ^
   drivers/char/random.c:2297:6: warning: no previous prototype for function 'add_hwgenerator_randomness' [-Wmissing-prototypes]
   void add_hwgenerator_randomness(const char *buffer, size_t count,
        ^

drivers/char/random.c:2297:1: note: declare 'static' if the function is not intended to be used outside of this translation unit void add_hwgenerator_randomness(const char *buffer, size_t count,
^
static
2 warnings generated.
--
In file included from drivers/android/binder.c:66:

>> include/linux/syscalls.h:432:46: warning: declaration of 'enum trusted_for_usage' will not be visible outside of this function [-Wvisibility]
   asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
                                                ^
   In file included from drivers/android/binder.c:6207:
   In file included from drivers/android/binder_trace.h:399:
   include/trace/define_trace.h:95:10: fatal error: './binder_trace.h' file not found
   #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/trace/define_trace.h:90:32: note: expanded from macro 'TRACE_INCLUDE'
   # define TRACE_INCLUDE(system) __TRACE_INCLUDE(system)
                                  ^~~~~~~~~~~~~~~~~~~~~~~
   include/trace/define_trace.h:87:34: note: expanded from macro '__TRACE_INCLUDE'
   # define __TRACE_INCLUDE(system) __stringify(TRACE_INCLUDE_PATH/system.h)
                                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/stringify.h:10:27: note: expanded from macro '__stringify'
   #define __stringify(x...)       __stringify_1(x)
                                   ^~~~~~~~~~~~~~~~
   include/linux/stringify.h:9:29: note: expanded from macro '__stringify_1'
   #define __stringify_1(x...)     #x
                                   ^~
   <scratch space>:35:1: note: expanded from here
   "./binder_trace.h"
   ^~~~~~~~~~~~~~~~~~
   1 warning and 1 error generated.

# https://github.com/0day-ci/linux/commit/4671d1c72b214c586edd9293053dabfa053b003a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Micka-l-Sala-n/Add-trusted_for-2-was-O_MAYEXEC/20200924-234005 git checkout 4671d1c72b214c586edd9293053dabfa053b003a
vim +432 include/linux/syscalls.h

413
414 /* fs/open.c */
415 asmlinkage long sys_statfs(const char __user * path,
416 struct statfs __user *buf);
417 asmlinkage long sys_statfs64(const char __user *path, size_t sz,
418 struct statfs64 __user *buf);
419 asmlinkage long sys_fstatfs(unsigned int fd, struct statfs __user *buf);
420 asmlinkage long sys_fstatfs64(unsigned int fd, size_t sz,
421 struct statfs64 __user *buf);
422 asmlinkage long sys_truncate(const char __user *path, long length);
423 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
424 #if BITS_PER_LONG == 32
425 asmlinkage long sys_truncate64(const char __user *path, loff_t length);
426 asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length);
427 #endif
428 asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
429 asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
430 asmlinkage long sys_faccessat2(int dfd, const char __user *filename, int mode,
431 int flags);

 > 432	asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);

433 asmlinkage long sys_chdir(const char __user *filename);
434 asmlinkage long sys_fchdir(unsigned int fd);
435 asmlinkage long sys_chroot(const char __user *filename);
436 asmlinkage long sys_fchmod(unsigned int fd, umode_t mode);
437 asmlinkage long sys_fchmodat(int dfd, const char __user * filename,
438 umode_t mode);
439 asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t user,
440 gid_t group, int flag);
441 asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group);
442 asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
443 umode_t mode);
444 asmlinkage long sys_openat2(int dfd, const char __user *filename,
445 struct open_how *how, size_t size);
446 asmlinkage long sys_close(unsigned int fd);
447 asmlinkage long sys_close_range(unsigned int fd, unsigned int max_fd,
448 unsigned int flags);
449 asmlinkage long sys_vhangup(void);
450

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#3 lore raw

Re: [PATCH v10 1/3] fs: Add trusted_for(2) syscall implementation and related sysctl

In reply to Mickaël Salaün
Thank you for the patch! Perhaps something to improve:

Hi "Mickaël,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on arm64/for-next/core]
[also build test WARNING on tip/x86/asm kselftest/next linus/master v5.9-rc6 next-20200924] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Micka-l-Sala-n/Add-trusted_for-2-was-O_MAYEXEC/20200924-234005
base:   https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-next/core
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/4671d1c72b214c586edd9293053dabfa053b003a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Micka-l-Sala-n/Add-trusted_for-2-was-O_MAYEXEC/20200924-234005 git checkout 4671d1c72b214c586edd9293053dabfa053b003a
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips

If you fix the issue, kindly add following tag as appropriate

All warnings (new ones prefixed by >>):

In file included from kernel/fork.c:54:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~
   kernel/fork.c:160:13: warning: no previous prototype for 'arch_release_task_struct' [-Wmissing-prototypes]
     160 | void __weak arch_release_task_struct(struct task_struct *tsk)
         |             ^~~~~~~~~~~~~~~~~~~~~~~~
   kernel/fork.c:743:20: warning: no previous prototype for 'arch_task_cache_init' [-Wmissing-prototypes]
     743 | void __init __weak arch_task_cache_init(void) { }
         |                    ^~~~~~~~~~~~~~~~~~~~

kernel/fork.c:834:12: warning: no previous prototype for 'arch_dup_task_struct' [-Wmissing-prototypes]
834 | int __weak arch_dup_task_struct(struct task_struct *dst,
| ^~~~~~~~~~~~~~~~~~~~
--
In file included from kernel/exec_domain.c:19:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~
--
   In file included from kernel/exit.c:42:
>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~
   kernel/exit.c:1754:13: warning: no previous prototype for 'abort' [-Wmissing-prototypes]
    1754 | __weak void abort(void)
         |             ^~~~~
--
   In file included from kernel/signal.c:30:
>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

kernel/signal.c:4608:6: warning: no previous prototype for 'kdb_send_sig' [-Wmissing-prototypes]
4608 | void kdb_send_sig(struct task_struct *t, int sig)
| ^~~~~~~~~~~~
--
In file included from kernel/module.c:27:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

In file included from kernel/module.c:35:
include/linux/vermagic.h:36:10: fatal error: generated/randomize_layout_hash.h: No such file or directory
36 | #include <generated/randomize_layout_hash.h>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
--
In file included from kernel/audit.c:44:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~
   kernel/audit.c:1779:14: warning: no previous prototype for 'audit_serial' [-Wmissing-prototypes]
    1779 | unsigned int audit_serial(void)
         |              ^~~~~~~~~~~~
   kernel/audit.c: In function 'audit_log_vformat':
   kernel/audit.c:1924:2: warning: function 'audit_log_vformat' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
    1924 |  len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args);
         |  ^~~
   kernel/audit.c:1933:3: warning: function 'audit_log_vformat' might be a candidate for 'gnu_printf' format attribute [-Wsuggest-attribute=format]
    1933 |   len = vsnprintf(skb_tail_pointer(skb), avail, fmt, args2);
         |   ^~~
--
   In file included from kernel/trace/bpf_trace.c:15:
>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

In file included from kernel/trace/bpf_trace.h:34,
from kernel/trace/bpf_trace.c:25:
include/trace/define_trace.h:95:42: fatal error: ./bpf_trace.h: No such file or directory
95 | #include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
| ^
compilation terminated.
--
In file included from kernel/sched/sched.h:65,
from kernel/sched/core.c:13:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

kernel/sched/core.c:2380:6: warning: no previous prototype for 'sched_set_stop_task' [-Wmissing-prototypes]
2380 | void sched_set_stop_task(int cpu, struct task_struct *stop)
| ^~~~~~~~~~~~~~~~~~~
--
In file included from kernel/sched/sched.h:65,
from kernel/sched/rt.c:6:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

kernel/sched/rt.c:668:6: warning: no previous prototype for 'sched_rt_bandwidth_account' [-Wmissing-prototypes]
668 | bool sched_rt_bandwidth_account(struct rt_rq *rt_rq)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
--
In file included from kernel/time/hrtimer.c:30:

>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:120:21: warning: initialized field overwritten [-Woverride-init]
     120 |  [CLOCK_REALTIME] = HRTIMER_BASE_REALTIME,
         |                     ^~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:120:21: note: (near initialization for 'hrtimer_clock_to_base_table[0]')
   kernel/time/hrtimer.c:121:22: warning: initialized field overwritten [-Woverride-init]
     121 |  [CLOCK_MONOTONIC] = HRTIMER_BASE_MONOTONIC,
         |                      ^~~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:121:22: note: (near initialization for 'hrtimer_clock_to_base_table[1]')
   kernel/time/hrtimer.c:122:21: warning: initialized field overwritten [-Woverride-init]
     122 |  [CLOCK_BOOTTIME] = HRTIMER_BASE_BOOTTIME,
         |                     ^~~~~~~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:122:21: note: (near initialization for 'hrtimer_clock_to_base_table[7]')
   kernel/time/hrtimer.c:123:17: warning: initialized field overwritten [-Woverride-init]
     123 |  [CLOCK_TAI]  = HRTIMER_BASE_TAI,
         |                 ^~~~~~~~~~~~~~~~
   kernel/time/hrtimer.c:123:17: note: (near initialization for 'hrtimer_clock_to_base_table[11]')
--
   In file included from kernel/events/core.c:34:
>> include/linux/syscalls.h:432:46: warning: 'enum trusted_for_usage' declared inside parameter list will not be visible outside of this definition or declaration
     432 | asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);
         |                                              ^~~~~~~~~~~~~~~~~

kernel/events/core.c:6506:6: warning: no previous prototype for 'perf_pmu_snapshot_aux' [-Wmissing-prototypes]
6506 | long perf_pmu_snapshot_aux(struct perf_buffer *rb,
| ^~~~~~~~~~~~~~~~~~~~~
..

vim +432 include/linux/syscalls.h

413
414 /* fs/open.c */
415 asmlinkage long sys_statfs(const char __user * path,
416 struct statfs __user *buf);
417 asmlinkage long sys_statfs64(const char __user *path, size_t sz,
418 struct statfs64 __user *buf);
419 asmlinkage long sys_fstatfs(unsigned int fd, struct statfs __user *buf);
420 asmlinkage long sys_fstatfs64(unsigned int fd, size_t sz,
421 struct statfs64 __user *buf);
422 asmlinkage long sys_truncate(const char __user *path, long length);
423 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
424 #if BITS_PER_LONG == 32
425 asmlinkage long sys_truncate64(const char __user *path, loff_t length);
426 asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length);
427 #endif
428 asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
429 asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
430 asmlinkage long sys_faccessat2(int dfd, const char __user *filename, int mode,
431 int flags);

 > 432	asmlinkage long sys_trusted_for(int fd, enum trusted_for_usage usage, u32 flags);

433 asmlinkage long sys_chdir(const char __user *filename);
434 asmlinkage long sys_fchdir(unsigned int fd);
435 asmlinkage long sys_chroot(const char __user *filename);
436 asmlinkage long sys_fchmod(unsigned int fd, umode_t mode);
437 asmlinkage long sys_fchmodat(int dfd, const char __user * filename,
438 umode_t mode);
439 asmlinkage long sys_fchownat(int dfd, const char __user *filename, uid_t user,
440 gid_t group, int flag);
441 asmlinkage long sys_fchown(unsigned int fd, uid_t user, gid_t group);
442 asmlinkage long sys_openat(int dfd, const char __user *filename, int flags,
443 umode_t mode);
444 asmlinkage long sys_openat2(int dfd, const char __user *filename,
445 struct open_how *how, size_t size);
446 asmlinkage long sys_close(unsigned int fd);
447 asmlinkage long sys_close_range(unsigned int fd, unsigned int max_fd,
448 unsigned int flags);
449 asmlinkage long sys_vhangup(void);
450

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

#4 lore raw

PATCH v10 2/3 arch: Wire up trusted_for(2)

In reply to Mickaël Salaün

From: Mickaël Salaün <[email protected]>

Wire up trusted_for(2) for all architectures.

Cc Al Viro <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Kees Cook <[email protected]>
Cc Vincent Strubel <[email protected]>

---

Changes since v9:
* Rename introspect_access(2) to trusted_for(2).
* Increase syscall number to leave space for memfd_secret(2) in -next.

Changes since v7:
* New patch for the new syscall.
* Increase syscall numbers by 2 to leave space for new ones (in linux-next): watch_mount(2) and process_madvise(2).

---
 arch/alpha/kernel/syscalls/syscall.tbl      | 1 +
 arch/arm/tools/syscall.tbl                  | 1 +
 arch/arm64/include/asm/unistd.h             | 2 +-
 arch/arm64/include/asm/unistd32.h           | 2 ++
 arch/ia64/kernel/syscalls/syscall.tbl       | 1 +
 arch/m68k/kernel/syscalls/syscall.tbl       | 1 +
 arch/microblaze/kernel/syscalls/syscall.tbl | 1 +
 arch/mips/kernel/syscalls/syscall_n32.tbl   | 1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl   | 1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl   | 1 +
 arch/parisc/kernel/syscalls/syscall.tbl     | 1 +
 arch/powerpc/kernel/syscalls/syscall.tbl    | 1 +
 arch/s390/kernel/syscalls/syscall.tbl       | 1 +
 arch/sh/kernel/syscalls/syscall.tbl         | 1 +
 arch/sparc/kernel/syscalls/syscall.tbl      | 1 +
 arch/x86/entry/syscalls/syscall_32.tbl      | 1 +
 arch/x86/entry/syscalls/syscall_64.tbl      | 1 +
 arch/xtensa/kernel/syscalls/syscall.tbl     | 1 +
 include/uapi/asm-generic/unistd.h           | 4 +++-
 19 files changed, 22 insertions(+), 2 deletions(-)
arch/alpha/kernel/syscalls/syscall.tbl +1 -0
index ec8bed9e7b75..0175cfc0f66f 100644
@@ -479,3 +479,4 @@
 547	common	openat2				sys_openat2
 548	common	pidfd_getfd			sys_pidfd_getfd
 549	common	faccessat2			sys_faccessat2
+553	common	trusted_for			sys_trusted_for
arch/arm/tools/syscall.tbl +1 -0
index 171077cbf419..db9c8d35e75b 100644
@@ -453,3 +453,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/arm64/include/asm/unistd.h +1 -1
index 3b859596840d..d1f7d35f986e 100644
@@ -38,7 +38,7 @@
 #define __ARM_NR_compat_set_tls		(__ARM_NR_COMPAT_BASE + 5)
 #define __ARM_NR_COMPAT_END		(__ARM_NR_COMPAT_BASE + 0x800)
 
-#define __NR_compat_syscalls		440
+#define __NR_compat_syscalls		444
 #endif
 
 #define __ARCH_WANT_SYS_CLONE
arch/arm64/include/asm/unistd32.h +2 -0
index 734860ac7cf9..33716dd2c04c 100644
@@ -887,6 +887,8 @@ __SYSCALL(__NR_openat2, sys_openat2)
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
 #define __NR_faccessat2 439
 __SYSCALL(__NR_faccessat2, sys_faccessat2)
+#define __NR_trusted_for 443
+__SYSCALL(__NR_trusted_for, sys_trusted_for)
 
 /*
  * Please add new compat syscalls above this comment and update
arch/ia64/kernel/syscalls/syscall.tbl +1 -0
index f52a41f4c340..68e56436b611 100644
@@ -360,3 +360,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/m68k/kernel/syscalls/syscall.tbl +1 -0
index 81fc799d8392..67f0bc2fc4d0 100644
@@ -439,3 +439,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/microblaze/kernel/syscalls/syscall.tbl +1 -0
index b4e263916f41..acd3057886b7 100644
@@ -445,3 +445,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/mips/kernel/syscalls/syscall_n32.tbl +1 -0
index f9df9edb67a4..8164dc51ebf8 100644
@@ -378,3 +378,4 @@
 437	n32	openat2				sys_openat2
 438	n32	pidfd_getfd			sys_pidfd_getfd
 439	n32	faccessat2			sys_faccessat2
+443	n32	trusted_for			sys_trusted_for
arch/mips/kernel/syscalls/syscall_n64.tbl +1 -0
index 557f9954a2b9..28bc5bb76987 100644
@@ -354,3 +354,4 @@
 437	n64	openat2				sys_openat2
 438	n64	pidfd_getfd			sys_pidfd_getfd
 439	n64	faccessat2			sys_faccessat2
+443	n64	trusted_for			sys_trusted_for
arch/mips/kernel/syscalls/syscall_o32.tbl +1 -0
index 195b43cf27c8..6a62cc5b4999 100644
@@ -427,3 +427,4 @@
 437	o32	openat2				sys_openat2
 438	o32	pidfd_getfd			sys_pidfd_getfd
 439	o32	faccessat2			sys_faccessat2
+443	o32	trusted_for			sys_trusted_for
arch/parisc/kernel/syscalls/syscall.tbl +1 -0
index def64d221cd4..654707acfa6c 100644
@@ -437,3 +437,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/powerpc/kernel/syscalls/syscall.tbl +1 -0
index c2d737ff2e7b..eb1c6d7655e6 100644
@@ -529,3 +529,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/s390/kernel/syscalls/syscall.tbl +1 -0
index 10456bc936fb..6e77640e2976 100644
@@ -442,3 +442,4 @@
 437  common	openat2			sys_openat2			sys_openat2
 438  common	pidfd_getfd		sys_pidfd_getfd			sys_pidfd_getfd
 439  common	faccessat2		sys_faccessat2			sys_faccessat2
+443  common	trusted_for		sys_trusted_for			sys_trusted_for
arch/sh/kernel/syscalls/syscall.tbl +1 -0
index ae0a00beea5f..f5fd0d63b43b 100644
@@ -442,3 +442,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/sparc/kernel/syscalls/syscall.tbl +1 -0
index 4af114e84f20..70806eb828b8 100644
@@ -485,3 +485,4 @@
 437	common	openat2			sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
arch/x86/entry/syscalls/syscall_32.tbl +1 -0
index 9d1102873666..a0824f88fcfb 100644
@@ -444,3 +444,4 @@
 437	i386	openat2			sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd
 439	i386	faccessat2		sys_faccessat2
+443	i386	trusted_for		sys_trusted_for
arch/x86/entry/syscalls/syscall_64.tbl +1 -0
index f30d6ae9a688..0b0ce536acf1 100644
@@ -361,6 +361,7 @@
 437	common	openat2			sys_openat2
 438	common	pidfd_getfd		sys_pidfd_getfd
 439	common	faccessat2		sys_faccessat2
+443	common	trusted_for		sys_trusted_for
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
arch/xtensa/kernel/syscalls/syscall.tbl +1 -0
index 6276e3c2d3fc..22fd070f2565 100644
@@ -410,3 +410,4 @@
 437	common	openat2				sys_openat2
 438	common	pidfd_getfd			sys_pidfd_getfd
 439	common	faccessat2			sys_faccessat2
+443	common	trusted_for			sys_trusted_for
include/uapi/asm-generic/unistd.h +3 -1
index 995b36c2ea7d..6b55804d9df9 100644
@@ -859,9 +859,11 @@ __SYSCALL(__NR_openat2, sys_openat2)
 __SYSCALL(__NR_pidfd_getfd, sys_pidfd_getfd)
 #define __NR_faccessat2 439
 __SYSCALL(__NR_faccessat2, sys_faccessat2)
+#define __NR_trusted_for 443
+__SYSCALL(__NR_trusted_for, sys_trusted_for)
 
 #undef __NR_syscalls
-#define __NR_syscalls 440
+#define __NR_syscalls 444
 
 /*
  * 32 bit systems traditionally used different
Signature · 1 line
2.28.0
#5 lore raw

PATCH v10 3/3 selftest/interpreter: Add tests for trusted_for(2) policies

In reply to Mickaël Salaün

From: Mickaël Salaün <[email protected]>

Test that checks performed by trusted_for(2) on file descriptors are consistent with noexec mount points and file execute permissions, according to the policy configured with the fs.trust_policy sysctl.

Cc Al Viro <[email protected]>
Cc Arnd Bergmann <[email protected]>
Cc Andrew Morton <[email protected]>
Cc Kees Cook <[email protected]>
Cc Shuah Khan <[email protected]>
Cc Vincent Strubel <[email protected]>

---

Changes since v9:
* Rename the syscall and the sysctl.
* Update tests for enum trusted_for_usage

Changes since v8:
* Update with the dedicated syscall introspect_access(2) and the renamed fs.introspection_policy sysctl.
* Remove check symlink which can't be use as is anymore.
* Use socketpair(2) to test UNIX socket.

Changes since v7:
* Update tests with faccessat2/AT_INTERPRETED, including new ones to check that setting R_OK or W_OK returns EINVAL.
* Add tests for memfd, pipefs and nsfs.
* Rename and move back tests to a standalone directory.

Changes since v6:
* Add full combination tests for all file types, including block devices, character devices, fifos, sockets and symlinks.
* Properly save and restore initial sysctl value for all tests.

Changes since v5:
* Refactor with FIXTURE_VARIANT, which make the tests much more easy to read and maintain.
* Save and restore initial sysctl value (suggested by Kees Cook).
* Test with a sysctl value of 0.
* Check errno in sysctl_access_write test.
* Update tests for the CAP_SYS_ADMIN switch.
* Update tests to check -EISDIR (replacing -EACCES).
* Replace FIXTURE_DATA() with FIXTURE() (spotted by Kees Cook).
* Use global const strings.

Changes since v3:
* Replace RESOLVE_MAYEXEC with O_MAYEXEC.
* Add tests to check that O_MAYEXEC is ignored by open(2) and openat(2).

Changes since v2:
* Move tests from exec/ to openat2/ .
* Replace O_MAYEXEC with RESOLVE_MAYEXEC from openat2(2).
* Cleanup tests.

Changes since v1:
* Move tests from yama/ to exec/ .
* Fix _GNU_SOURCE in kselftest_harness.h .
* Add a new test sysctl_access_write to check if CAP_MAC_ADMIN is taken into account.
* Test directory execution which is always forbidden since commit 73601ea5b7b1 ("fs/open.c: allow opening only regular files during execve()"), and also check that even the root user can not bypass file execution checks.
* Make sure delete_workspace() always as enough right to succeed.
* Cosmetic cleanup.

---
 .../testing/selftests/interpreter/.gitignore  |   2 +
 tools/testing/selftests/interpreter/Makefile  |  21 +
 tools/testing/selftests/interpreter/config    |   1 +
 .../selftests/interpreter/trust_policy_test.c | 362 ++++++++++++++++++
 4 files changed, 386 insertions(+)
 create mode 100644 tools/testing/selftests/interpreter/.gitignore
 create mode 100644 tools/testing/selftests/interpreter/Makefile
 create mode 100644 tools/testing/selftests/interpreter/config
 create mode 100644 tools/testing/selftests/interpreter/trust_policy_test.c
tools/testing/selftests/interpreter/.gitignore new file +2 -0
new file mode 100644
index 000000000000..82a4846cbc4b
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0-only
+/*_test
tools/testing/selftests/interpreter/Makefile new file +21 -0
new file mode 100644
index 000000000000..dbca8ebda67e
@@ -0,0 +1,21 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+CFLAGS += -Wall -O2
+LDLIBS += -lcap
+
+src_test := $(wildcard *_test.c)
+TEST_GEN_PROGS := $(src_test:.c=)
+
+KSFT_KHDR_INSTALL := 1
+include ../lib.mk
+
+khdr_dir = $(top_srcdir)/usr/include
+
+$(khdr_dir)/asm-generic/unistd.h: khdr
+	@:
+
+$(khdr_dir)/linux/trusted-for.h: khdr
+	@:
+
+$(OUTPUT)/%_test: %_test.c $(khdr_dir)/asm-generic/unistd.h $(khdr_dir)/linux/trusted-for.h ../kselftest_harness.h
+	$(LINK.c) $< $(LDLIBS) -o $@ -I$(khdr_dir)
tools/testing/selftests/interpreter/config new file +1 -0
new file mode 100644
index 000000000000..dd53c266bf52
@@ -0,0 +1 @@
+CONFIG_SYSCTL=y
tools/testing/selftests/interpreter/trust_policy_test.c new file +362 -0

362 lines not on this page · raw message

Signature · 1 line
2.28.0