File Sealing & memfd_create()
Subsystems (7)
cover File Sealing & memfd_create()
Hi
This series introduces the concept of "file sealing". Sealing a file restricts the set of allowed operations on the file in question. Multiple seals are defined and each seal will cause a different set of operations to return EPERM if it is set. The following seals are introduced:
* SEAL_SHRINK: If set, the inode size cannot be reduced
* SEAL_GROW: If set, the inode size cannot be increased
* SEAL_WRITE: If set, the file content cannot be modified
Unlike existing techniques that provide similar protection, sealing allows file-sharing without any trust-relationship. This is enforced by rejecting seal modifications if you don't own an exclusive reference to the given file. So if you own a file-descriptor, you can be sure that no-one besides you can modify the seals on the given file. This allows mapping shared files from untrusted parties without the fear of the file getting truncated or modified by an attacker.
Several use-cases exist that could make great use of sealing:
1) Graphics Compositors
If a graphics client creates a memory-backed render-buffer and passes a file-decsriptor to it to the graphics server for display, the server _has_ to setup SIGBUS handlers whenever mapping the given file. Otherwise, the client might run ftruncate() or O_TRUNC on the on file in parallel, thus crashing the server.
With sealing, a compositor can reject any incoming file-descriptor that does _not_ have SEAL_SHRINK set. This way, any memory-mappings are guaranteed to stay accessible. Furthermore, we still allow clients to increase the buffer-size in case they want to resize the render-buffer for the next frame. We also allow parallel writes so the client can render new frames into the same buffer (client is responsible of never rendering into a front-buffer if you want to avoid artifacts).
Real use-case: Wayland wl_shm buffers can be transparently converted
2) Geneal-purpose IPC
IPC mechanisms that do not require a mutual trust-relationship (like dbus) cannot do zero-copy so far. With sealing, zero-copy can be easily done by sharing a file-descriptor that has SEAL_SHRINK | SEAL_GROW | SEAL_WRITE set. This way, the source can store sensible data in the file, seal the file and then pass it to the destination. The destination verifies these seals are set and then can parse the message in-line.
Note that these files are usually one-shot files. Without any trust-relationship, a destination can notify the source that it released a file again, but a source can never rely on it. So unless the destination releases the file, a source cannot clear the seals for modification again. However, this is inherent to situations without any trust-relationship.
Real use-case: kdbus messages already use a similar interface and can be
transparently converted to use these seals
Other similar use-cases exist (eg., audio), but these two I am personally working on. Interest in this interface has been raised from several other camps and I've put respective maintainers into CC. If more information on these use-cases is needed, I think they can give some insights.
The API introduced by this patchset is:
* fcntl() extension:
Two new fcntl() commands are added that allow retrieveing (SHMEM_GET_SEALS) and setting (SHMEM_SET_SEALS) seals on a file. Only shmfs implements them so far and there is no intention to implement them on other file-systems. All shmfs based files support sealing.
Patch 2/6
* memfd_create() syscall:
The new memfd_create() syscall is a public frontend to the shmem_file_new() interface in the kernel. It avoids the need of a local shmfs mount-point (as requested by android people) and acts more like MAP_ANON than O_TMPFILE.
Patch 3/6
The other 4 patches are cleanups, self-tests and docs.
The commit-messages explain the API extensions in detail. Man-page proposals are also provided. Last but not least, the extensive self-tests document the intended behavior, in case it is still not clear.
Technically, sealing and memfd_create() are independent, but the described use-cases would greatly benefit from the combination of both. Hence, I merged them into the same series. Please also note that this series is based on earlier works (ashmem, memfd, shmgetfd, ..) and unifies these attempts.
Comments welcome!
Thanks
David
David Herrmann (4):
fs: fix i_writecount on shmem and friends
shm: add sealing API
shm: add memfd_create() syscall
selftests: add memfd_create() + sealing tests
David Herrmann (2): (man-pages)
fcntl.2: document SHMEM_SET/GET_SEALS commands
memfd_create.2: add memfd_create() man-page
arch/x86/syscalls/syscall_32.tbl | 1 + arch/x86/syscalls/syscall_64.tbl | 1 + fs/fcntl.c | 12 +- fs/file_table.c | 27 +- include/linux/shmem_fs.h | 17 + include/linux/syscalls.h | 1 + include/uapi/linux/fcntl.h | 13 + include/uapi/linux/memfd.h | 9 + kernel/sys_ni.c | 1 + mm/shmem.c | 267 +++++++- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/memfd/.gitignore | 2 + tools/testing/selftests/memfd/Makefile | 29 + tools/testing/selftests/memfd/memfd_test.c | 972 +++++++++++++++++++++++++++++ 14 files changed, 1338 insertions(+), 15 deletions(-) create mode 100644 include/uapi/linux/memfd.h create mode 100644 tools/testing/selftests/memfd/.gitignore create mode 100644 tools/testing/selftests/memfd/Makefile create mode 100644 tools/testing/selftests/memfd/memfd_test.c
Signature · 1 line
1.9.0
PATCH 1/6 fs: fix i_writecount on shmem and friends
VM_DENYWRITE currently relies on i_writecount. Unless there's an active writable reference to an inode, VM_DENYWRITE is not allowed. Unfortunately, alloc_file() does not increase i_writecount, therefore, does not prevent a following VM_DENYWRITE even though the new file might have been opened with FMODE_WRITE. However, callers of alloc_file() expect the file object to be fully instantiated so they can call fput() on it. We could now either fix all callers to do an get_write_access() if opened with FMODE_WRITE, or simply fix alloc_file() to do that. I chose the latter.
Note that this bug allows some rather subtle misbehavior. The following sequence of calls should work just fine, but currently fails:
int p[2], orig, ro, rw;
char buf[128];
pipe(p);
sprintf(buf, "/proc/self/fd/%d", p[1]);
ro = open(buf, O_RDONLY);
close(p[1]);
sprintf(buf, "/proc/self/fd/%d", ro);
rw = open(buf, O_RDWR);The final open() cannot succeed as close(p[1]) caused an integer underflow on i_writecount, effectively causing VM_DENYWRITE on the inode. The open will fail with -ETXTBUSY.
It's a rather odd sequence of calls and given that open() doesn't use alloc_file() (and thus not affected by this bug), it's rather unlikely that this is a serious issue. But stuff like anon_inode shares a *single* inode across a huge set of interfaces. If any of these is broken like pipe(), it will affect all of these (ranging from dma-buf to epoll).
---
Hi
This patch is only included for reference. It was submitted to fs-devel separately and is being worked on. However, this bug must be fixed in order to make use of memfd_create(), so I decided to include it here.
David
fs/file_table.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
fs/file_table.c +18 -9
@@ -168,6 +168,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, const struct file_operations *fop) {struct file *file; +int error; file =get_empty_filp ();if (IS_ERR (file))
@@ -179,15 +180,23 @@ struct file *alloc_file(struct path *path, fmode_t mode, file->f_mode = mode; file->f_op = fop; -/* -* These mounts don't really matter in practice -* for r/o bind mounts. They aren't userspace- -* visible. We do this for consistency, and so -* that we can do debugging checks at __fput() -*/ -if ((mode &FMODE_WRITE ) && !special_file (path->dentry->d_inode->i_mode)) { -file_take_write (file); -WARN_ON (mnt_clone_write (path->mnt)); +if (mode &FMODE_WRITE ) { + error =get_write_access (path->dentry->d_inode); +if (error) { +put_filp (file); +return ERR_PTR (error); + } + +/* +* These mounts don't really matter in practice +* for r/o bind mounts. They aren't userspace- +* visible. We do this for consistency, and so +* that we can do debugging checks at __fput() +*/ +if (!special_file (path->dentry->d_inode->i_mode)) { +file_take_write (file); +WARN_ON (mnt_clone_write (path->mnt)); + } }if ((mode & (FMODE_READ |FMODE_WRITE )) ==FMODE_READ )i_readcount_inc (path->dentry->d_inode);
Signature · 1 line
1.9.0
PATCH 2/6 shm: add sealing API
In reply to David HerrmannIf two processes share a common memory region, they usually want some guarantees to allow safe access. This often includes:
- one side cannot overwrite data while the other reads it
- one side cannot shrink the buffer while the other accesses it
- one side cannot grow the buffer beyond previously set boundaries
If there is a trust-relationship between both parties, there is no need for policy enforcement. However, if there's no trust relationship (eg., for general-purpose IPC) sharing memory-regions is highly fragile and often not possible without local copies. Look at the following two use-cases:
1) A graphics client wants to share its rendering-buffer with a graphics-server. The memory-region is allocated by the client for read/write access and a second FD is passed to the server. While scanning out from the memory region, the server has no guarantee that the client doesn't shrink the buffer at any time, requiring rather cumbersome SIGBUS handling.
2) A process wants to perform an RPC on another process. To avoid huge bandwidth consumption, zero-copy is preferred. After a message is assembled in-memory and a FD is passed to the remote side, both sides want to be sure that neither modifies this shared copy, anymore. The source may have put sensible data into the message without a separate copy and the target may want to parse the message inline, to avoid a local copy.
While SIGBUS handling, POSIX mandatory locking and MAP_DENYWRITE provide ways to achieve most of this, the first one is unproportionally ugly to use in libraries and the latter two are broken/racy or even disabled due to denial of service attacks.
This patch introduces the concept of SEALING. If you seal a file, a specific set of operations is blocked until this seal is removed again. Unlike locks, seals can only be modified if you own an exclusive reference to the file. Hence, if, and only if you hold a reference to a file, you can be sure that no-one else can modify the seals besides you (and you can only modify them, if you are the exclusive holder). This makes sealing useful in situations where no trust-relationship is given.
An initial set of SEALS is introduced by this patch:
- SHRINK: If SEAL_SHRINK is set, the file in question cannot be reduced in size. This currently affects only ftruncate().
- GROW: If SEAL_GROW is set, the file in question cannot be increased in size. This affects ftruncate(), fallocate() and write().
- WRITE: If SEAL_WRITE is set, no write operations (besides resizing) are possible. This affects fallocate(PUNCH_HOLE), mmap() and write().
The described use-cases can easily use these seals to provide safe use without any trust-relationship:
1) The graphics server can verify that a passed file-descriptor has SEAL_SHRINK set. This allows safe scanout, while the client is allowed to increase buffer size for window-resizing on-the-fly. Concurrent writes are explicitly allowed.
2) Both processes can verify that SEAL_SHRINK, SEAL_GROW and SEAL_WRITE are set. This guarantees that neither process can modify the data while the other side parses it. Furthermore, it guarantees that even with writable FDs passed to the peer, it cannot increase the size to hit memory-limits of the source process (in case the file-storage is accounted to the source).
There is one exception to setting seals: Imagine a library makes use of sealing. While creating a new memory object with an FD, another thread may fork(), retaining a copy of the FD and thus also a reference. Sealing wouldn't be possible anymore, until this process closes the FDs or exec()s. To avoid this race initial seals can be set on non-exclusive FDs. This is safe as both sides can, and always have to, verify that the required set of seals is set. Once they are set, neither side can extend, reduce or modify the set of seals as long as they have no exclusive reference.
Note that this exception also allows keeping read-only mmaps() around during initial sealing (mmaps() also own a reference to the file).
The new API is an extension to fcntl(), adding two new commands:
SHMEM_GET_SEALS: Return a bitset describing the seals on the file. This
can be called on any FD if the underlying file supports sealing.
SHMEM_SET_SEALS: Change the seals of a given file. This requires WRITE
access to the file. If at least one seal is already set, this also requires an exclusive reference. Note that this call will fail with EPERM if there is any active mapping with MAP_SHARED set.
The fcntl() handler is currently specific to shmem. There is no intention to support this on other file-systems, that's why the bits are prefixed with SHMEM_*. Furthermore, sealing is supported on all shmem-files. Setting seals requires write-access, so this doesn't allow any DoS attacks onto existing shmem users (just like mandatory locking).
--- fs/fcntl.c | 12 ++- include/linux/shmem_fs.h | 17 ++++ include/uapi/linux/fcntl.h | 13 +++ mm/shmem.c | 200 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 236 insertions(+), 6 deletions(-)
fs/fcntl.c +9 -3
@@ -21,6 +21,7 @@#include <linux/rcupdate.h> #include <linux/pid_namespace.h> #include <linux/user_namespace.h> +#include <linux/shmem_fs.h> #include <asm/poll.h> #include <asm/siginfo.h>
@@ -248,9 +249,10 @@ static int f_getowner_uids(struct file *filp, unsigned long arg)#endif static long do_fcntl (int fd,unsigned int cmd,unsigned long arg, -struct file *filp) +struct fd f) {long err = -EINVAL ; +struct file *filp = f.file;switch (cmd) {case F_DUPFD :
@@ -326,6 +328,10 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,case F_GETPIPE_SZ : err =pipe_fcntl (filp, cmd, arg);break ; +case SHMEM_SET_SEALS : +case SHMEM_GET_SEALS : + err =shmem_fcntl (f, cmd, arg); +break ;default :break ; }
@@ -360,7 +366,7 @@ SYSCALL_DEFINE3(fcntl, unsigned int, fd, unsigned int, cmd, unsigned long, arg) err =security_file_fcntl (f.file, cmd, arg);if (!err) - err =do_fcntl (fd, cmd, arg, f.file); + err =do_fcntl (fd, cmd, arg, f); out1:fdput (f);
@@ -397,7 +403,7 @@ SYSCALL_DEFINE3(fcntl64, unsigned int, fd, unsigned int, cmd, (struct flock64 __user *) arg);break ;default : - err =do_fcntl (fd, cmd, arg, f.file); + err =do_fcntl (fd, cmd, arg, f);break ; } out1:
include/linux/shmem_fs.h +17 -0
@@ -1,6 +1,7 @@#ifndef __SHMEM_FS_H#define __SHMEM_FS_H +#include <linux/file.h> #include <linux/swap.h> #include <linux/mempolicy.h> #include <linux/pagemap.h>
@@ -20,6 +21,7 @@ struct shmem_inode_info {struct shared_policy policy;/* NUMA memory alloc policy */ struct list_head swaplist;/* chain of maybes on swap */ struct simple_xattrs xattrs;/* list of xattrs */ +u32 seals;/* shmem seals */ struct inode vfs_inode; };
@@ -57,6 +59,21 @@ extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping,extern void shmem_truncate_range (struct inode *inode,loff_t start,loff_t end);extern int shmem_unuse (swp_entry_t entry,struct page *page); +#ifdef CONFIG_SHMEM + +extern int shmem_set_seals (struct file *file,u32 seals); +extern int shmem_get_seals (struct file *file); +extern long shmem_fcntl (struct fd f,unsigned int cmd,unsigned long arg); + +#else + +static inline long shmem_fcntl (struct fd f,unsigned int cmd,unsigned long arg) +{ +return -EINVAL ; +} + +#endif +static inline struct page *shmem_read_mapping_page (struct address_space *mapping,pgoff_t index) {
include/uapi/linux/fcntl.h +13 -0
@@ -28,6 +28,19 @@#define F_GETPIPE_SZ (F_LINUX_SPECIFIC_BASE + 8)/* +* Set/Get seals +*/ +#define SHMEM_SET_SEALS (F_LINUX_SPECIFIC_BASE + 9) +#define SHMEM_GET_SEALS (F_LINUX_SPECIFIC_BASE + 10) + +/* +* Types of seals +*/ +#define SHMEM_SEAL_SHRINK 0x0001/* prevent file from shrinking */ +#define SHMEM_SEAL_GROW 0x0002/* prevent file from growing */ +#define SHMEM_SEAL_WRITE 0x0004/* prevent writes */ + +/* * Types of directory notifications that may be requested. */ #define DN_ACCESS 0x00000001/* File accessed */
mm/shmem.c +197 -3
255 lines not on this page · raw message
Signature · 1 line
1.9.0
PATCH 3/6 shm: add memfd_create() syscall
In reply to David Herrmannmemfd_create() is similar to mmap(MAP_ANON), but returns a file-descriptor that you can pass to mmap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
memfd_create() does not create a front-FD, but instead returns the raw shmem file, so calls like ftruncate() can be used. Also calls like fstat() will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.
Compared to O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.
--- arch/x86/syscalls/syscall_32.tbl | 1 + arch/x86/syscalls/syscall_64.tbl | 1 + include/linux/syscalls.h | 1 + include/uapi/linux/memfd.h | 9 ++++++ kernel/sys_ni.c | 1 + mm/shmem.c | 67 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 include/uapi/linux/memfd.h
arch/x86/syscalls/syscall_32.tbl +1 -0
@@ -359,3 +359,4 @@ 350 i386 finit_module sys_finit_module 351 i386 sched_setattr sys_sched_setattr 352 i386 sched_getattr sys_sched_getattr +353 i386 memfd_create sys_memfd_create
arch/x86/syscalls/syscall_64.tbl +1 -0
@@ -322,6 +322,7 @@ 313 common finit_module sys_finit_module 314 common sched_setattr sys_sched_setattr 315 common sched_getattr sys_sched_getattr +316 common memfd_create sys_memfd_create # # x32-specific system call numbers start at 512 to avoid cache impact
include/linux/syscalls.h +1 -0
@@ -791,6 +791,7 @@ asmlinkage long sys_timerfd_settime(int ufd, int flags,asmlinkage long sys_timerfd_gettime (int ufd,struct itimerspec __user *otmr);asmlinkage long sys_eventfd (unsigned int count);asmlinkage long sys_eventfd2 (unsigned int count,int flags); +asmlinkage long sys_memfd_create (const char *uname_ptr,u64 size,u64 flags);asmlinkage long sys_fallocate (int fd,int mode,loff_t offset,loff_t len);asmlinkage long sys_old_readdir (unsigned int ,struct old_linux_dirent __user *,unsigned int ); asmlinkage long sys_pselect6(int, fd_set __user *, fd_set __user *,
include/uapi/linux/memfd.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _UAPI_LINUX_MEMFD_H +#define _UAPI_LINUX_MEMFD_H + +#include <linux/types.h> + +/* flags for memfd_create(2) */ +#define MFD_CLOEXEC 0x0001 + +#endif /* _UAPI_LINUX_MEMFD_H */
kernel/sys_ni.c +1 -0
@@ -193,6 +193,7 @@ cond_syscall(compat_sys_timerfd_settime);cond_syscall (compat_sys_timerfd_gettime);cond_syscall (sys_eventfd);cond_syscall (sys_eventfd2); +cond_syscall (sys_memfd_create);/* performance counters: */ cond_syscall (sys_perf_event_open);
mm/shmem.c +67 -0
80 lines not on this page · raw message
Signature · 1 line
1.9.0
Re: [PATCH 3/6] shm: add memfd_create() syscall
Quoted 6 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
Quoted 7 lines
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.
If I'm not mistaken in something obvious, this looks similar to /proc/pid/map_files feature, Pavel?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/6] shm: add memfd_create() syscall
Quoted 12 lines · Cyrill Gorcunov
Quoted 11 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.
Quoted 5 lines
Quoted 2 lines
Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.If I'm not mistaken in something obvious, this looks similar to
/proc/pid/map_filesfeature, Pavel?
Thanks, Cyrill.
It is, but the map_files will work "in the opposite direction" :) In the memfd case one first gets an FD, then mmap()s it; in the /proc/pis/map_files case one should first mmap() a region, then open it via /proc/self/map_files.
But I don't know whether this matters.
Thanks,
Pavel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/6] shm: add memfd_create() syscall
Hi
Quoted 9 lines · Pavel Emelyanov
Quoted 2 lines · Cyrill Gorcunov
If I'm not mistaken in something obvious, this looks similar to
/proc/pid/map_filesfeature, Pavel?It is, but the
map_fileswill work "in the opposite direction" :) In the memfd case one first gets an FD, then mmap()s it; in the/proc/pis/map_filescase one should firstmmap()a region, then open it via/proc/self/map_files.But I don't know whether this matters.
Yes, you can replace memfd_create() so far with:
p = mmap(NULL, size, ..., MAP_ANON | MAP_SHARED, -1, 0); sprintf(path, "/proc/self/map_files/%lx-%lx", p, p + size); fd = open(path, O_RDWR);
However, map_files is only enabled with CONFIG_CHECKPOINT_RESTORE, the /proc/pid/map_files/ directory is root-only (at least I get EPERM if non-root), it doesn't provide the "name" argument which is very handy for debugging, it doesn't explicitly support sealing (it requires MAP_ANON to be backed by shmem) and it's a very weird API for something this simple.
Thanks
David
Re: [PATCH 3/6] shm: add memfd_create() syscall
Quoted 13 lines · David Herrmann
Hi
Quoted 9 lines · Pavel Emelyanov
Quoted 2 lines · Cyrill Gorcunov
If I'm not mistaken in something obvious, this looks similar to
/proc/pid/map_filesfeature, Pavel?It is, but the
map_fileswill work "in the opposite direction" :) In the memfd case one first gets an FD, then mmap()s it; in the/proc/pis/map_filescase one should firstmmap()a region, then open it via/proc/self/map_files.But I don't know whether this matters.
Quoted 8 lines
Yes, you can replace
memfd_create()so far with:
p =mmap(NULL, size, ..., MAP_ANON | MAP_SHARED, -1, 0);sprintf(path, "/proc/self/map_files/%lx-%lx", p, p + size); fd =open(path, O_RDWR);However,
map_filesis only enabled withCONFIG_CHECKPOINT_RESTORE, the/proc/pid/map_files/directory is root-only (at least I get EPERM if non-root),
Yes. But this is something we'd also like to have fixed :) Having two parties willing the same makes it easier for the patch to get accepted.
Quoted 2 lines
it doesn't provide the "name" argument which is very handy for debugging,
What if we make mmap's shmem_zero_setup() generate a meaningful name, would it solve the debugging issue?
Quoted 2 lines
it doesn't explicitly support sealing (it requires
MAP_ANONto be backed by shmem)
Can you elaborate on this? The fd generated by sys_memfd() will be shmem-backed, so will be the file opened via map_files link for the MAP_ANON | MAP_SHARED mapping. So what are the problems to make it support sealing?
Quoted 1 line
and it's a very weird API for something this simple.
:)
Thanks,
Pavel
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/6] shm: add memfd_create() syscall
In reply to David HerrmannQuoted 6 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
Quoted 7 lines
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.
This syscall would also be useful to Android, since it would satisfy the requirement for providing atomically unlinked tmpfs fds that ashmem provides (although upstreamed solutions to ashmem's other functionalities are still needed).
My only comment is that I think memfd_* is sort of a new namespace. Since this is providing shmem files, it seems it might be better named something like shmfd_create() or my earlier suggestion of shmget_fd(). Otherwise, when talking about functionality like sealing, which is only available on shmfs, we'll have to say "shmfs/tmpfs/memfd" or risk confusing folks who might not initially grasp that its all the same underneath.
thanks
-john
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/6] shm: add memfd_create() syscall
In reply to David HerrmannQuoted 6 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
Quoted 7 lines
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.
Instead of adding new syscall we can extend existing openat() a little bit more:
openat(AT_FDSHM, "name", O_TMPFILE | O_RDWR, 0666)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Re: [PATCH 3/6] shm: add memfd_create() syscall
Hi
Quoted 12 lines · Konstantin Khlebnikov
Quoted 11 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.
Quoted 7 lines
Quoted 2 lines
Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.Instead of adding new syscall we can extend existing
openat()a little bit more:
openat(AT_FDSHM, "name", O_TMPFILE | O_RDWR, 0666)
O_TMPFILE requires an existing directory as "name". So you have to use:
open("/run/", O_TMPFILE | O_RDWR, 0666)
instead of
open("/run/new_file", O_TMPFILE | O_RDWR, 0666)
We _really_ want to set a name for the inode, though. Otherwise, debug-info via /proc/pid/fd/ is useless.
Furthermore, Linus requested to allow sealing only on files that _explicitly_ allow sealing. So v2 of this series will have MFD_ALLOW_SEALING as memfd_create() flag. I don't think we can do this with linkat() (or is that meant to be implicit for the new AT_FDSHM?). Last but not least, you now need a separate syscall to set the file-size.
I could live with most of these issues, except for the name-thing. Ideas?
Thanks
David
Re: [PATCH 3/6] shm: add memfd_create() syscall
Quoted 31 lines · David Herrmann
Hi
Quoted 12 lines · Konstantin Khlebnikov
Quoted 11 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.Quoted 7 lines
Quoted 2 lines
Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.Instead of adding new syscall we can extend existing
openat()a little bit more:
openat(AT_FDSHM, "name", O_TMPFILE | O_RDWR, 0666)
O_TMPFILErequires an existing directory as "name". So you have to use:
open("/run/", O_TMPFILE | O_RDWR, 0666)
instead of
open("/run/new_file", O_TMPFILE | O_RDWR, 0666)We _really_ want to set a name for the inode, though. Otherwise, debug-info via
/proc/pid/fd/is useless.
Quoted 8 lines
Furthermore, Linus requested to allow sealing only on files that _explicitly_ allow sealing. So v2 of this series will have
MFD_ALLOW_SEALINGasmemfd_create()flag. I don't think we can do this withlinkat()(or is that meant to be implicit for the newAT_FDSHM?). Last but not least, you now need a separate syscall to set the file-size.I could live with most of these issues, except for the name-thing. Ideas?
Hmm, why AT_FDSHM + O_TMPFILE pair cannot has different naming behavior? Actually O_TMPFILE flag is optional here. AT_FDSHM is enough, but O_TMPFILE allows to
move branching out of common fast-paths and hide it inside do_tmpfile.
BTW you can set some extended attribute via fsetxattr and distinguish files in proc by its value.
OR you could add fcntl() for changing 'name' of tmpfiles. In combination with AT_FDSHM this
would give complete solution without changing O_TMPFILE naming scheme. But one syscall turns into three. )
--
Re: [PATCH 3/6] shm: add memfd_create() syscall
In reply to Konstantin KhlebnikovQuoted 12 lines · Konstantin Khlebnikov
Quoted 11 lines · David Herrmann
memfd_create()is similar tommap(MAP_ANON), but returns a file-descriptor that you can pass tommap(). It explicitly allows sealing and avoids any connection to user-visible mount-points. Thus, it's not subject to quotas on mounted file-systems, but can be used like malloc()'ed memory, but with a file-descriptor to it.
memfd_create()does not create a front-FD, but instead returns the raw shmem file, so calls likeftruncate()can be used. Also calls likefstat()will return proper information and mark the file as regular file. Sealing is explicitly supported on memfds.
Quoted 7 lines
Quoted 2 lines
Compared to
O_TMPFILE, it does not require a tmpfs mount-point and is not subject to quotas and alike.Instead of adding new syscall we can extend existing
openat()a little bit more:
openat(AT_FDSHM, "name", O_TMPFILE | O_RDWR, 0666)
Please don't. O_TMPFILE is a messy enough API, and the last thing we need to do is to extend it. If we want a fancy API for creating new inodes with no corresponding dentry, let's create one.
Otherwise, let's just stick with a special-purpose API for these shm files.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 4/6 selftests: add memfd_create() + sealing tests
In reply to David HerrmannSome basic tests to verify sealing on memfds works as expected and guarantees the advertised semantics.
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/memfd/.gitignore | 2 + tools/testing/selftests/memfd/Makefile | 29 + tools/testing/selftests/memfd/memfd_test.c | 972 +++++++++++++++++++++++++++++ 4 files changed, 1004 insertions(+) create mode 100644 tools/testing/selftests/memfd/.gitignore create mode 100644 tools/testing/selftests/memfd/Makefile create mode 100644 tools/testing/selftests/memfd/memfd_test.c
tools/testing/selftests/Makefile +1 -0
@@ -2,6 +2,7 @@ TARGETS = breakpoints TARGETS += cpu-hotplug TARGETS += efivarfs TARGETS += kcmp +TARGETS += memfd TARGETS += memory-hotplug TARGETS += mqueue TARGETS += net
tools/testing/selftests/memfd/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +memfd_test +memfd-test-file
tools/testing/selftests/memfd/Makefile new file +29 -0
@@ -0,0 +1,29 @@ +uname_M := $(shell uname -m 2>/dev/null || echo not) +ARCH ?= $(shell echo $(uname_M) | sed -e s/i.86/i386/) +ifeq ($(ARCH),i386) + ARCH := X86 +endif +ifeq ($(ARCH),x86_64) + ARCH := X86 +endif + +CFLAGS += -I../../../../arch/x86/include/generated/uapi/ +CFLAGS += -I../../../../arch/x86/include/uapi/ +CFLAGS += -I../../../../include/uapi/ +CFLAGS += -I../../../../include/ + +all: +ifeq ($(ARCH),X86) + gcc $(CFLAGS) memfd_test.c -o memfd_test +else + echo "Not an x86 target, can't build memfd selftest" +endif + +run_tests: all +ifeq ($(ARCH),X86) + gcc $(CFLAGS) memfd_test.c -o memfd_test +endif + @./memfd_test || echo "memfd_test: [FAIL]" + +clean: + $(RM) memfd_test
tools/testing/selftests/memfd/memfd_test.c new file +972 -0
972 lines not on this page · raw message
Signature · 7 lines
1.9.0 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 5/6 fcntl.2: document SHMEM_SET/GET_SEALS commands
In reply to David HerrmannThe SHMEM_GET_SEALS and SHMEM_SET_SEALS commands allow retrieving and modifying the active set of seals on a file. They're only supported on selected file-systems (currently shmfs) and are linux-only.
--- man2/fcntl.2 | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+)
man2/fcntl.2 +90 -0
@@ -57,6 +57,8 @@ .\" Document F_SETOWN_EX and F_GETOWN_EX .\" 2010-06-17, Michael Kerrisk .\" Document F_SETPIPE_SZ and F_GETPIPE_SZ. +.\" 2014-03-19, David Herrmann <[email protected]> +.\" Document SHMEM_SET_SEALS and SHMEM_GET_SEALS .\" .TH FCNTL 2 2014-02-20 "Linux" "Linux Programmer's Manual" .SH NAME
@@ -1064,6 +1066,94 @@ of buffer space currently used to store data produces the error .BR F_GETPIPE_SZ " (\fIvoid\fP; since Linux 2.6.35)" Return (as the function result) the capacity of the pipe referred to by .IR fd . +.SS File Sealing +Sealing files limits the set of allowed operations on a given file. For each +seal that is set on a file, a specific set of operations will fail with +.B EPERM +on this file from now on. The file is said to be sealed. A file does not have +any seals set by default. Moreover, most filesystems do not support sealing +(only shmfs implements it right now). The following seals are available: +.RS +.TP +.BR SHMEM_SEAL_SHRINK +If this seal is set, the file in question cannot be reduced in size. This +affects +.BR open (2) +with the +.B O_TRUNC +flag and +.BR ftruncate (2). +They will fail with +.B EPERM +if you try to shrink the file in question. Increasing the file size is still +possible. +.TP +.BR SHMEM_SEAL_GROW +If this seal is set, the size of the file in question cannot be increased. This +affects +.BR write (2) +if you write across size boundaries, +.BR ftruncate (2) +and +.BR fallocate (2). +These calls will fail with +.B EPERM +if you use them to increase the file size or write beyond size boundaries. If +you keep the size or shrink it, those calls still work as expected. +.TP +.BR SHMEM_SEAL_WRITE +If this seal is set, you cannot modify data contents of the file. Note that +shrinking or growing the size of the file is still possible and allowed. Thus, +this seal is normally used in combination with one of the other seals. This seal +affects +.BR write (2) +and +.BR fallocate (2) +(only in combination with the +.B FALLOC_FL_PUNCH_HOLE +flag). Those calls will fail with +.B EPERM +if this seal is set. Furthermore, trying to create new memory-mappings via +.BR mmap (2) +in combination with +.B MAP_SHARED +will also fail with +.BR EPERM . +.RE +.TP +.BR SHMEM_SET_SEALS " (\fIint\fP; since Linux TBD)" +Change the set of seals of the file referred to by +.I fd +to +.IR arg . +You are required to own an exclusive reference to the file in question in order +to modify the seals. Otherwise, this call will fail with +.BR EPERM . +There is one exception: If no seals are set, this restriction does not apply and +you can set seals even if you don't own an exclusive reference. However, in any +case there may not exist any shared writable mapping or this call will always +fail with +.BR EPERM . +These semantics guarantee that once you verified a specific set of seals is set +on a given file, nobody besides you (in case you own an exclusive reference) can +modify the seals, anymore. + +You own an exclusive reference to a file if, and only if, the file-descriptor +passed to +.BR fcntl (2) +is the only reference to the underlying inode. There must not be any duplicates +of this file-descriptor, no other open files to the same underlying inode, no +hard-links or any active memory mappings. +.TP +.BR SHMEM_GET_SEALS " (\fIvoid\fP; since Linux TBD)" +Return (as the function result) the current set of seals of the file referred to +by +.IR fd . +If no seals are set, 0 is returned. If the file does not support sealing, -1 is +returned and +.I errno +is set to +.BR EINVAL . .SH RETURN VALUE For a successful call, the return value depends on the operation: .TP 0.9i
Signature · 1 line
1.9.0
PATCH 6/6 memfd_create.2: add memfd_create() man-page
In reply to David HerrmannThe memfd_create() syscall creates anonymous files similar to O_TMPFILE but does not require an active mount-point.
--- man2/memfd_create.2 | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 man2/memfd_create.2
man2/memfd_create.2 new file +110 -0
@@ -0,0 +1,110 @@ +.\" Copyright (C) 2014 David Herrmann <[email protected]> +.\" starting from a version by Michael Kerrisk <[email protected]> +.\" +.\" %%%LICENSE_START(GPLv2+_SW_3_PARA) +.\" 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 manual; if not, see +.\" <http://www.gnu.org/licenses/>. +.\" %%%LICENSE_END +.\" +.TH MEMFD_CREATE 2 2014-03-18 Linux "Linux Programmer's Manual" +.SH NAME +memfd_create \- create an anonymous file +.SH SYNOPSIS +.B #include <sys/memfd.h> +.sp +.BI "int memfd_create(const char *" name ", u64 " size ", u64 " flags ");" +.SH DESCRIPTION +.BR memfd_create () +creates an anonymous file and returns a file-descriptor to it. The file behaves +like regular files, thus can be modified, truncated, memory-mapped and more. +However, unlike regular files it lives in main memory and has no non-volatile +backing storage. Once all references to the file are dropped, it is +automatically released. Like all shmem-based files, memfd files support +.BR SHMEM +sealing parameters. See +.BR SHMEM_SET_SEALS " with " fcntl (2) +for more information. + +The initial size of the file is set to +.IR size ". " name +is used as internal file-name and will occur as such in +.IR /proc/self/fd/ . +The name is always prefixed with +.BR memfd: +and serves only debugging purposes. + +The following values may be bitwise ORed in +.IR flags +to change the behaviour of +.BR memfd_create (): +.TP +.BR MFD_CLOEXEC +Set the close-on-exec +.RB ( FD_CLOEXEC ) +flag on the new file descriptor. +See the description of the +.B O_CLOEXEC +flag in +.BR open (2) +for reasons why this may be useful. +.PP +Unused bits must be cleared to 0. + +As its return value, +.BR memfd_create () +returns a new file descriptor that can be used to refer to the file. +A copy of the file descriptor created by +.BR memfd_create () +is inherited by the child produced by +.BR fork (2). +The duplicate file descriptor is associated with the same file. +File descriptors created by +.BR memfd_create () +are preserved across +.BR execve (2), +unless the close-on-exec flag has been set. +.SH RETURN VALUE +On success, +.BR memfd_create () +returns a new file descriptor. +On error, \-1 is returned and +.I errno +is set to indicate the error. +.SH ERRORS +.TP +.B EINVAL +An unsupported value was specified in one of the arguments. +.TP +.B EMFILE +The per-process limit on open file descriptors has been reached. +.TP +.B ENFILE +The system-wide limit on the total number of open files has been +reached. +.TP +.B EFAULT +The name given in +.IR name +points to invalid memory. +.TP +.B ENOMEM +There was insufficient memory to create a new anonymous file. +.SH VERSIONS +to-be-defined +.SH CONFORMING TO +.BR memfd_create () +is Linux-specific. +.SH SEE ALSO +.BR shmget (2), +.BR fcntl (2),
Signature · 1 line
1.9.0
Quoted 35 lines · David Herrmann
Hi
This series introduces the concept of "file sealing". Sealing a file restricts the set of allowed operations on the file in question. Multiple seals are defined and each seal will cause a different set of operations to return EPERM if it is set. The following seals are introduced:
*
SEAL_SHRINK: If set, the inode size cannot be reduced
*SEAL_GROW: If set, the inode size cannot be increased
*SEAL_WRITE: If set, the file content cannot be modifiedUnlike existing techniques that provide similar protection, sealing allows file-sharing without any trust-relationship. This is enforced by rejecting seal modifications if you don't own an exclusive reference to the given file. So if you own a file-descriptor, you can be sure that no-one besides you can modify the seals on the given file. This allows mapping shared files from untrusted parties without the fear of the file getting truncated or modified by an attacker.
Several use-cases exist that could make great use of sealing:
1) Graphics Compositors
If a graphics client creates a memory-backed render-buffer and passes a file-decsriptor to it to the graphics server for display, the server _has_ to setup SIGBUS handlers whenever mapping the given file. Otherwise, the client might runftruncate()orO_TRUNCon the on file in parallel, thus crashing the server.
With sealing, a compositor can reject any incoming file-descriptor that does _not_ haveSEAL_SHRINKset. This way, any memory-mappings are guaranteed to stay accessible. Furthermore, we still allow clients to increase the buffer-size in case they want to resize the render-buffer for the next frame. We also allow parallel writes so the client can render new frames into the same buffer (client is responsible of never rendering into a front-buffer if you want to avoid artifacts).
Quoted 1 line
Real use-case: Wayland
wl_shmbuffers can be transparently converted
Very nice, the Enlightenment developers have been asking for something like this for a while, it should help them out a lot as well.
And thanks for the man pages and test code, if only all new apis came with that already...
greg k-h
Quoted 4 lines · David Herrmann
Unlike existing techniques that provide similar protection, sealing allows file-sharing without any trust-relationship. This is enforced by rejecting seal modifications if you don't own an exclusive reference to the given file.
I like the concept, but I really hate that "exclusive reference" approach. I see why you did it, but I also worry that it means that people can open random shm files that are *not* expected to be sealed, and screw up applications that don't expect it.
Is there really any use-case where the sealer isn't also the same thing that *created* the file in the first place? Because I would be a ton happier with the notion that you can only seal things that you yourself created. At that point, the exclusive reference isn't such a big deal any more, but more importantly, you can't play random denial-of-service games on files that aren't really yours.
The fact that you bring up the races involved with the exclusive reference approach also just makes me go "Is that really the correct security model"?
Linus
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 6 lines · Linus Torvalds
Is there really any use-case where the sealer isn't also the same thing that *created* the file in the first place? Because I would be a ton happier with the notion that you can only seal things that you yourself created. At that point, the exclusive reference isn't such a big deal any more, but more importantly, you can't play random denial-of-service games on files that aren't really yours.
My first idea was to add MFD_ALLOW_SEALING as memfd_create() flag, which enables the sealing-API for that file. Then I looked at POSIX mandatory locking and noticed that it provides similar restrictions on _all_ files. Mandatory locks can be more easily removed, but an attacker could just re-apply them in a loop, so that's not really an argument. Furthermore, sealing requires _write_ access so I wonder what kind of DoS attacks are possible with sealing that are not already possible with write access? And sealing is only possible if no writable, shared mapping exists. So even if an attacker seals a file, all that happens is EPERM, not SIGBUS (still a possible denial-of-service scenario).
But I understand that it is quite hard to review all the possible scenarios. So I'm fine with checking inode-ownership permissions for SET_SEALS. We could also make sealing a one-shot operation. Given that in a no-trust situation there is never a guarantee that the other side drops its references, re-using a sealed file is usually not possible. However, in sane environments, this could be a nice optimization in case the other side plays along. The one-shot semantics would allow dropping reference-checks entirely. The inode-ownership semantics would still require it.
Thanks
David
Quoted 2 lines
My first idea was to add
MFD_ALLOW_SEALINGasmemfd_create()flag, which enables the sealing-API for that file. Then I looked at POSIX
This actually seems the most sensible to me. The reason being that if I have some existing used object there is no way on earth I can be sure who has existing references to it, and we don't have revoke() to fix that.
So it pretty much has to be a new object in a sane programming model.
Quoted 2 lines
mandatory locking and noticed that it provides similar restrictions on _all_ files. Mandatory locks can be more easily removed, but an
The fact someone got it past a standards body doesn't make it a good idea.
Quoted 7 lines
attacker could just re-apply them in a loop, so that's not really an argument. Furthermore, sealing requires _write_ access so I wonder what kind of DoS attacks are possible with sealing that are not already possible with write access? And sealing is only possible if no writable, shared mapping exists. So even if an attacker seals a file, all that happens is EPERM, not SIGBUS (still a possible denial-of-service scenario).
I think you want two things at minimum
owner to seal
root can always override
I would query the name too. Right now your assumption is 'shmem only' but that might change with other future use cases or types (eg some driver file handles) so SHMEM_ in the fcntl might become misleading.
Whether you want some way to undo a seal without an exclusive reference as the file owner is another question.
Alan
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 4 lines · One Thousand Gnomes
I think you want two things at minimum
owner to seal
root can always override
Why should root be allowed to override?
Quoted 3 lines
I would query the name too. Right now your assumption is 'shmem only' but that might change with other future use cases or types (eg some driver file handles) so
SHMEM_in the fcntl might become misleading.
I'm fine with F_SET/GET_SEALS. But given you suggested requiring MFD_ALLOW_SEALS for sealing, I don't see why we couldn't limit this interface entirely to memfd_create().
Quoted 2 lines
Whether you want some way to undo a seal without an exclusive reference as the file owner is another question.
No. You are never allowed to undo a seal but with an exclusive reference. This interface was created for situations _without_ any trust relationship. So if the owner is allowed to undo seals, the interface doesn't make any sense. The only options I see is to not allow un-sealing at all (which I'm fine with) or tracking users (which is way too much overhead).
Thanks
David
Quoted 10 lines · On Thu, 20 Mar 2014 16:12:54 +0100 David Herrmann <[email protected]> wrote:
Hi
Quoted 4 lines · One Thousand Gnomes
I think you want two things at minimum
owner to seal
root can always overrideWhy should root be allowed to override?
Because root can already override it by say mmapping the kernel memory and patching. It also tends to be valuable for debugging horrible problems with complex systems.
Imposing fake restrictions on root just causes annoyance when doing stuff like debugging but doesn't actually change the security situation.
Quoted 4 lines
I'm fine with F_SET/GET_SEALS. But given you suggested requiring
MFD_ALLOW_SEALSfor sealing, I don't see why we couldn't limit this interface entirely tomemfd_create().
But if someone does find a non memfd use for it then it's useful not to have to go "this fnctl for memfd, that fnctl for the other"
Just planning ahead.
Quoted 9 lines
Quoted 2 lines
Whether you want some way to undo a seal without an exclusive reference as the file owner is another question.
No. You are never allowed to undo a seal but with an exclusive reference. This interface was created for situations _without_ any trust relationship. So if the owner is allowed to undo seals, the interface doesn't make any sense. The only options I see is to not allow un-sealing at all (which I'm fine with) or tracking users (which is way too much overhead).
Ok - that makes sense
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 9 lines · David Herrmann
This series introduces the concept of "file sealing". Sealing a file restricts the set of allowed operations on the file in question. Multiple seals are defined and each seal will cause a different set of operations to return EPERM if it is set. The following seals are introduced:
*
SEAL_SHRINK: If set, the inode size cannot be reduced
*SEAL_GROW: If set, the inode size cannot be increased
*SEAL_WRITE: If set, the file content cannot be modified
Looking at your patches, and what files you are modifying, you are enforcing this in the low-level file system.
Why not make sealing an attribute of the "struct file", and enforce it at the VFS layer? That way all file system objects would have access to sealing interface, and for memfd_shmem, you can't get another struct file pointing at the object, the security properties would be identical.
Cheers,
- Ted
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · On Thu, 20 Mar 2014 11:32:51 -0400 [email protected] wrote:
Quoted 9 lines · David Herrmann
This series introduces the concept of "file sealing". Sealing a file restricts the set of allowed operations on the file in question. Multiple seals are defined and each seal will cause a different set of operations to return EPERM if it is set. The following seals are introduced:
*
SEAL_SHRINK: If set, the inode size cannot be reduced
*SEAL_GROW: If set, the inode size cannot be increased
*SEAL_WRITE: If set, the file content cannot be modified
Quoted 8 lines
Looking at your patches, and what files you are modifying, you are enforcing this in the low-level file system.
Why not make sealing an attribute of the "struct file", and enforce it at the VFS layer? That way all file system objects would have access to sealing interface, and for
memfd_shmem, you can't get another struct file pointing at the object, the security properties would be identical.
Would it be more sensible to have a "sealer" which is a "device" which you give a file handle too and it gives you back a sealable one.
So for the memfd case you'd create a private handle, pass it to the sealer, and then pass the sealer handles to everyone else.
You have to implicitly trust the creator of the object has
- handed you the object you expect
- sealed it
so that appears no weaker but means you can meaningfully created sealed versions of arbitary objects and if you want have non-sealed ones around with it being up to the creator if they want for example to simply close the unsealed one immediately afterwards.
Alan
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 5 lines · On Thu, Mar 20, 2014 at 4:32 PM, <[email protected]> wrote:
Why not make sealing an attribute of the "struct file", and enforce it at the VFS layer? That way all file system objects would have access to sealing interface, and for
memfd_shmem, you can't get another struct file pointing at the object, the security properties would be identical.
Sealing as introduced here is an inode-attribute, not "struct file". This is intentional. For instance, a gfx-client can get a read-only FD via /proc/self/fd/ and pass it to the compositor so it can never overwrite the contents (unless the compositor has write-access to the inode itself, in which case it can just re-open it read-write).
Furthermore, I don't see any use-case besides memfd for sealing, so I purposely avoided changing core VFS interfaces. Protecting page-allocation/access for SEAL_WRITE like I do in shmem.c is not that easy to do generically. So if we moved this interface to "struct inode", all that would change is moving "u32 seals;" from one struct to the other. Ok, some protections might get easily implemented generically, but I without proper insight in the underlying implemenation, I couldn't verify all paths and possible races. Isn't keeping the API generic enough so far? Changing the underlying implementation can be done once we know what we want.
Thanks
David
Quoted 7 lines · David Herrmann
Quoted 5 lines · On Thu, Mar 20, 2014 at 4:32 PM, <[email protected]> wrote:
Why not make sealing an attribute of the "struct file", and enforce it at the VFS layer? That way all file system objects would have access to sealing interface, and for
memfd_shmem, you can't get another struct file pointing at the object, the security properties would be identical.
Quoted 5 lines
Sealing as introduced here is an inode-attribute, not "struct file". This is intentional. For instance, a gfx-client can get a read-only FD via
/proc/self/fd/and pass it to the compositor so it can never overwrite the contents (unless the compositor has write-access to the inode itself, in which case it can just re-open it read-write).
Hmm, good point. I had forgotten about the /proc/self/fd hole. Hmm... what if we have a SEAL_PROC which forces the permissions of /proc/self/fd to be 000?
So if it is a property of the attribute, SEAL_WRITE and SEAL_GROW is basically equivalent to using chattr to set the immutable and append-only attribute, except for the "you can't undo the seal unless you have exclusive access to the inode" magic.
That does make it pretty memfd_create specific and not a very general API, which is a little unfortunate; hence why I'm trying to explore ways of making a bit more generic and hopefully useful for more use cases.
Cheers,
- Ted
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 14 lines · On 03/20/2014 09:38 AM, [email protected] wrote:
Quoted 7 lines · David Herrmann
Quoted 5 lines · On Thu, Mar 20, 2014 at 4:32 PM, <[email protected]> wrote:
Why not make sealing an attribute of the "struct file", and enforce it at the VFS layer? That way all file system objects would have access to sealing interface, and for
memfd_shmem, you can't get another struct file pointing at the object, the security properties would be identical.Quoted 5 lines
Sealing as introduced here is an inode-attribute, not "struct file". This is intentional. For instance, a gfx-client can get a read-only FD via
/proc/self/fd/and pass it to the compositor so it can never overwrite the contents (unless the compositor has write-access to the inode itself, in which case it can just re-open it read-write).
Quoted 3 lines
Hmm, good point. I had forgotten about the
/proc/self/fdhole. Hmm... what if we have aSEAL_PROCwhich forces the permissions of/proc/self/fdto be 000?
This is the second time in a week that someone has asked for a way to have a struct file (or struct inode or whatever) that can't be reopened through /proc/pid/fd. This should be quite easy to implement as a separate feature.
Actually, that feature would solve a major pet peeve of mine, I think: I want something like memfd that allows me to keep the thing read-write but that whomever I pass the fd to can't change. With this feature, I could do:
fd_rw = memfd_create (or O_TMPFILE or whatever)fd_ro = open(/proc/self/fd/fd_ro, O_RDONLY);fcntl(fd_ro, F_RESTRICT, F_RESTRICT_REOPEN);
send fd_ro via SCM_RIGHTS.
To really make this work well, I also want to SEAL_SHRINK the inode so that the receiver can verify that I'm not going to truncate the file out from under it.
Bingo, fast and secure one-way IPC.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 5 lines · Andy Lutomirski
This is the second time in a week that someone has asked for a way to have a struct file (or struct inode or whatever) that can't be reopened through
/proc/pid/fd. This should be quite easy to implement as a separate feature.
What I suggested on a different thread was to add the following new file descriptor flags, to join FD_CLOEXEC, which would be maniuplated using the F_GETFD and F_SETFD fcntl commands:
FD_NOPROCFS disallow being able to open the inode via /proc/<pid>/fd
FD_NOPASSFD disallow being able to pass the fd via a unix domain socket
FD_LOCKFLAGS if this bit is set, disallow any further changes of FD_CLOEXEC,
FD_NOPROCFS, FD_NOPASSFD, and FD_LOCKFLAGS flags.
Regardless of what else we might need to meet the use case for the proposed File Sealing API, I think this is a useful feature that could be used in many other contexts besides just the proposed memfd_create() use case.
Cheers,
- Ted
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 15 lines · Theodore Ts'o
Quoted 5 lines · Andy Lutomirski
This is the second time in a week that someone has asked for a way to have a struct file (or struct inode or whatever) that can't be reopened through
/proc/pid/fd. This should be quite easy to implement as a separate feature.What I suggested on a different thread was to add the following new file descriptor flags, to join
FD_CLOEXEC, which would be maniuplated using theF_GETFDandF_SETFDfcntl commands:
FD_NOPROCFSdisallow being able to open the inode via /proc/<pid>/fd
FD_NOPASSFDdisallow being able to pass the fd via a unix domain socket
Quoted 7 lines
FD_LOCKFLAGSif this bit is set, disallow any further changes ofFD_CLOEXEC,
FD_NOPROCFS,FD_NOPASSFD, andFD_LOCKFLAGSflags.Regardless of what else we might need to meet the use case for the proposed File Sealing API, I think this is a useful feature that could be used in many other contexts besides just the proposed
memfd_create()use case.
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the /proc/self/fd issue for real -- we could just make open("/proc/self/fd/3", O_RDWR) fail if fd 3 is read-only. That may be enough for the file sealing thing.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 4 lines · Andy Lutomirski
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the
/proc/self/fdissue for real -- we could just makeopen("/proc/self/fd/3", O_RDWR)fail if fd 3 is read-only. That may be enough for the file sealing thing.
For the sealing API, none of this is needed. As long as the inode is owned by the uid who creates the memfd, you can pass it around and no-one besides root and you can open /proc/self/fd/$fd (assuming chmod 700). If you share the fd with someone with the same uid as you, you're screwed anyway. We don't protect users against themselves (I mean, they can ptrace you, or kill()..). Therefore, I'm not really convinced that we want this for memfd. At least no-one has provided a _proper_ use-case for this so far.
Thanks
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 8 lines · David Herrmann
Hi
Quoted 4 lines · Andy Lutomirski
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the
/proc/self/fdissue for real -- we could just makeopen("/proc/self/fd/3", O_RDWR)fail if fd 3 is read-only. That may be enough for the file sealing thing.
Quoted 8 lines
For the sealing API, none of this is needed. As long as the inode is owned by the uid who creates the memfd, you can pass it around and no-one besides root and you can open
/proc/self/fd/$fd(assuming chmod 700). If you share the fd with someone with the same uid as you, you're screwed anyway. We don't protect users against themselves (I mean, they can ptrace you, orkill()..). Therefore, I'm not really convinced that we want this for memfd. At least no-one has provided a _proper_ use-case for this so far.
Hmm. Fair enough.
Would it make sense for the initial mode on a memfd inode to be 000? Anyone who finds this to be problematic could use fchmod to fix it.
I might even go so far as to suggest that the default uid on the inode should be 0 (i.e. global root), since there is the odd corner case of root setting euid != 0, creating a memfd, and setting euid back to 0. The latter might cause resource accounting issues, though.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 2 lines · Andy Lutomirski
Would it make sense for the initial mode on a memfd inode to be 000? Anyone who finds this to be problematic could use fchmod to fix it.
memfd_create() should be subject to umask() just like anything else. That should solve any possible race here, right?
Thanks
David
Quoted 8 lines · David Herrmann
Hi
Quoted 2 lines · Andy Lutomirski
Would it make sense for the initial mode on a memfd inode to be 000? Anyone who finds this to be problematic could use fchmod to fix it.
memfd_create()should be subject toumask()just like anything else. That should solve any possible race here, right?
Yes, but how many people will actually think about umask when doing things that don't really look like creating files?
/proc/pid/fd is a really weird corner case in which the mode of an inode that doesn't have a name matters. I suspect that almost no one will ever want to open one of these things out of /proc/self/fd, and those who do should be made to think about it.
It also avoids odd screwups where things are secure until someone runs them with umask 000.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 4 lines · Andy Lutomirski
/proc/pid/fdis a really weird corner case in which the mode of an inode that doesn't have a name matters. I suspect that almost no one will ever want to open one of these things out of/proc/self/fd, and those who do should be made to think about it.
I'm arguing in the context of memfd, and there's no security leak if people get access to the underlying inode (at least I'm not aware of any). As I said, context information is attached to the inode, not file context, so I'm fine if people want to open multiple file contexts via /proc. If someone wants to forbid open(), I want to hear _why_. I assume the memfd object has uid==uid-of-creator and mode==(777 & ~umask) (which usually results in X00, so no access for non-owners). I cannot see how /proc is a security issue here.
Thanks
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 11 lines · David Herrmann
Hi
Quoted 4 lines · Andy Lutomirski
/proc/pid/fdis a really weird corner case in which the mode of an inode that doesn't have a name matters. I suspect that almost no one will ever want to open one of these things out of/proc/self/fd, and those who do should be made to think about it.I'm arguing in the context of memfd, and there's no security leak if people get access to the underlying inode (at least I'm not aware of any).
I'm not sure what you mean.
Quoted 6 lines
As I said, context information is attached to the inode, not file context, so I'm fine if people want to open multiple file contexts via /proc. If someone wants to forbid
open(), I want to hear _why_. I assume the memfd object has uid==uid-of-creator and mode==(777 & ~umask) (which usually results in X00, so no access for non-owners). I cannot see how /proc is a security issue here.
On further reflection, my argument for 000 is crap. As far as I can see, the only time that the mode matters at all when playing with /proc/pid/fd, and they only way to get a non-O_RDWR memfd is using /proc/pid/fd, so I'll argue for 0600 instead.
Argument why 0600 is better than 0600 & ~umask: either callers don't care because the inode mode simply doesn't matter or they're using /proc/pid/fd to *reduce* permissions, in which case they'd probably like to avoid having to play with umask or call fchmod.
Argument why 0600 is better than 0777 & ~umask: People /prod/pid/fd are the only ones who care, in which case they probably prefer for the permissions not be increased by other users if they give them a reduced-permission fd.
Anyway, this is all mostly unimportant. Some text in the man page is probably sufficient, but I still think that 0600 is trivial to implement and a little bit more friendly.
--Andy
Quoted 3 lines
Thanks
David
Signature · 8 lines
Andy Lutomirski AMA Capital Management, LLC -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 24 lines · Andy Lutomirski
Quoted 15 lines · Theodore Ts'o
Quoted 5 lines · Andy Lutomirski
This is the second time in a week that someone has asked for a way to have a struct file (or struct inode or whatever) that can't be reopened through
/proc/pid/fd. This should be quite easy to implement as a separate feature.What I suggested on a different thread was to add the following new file descriptor flags, to join
FD_CLOEXEC, which would be maniuplated using theF_GETFDandF_SETFDfcntl commands:
FD_NOPROCFSdisallow being able to open the inode via /proc/<pid>/fd
FD_NOPASSFDdisallow being able to pass the fd via a unix domain socketQuoted 7 lines
FD_LOCKFLAGSif this bit is set, disallow any further changes ofFD_CLOEXEC,
FD_NOPROCFS,FD_NOPASSFD, andFD_LOCKFLAGSflags.Regardless of what else we might need to meet the use case for the proposed File Sealing API, I think this is a useful feature that could be used in many other contexts besides just the proposed
memfd_create()use case.
Quoted 4 lines
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the
/proc/self/fdissue for real -- we could just makeopen("/proc/self/fd/3", O_RDWR)fail if fd 3 is read-only. That may be enough for the file sealing thing.
Yes please.
Current behaviour is very unexpected, and unexpected behaviour in security area is normally called "security hole".
Pavel
Signature · 8 lines
(english) http://www.livejournal.com/~pavelmachek (cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Andy Lutomirski
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the
/proc/self/fdissue for real -- we could just makeopen("/proc/self/fd/3", O_RDWR)fail if fd 3 is read-only. That may be enough for the file sealing thing.
Increasing privilege on O_PATH descriptors via access through /proc/self/fd is part of the userspace API. The same thing might be true for O_RDONLY descriptors, but it's a bit less likely that there are any users out there. In any case, I'm not sure it makes sense to plug the O_RDONLY hole while leaving the O_PATH hole open.
Signature · 7 lines
Florian Weimer / Red Hat Product Security Team -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · Florian Weimer
Quoted 4 lines · Andy Lutomirski
It occurs to me that, before going nuts with these kinds of flags, it may pay to just try to fix the
/proc/self/fdissue for real -- we could just makeopen("/proc/self/fd/3", O_RDWR)fail if fd 3 is read-only. That may be enough for the file sealing thing.Increasing privilege on
O_PATHdescriptors via access through
/proc/self/fd is part of the userspace API. The same thing might be true for O_RDONLY descriptors, but it's a bit less likely that there are any users out there. In any case, I'm not sure it makes sense to plug the O_RDONLY hole while leaving the O_PATH hole open.
Do you mean O_PATH fds for the directory or O_PATH fds for the file itself? In any event, I'm much less concerned about passing O_PATH memfds around than O_RDONLY memfds.
I have incomplete patches for this stuff. I need to fix them so they work and get past Al Viro.
--Andy
Quoted 3 lines · On Thu, Mar 20, 2014 at 11:32 AM, [email protected] wrote:
Looking at your patches, and what files you are modifying, you are enforcing this in the low-level file system.
I would love for this to be implemented in the filesystem level as well. Something like the ext4 immutable bit, but with the ability to still make hardlinks would be *very* useful for OSTree. And anyone else that uses hardlinks as a data source. The vserver people do something similiar:
http://linux-vserver.org/util-vserver:Vhashify
At the moment I have a read-only bind mount over /usr, but what I really want is to make the individual objects in the object store in /ostree/repo/objects be immutable, so even if a user or app navigates out to /sysroot they still can't mutate them (or the link targets in the visible /usr).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Colin Walters
Quoted 3 lines · On Thu, Mar 20, 2014 at 11:32 AM, [email protected] wrote:
Looking at your patches, and what files you are modifying, you are enforcing this in the low-level file system.
I would love for this to be implemented in the filesystem level as well. Something like the ext4 immutable bit, but with the ability to still make hardlinks would be *very* useful for OSTree. And anyone else that uses hardlinks as a data source. The vserver people do something similiar:
http://linux-vserver.org/util-vserver:Vhashify
Quoted 5 lines
At the moment I have a read-only bind mount over /usr, but what I really want is to make the individual objects in the object store in /ostree/repo/objects be immutable, so even if a user or app navigates out to /sysroot they still can't mutate them (or the link targets in the visible /usr).
COW links can do this already, I think. Of course, you'll have to use a filesystem that supports them.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · Andy Lutomirski
COW links can do this already, I think. Of course, you'll have to use a filesystem that supports them.
COW is nice if the filesystem supports them, but my userspace code needs to be filesystem agnostic. Because of that, the design for userspace simply doesn't allow arbitrary writes.
Instead, I have to painfully audit every rpm %post/dpkg postinst type script to ensure they break hardlinks, and furthermore only allow executing scripts that are known to do so.
But I think even in a btrfs world it'd still be useful to mark files as content-immutable.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 12 lines · Colin Walters
Quoted 5 lines · Andy Lutomirski
COW links can do this already, I think. Of course, you'll have to use a
filesystem that supports them.COW is nice if the filesystem supports them, but my userspace code needs to be filesystem agnostic. Because of that, the design for userspace simply doesn't allow arbitrary writes.
Quoted 6 lines
Instead, I have to painfully audit every rpm %post/dpkg postinst type script to ensure they break hardlinks, and furthermore only allow executing scripts that are known to do so.
But I think even in a btrfs world it'd still be useful to mark files as content-immutable.
If you create each tree as a subvolume and when it's complete put it in place with btrfs subvolume snapshot -r FOO_inprogress /ostree/repo/FOO, you get exactly that.
You can even use the new(ish) btrfs out-of-band dedup functionality to deduplicate read-only snapshots safely.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 7 lines · David Herrmann
Unlike existing techniques that provide similar protection, sealing allows file-sharing without any trust-relationship. This is enforced by rejecting seal modifications if you don't own an exclusive reference to the given file. So if you own a file-descriptor, you can be sure that no-one besides you can modify the seals on the given file. This allows mapping shared files from untrusted parties without the fear of the file getting truncated or modified by an attacker.
How do you keep these promises on network and FUSE file systems? Surely there is still some trust involved for such descriptors?
What happens if you create a loop device on a sealed descriptor?
Why does memfd_create not create a file backed by a memory region in the current process? Wouldn't this be a far more generic primitive? Creating aliases of memory regions would be interesting for many things (not just libffi bypassing SELinux-enforced NX restrictions :-).
Signature · 7 lines
Florian Weimer / Red Hat Product Security Team -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 1 line · Florian Weimer
How do you keep these promises on network and FUSE file systems?
I don't. This is shmem only.
Thanks
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 4 lines · David Herrmann
Quoted 1 line · Florian Weimer
How do you keep these promises on network and FUSE file systems?
I don't. This is shmem only.
Ah. What do you recommend for recipient to recognize such descriptors?
Would they just try to seal them and reject them if this fails?
Signature · 7 lines
Florian Weimer / Red Hat Product Security Team -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi
Quoted 2 lines · Florian Weimer
Ah. What do you recommend for recipient to recognize such descriptors? Would they just try to seal them and reject them if this fails?
This highly depends on your use-case. Please see the initial email in this thread. It describes 2 example use-cases. In both cases, the recipients read the current set of seals and verify that a given set of seals is set.
Thanks
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 10 lines · David Herrmann
Hi
Quoted 2 lines · Florian Weimer
Ah. What do you recommend for recipient to recognize such descriptors? Would they just try to seal them and reject them if this fails?
This highly depends on your use-case. Please see the initial email in this thread. It describes 2 example use-cases. In both cases, the recipients read the current set of seals and verify that a given set of seals is set.
I didn't find that very convincing. But in v2, seals are monotonic, so checking them should be reliable enough.
What happens when you create a loop device on a write-sealed descriptor?
Signature · 1 line
Florian Weimer / Red Hat Product Security Team
Hi
Quoted 2 lines · Florian Weimer
I didn't find that very convincing. But in v2, seals are monotonic, so checking them should be reliable enough.
Ok.
Quoted 1 line
What happens when you create a loop device on a write-sealed descriptor?
Any write-back to the loop-device will fail with EPERM as soon as the fd gets write-sealed. See __do_lo_send_write() in drivers/block/loop.c. It's up to the loop-device to forward the error via bio_endio() to the caller for proper error-handling.
Thanks
David
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 18 lines · Florian Weimer
Quoted 4 lines · David Herrmann
Unlike existing techniques that provide similar protection, sealing allows
file-sharing without any trust-relationship. This is enforced by rejecting sealQuoted 8 lines
modifications if you don't own an exclusive reference to the given file. So if
you own a file-descriptor, you can be sure that no-one besides you can modify
the seals on the given file. This allows mapping shared files from untrusted
parties without the fear of the file getting truncated or modified by an attacker.How do you keep these promises on network and FUSE file systems? Surely there is still some trust involved for such descriptors?
Quoted 6 lines
What happens if you create a loop device on a sealed descriptor?
Why does
memfd_createnot create a file backed by a memory region in the current process? Wouldn't this be a far more generic primitive? Creating aliases of memory regions would be interesting for many things (not just libffi bypassing SELinux-enforced NX restrictions :-).
If you write a patch to prevent selinux from enforcing NX, I will ack that patch with all my might. I don't know how far it would get me, but I think that selinux has no business going anywhere near execmem.
Adding a clone mode to mremap might be a better bet. But memfd solves that problem, too, albeit messily.
--Andy
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>