Message ID | 20200428175129.634352-2-mic@digikod.net (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Add support for RESOLVE_MAYEXEC | expand |
On Tue, 28 Apr 2020, Mickaël Salaün wrote: > When the RESOLVE_MAYEXEC flag is passed, openat2(2) may be subject to > additional restrictions depending on a security policy managed by the > kernel through a sysctl or implemented by an LSM thanks to the > inode_permission hook. Reviewed-by: James Morris <jamorris@linux.microsoft.com>
On 01/05/2020 06:04, James Morris wrote: > On Tue, 28 Apr 2020, Mickaël Salaün wrote: > >> When the RESOLVE_MAYEXEC flag is passed, openat2(2) may be subject to >> additional restrictions depending on a security policy managed by the >> kernel through a sysctl or implemented by an LSM thanks to the >> inode_permission hook. > > > Reviewed-by: James Morris <jamorris@linux.microsoft.com> As requested, I switched back to O_MAYEXEC yesterday with the v4: https://lore.kernel.org/lkml/20200430132320.699508-2-mic@digikod.net/
diff --git a/fs/open.c b/fs/open.c index 719b320ede52..ca5a145761a2 100644 --- a/fs/open.c +++ b/fs/open.c @@ -1029,6 +1029,12 @@ inline int build_open_flags(const struct open_how *how, struct open_flags *op) if (flags & __O_SYNC) flags |= O_DSYNC; + /* Checks execution permissions on open. */ + if (how->resolve & RESOLVE_MAYEXEC) { + acc_mode |= MAY_OPENEXEC; + flags |= __FMODE_EXEC; + } + op->open_flag = flags; /* O_TRUNC implies we need access checks for write permissions */ diff --git a/include/linux/fcntl.h b/include/linux/fcntl.h index 7bcdcf4f6ab2..a37e213220ad 100644 --- a/include/linux/fcntl.h +++ b/include/linux/fcntl.h @@ -19,7 +19,7 @@ /* List of all valid flags for the how->resolve argument: */ #define VALID_RESOLVE_FLAGS \ (RESOLVE_NO_XDEV | RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS | \ - RESOLVE_BENEATH | RESOLVE_IN_ROOT) + RESOLVE_BENEATH | RESOLVE_IN_ROOT | RESOLVE_MAYEXEC) /* List of all open_how "versions". */ #define OPEN_HOW_SIZE_VER0 24 /* sizeof first published struct */ diff --git a/include/linux/fs.h b/include/linux/fs.h index 4f6f59b4f22a..f5be4be7c01d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -101,6 +101,8 @@ typedef int (dio_iodone_t)(struct kiocb *iocb, loff_t offset, #define MAY_CHDIR 0x00000040 /* called from RCU mode, don't block */ #define MAY_NOT_BLOCK 0x00000080 +/* the inode is opened with RESOLVE_MAYEXEC */ +#define MAY_OPENEXEC 0x00000100 /* * flags in file.f_mode. Note that FMODE_READ and FMODE_WRITE must correspond diff --git a/include/uapi/linux/openat2.h b/include/uapi/linux/openat2.h index 58b1eb711360..86ed0a2321c3 100644 --- a/include/uapi/linux/openat2.h +++ b/include/uapi/linux/openat2.h @@ -35,5 +35,11 @@ struct open_how { #define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".." be scoped inside the dirfd (similar to chroot(2)). */ +#define RESOLVE_MAYEXEC 0x20 /* Code execution from the target file is + intended, checks such permission. A + simple policy can be enforced + system-wide as explained in + Documentation/admin-guide/sysctl/fs.rst + */ #endif /* _UAPI_LINUX_OPENAT2_H */