path: root/mm/memfd.c
diff options
authorJoel Fernandes (Google) <>2019-03-05 15:47:54 -0800
committerLinus Torvalds <>2019-03-05 21:07:19 -0800
commitab3948f58ff841e51feb845720624665ef5b7ef3 (patch)
tree7258ed463b4e48b91add44c6ee09217ef8611679 /mm/memfd.c
parent7f18825174203526a47c127c12a50f897ee0b511 (diff)
mm/memfd: add an F_SEAL_FUTURE_WRITE seal to memfd
Android uses ashmem for sharing memory regions. We are looking forward to migrating all usecases of ashmem to memfd so that we can possibly remove the ashmem driver in the future from staging while also benefiting from using memfd and contributing to it. Note staging drivers are also not ABI and generally can be removed at anytime. One of the main usecases Android has is the ability to create a region and mmap it as writeable, then add protection against making any "future" writes while keeping the existing already mmap'ed writeable-region active. This allows us to implement a usecase where receivers of the shared memory buffer can get a read-only view, while the sender continues to write to the buffer. See CursorWindow documentation in Android for more details: This usecase cannot be implemented with the existing F_SEAL_WRITE seal. To support the usecase, this patch adds a new F_SEAL_FUTURE_WRITE seal which prevents any future mmap and write syscalls from succeeding while keeping the existing mmap active. A better way to do F_SEAL_FUTURE_WRITE seal was discussed [1] last week where we don't need to modify core VFS structures to get the same behavior of the seal. This solves several side-effects pointed by Andy. self-tests are provided in later patch to verify the expected semantics. [1] Thanks a lot to Andy for suggestions to improve code. Link: Signed-off-by: Joel Fernandes (Google) <> Acked-by: John Stultz <> Cc: Andy Lutomirski <> Cc: Minchan Kim <> Cc: Jann Horn <> Cc: Al Viro <> Cc: Andy Lutomirski <> Cc: Hugh Dickins <> Cc: J. Bruce Fields <> Cc: Jeff Layton <> Cc: Marc-Andr Lureau <> Cc: Matthew Wilcox <> Cc: Mike Kravetz <> Cc: Shuah Khan <> Signed-off-by: Andrew Morton <> Signed-off-by: Linus Torvalds <>
Diffstat (limited to 'mm/memfd.c')
1 files changed, 2 insertions, 1 deletions
diff --git a/mm/memfd.c b/mm/memfd.c
index 97264c79d2cd..650e65a46b9c 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -131,7 +131,8 @@ static unsigned int *memfd_file_seals_ptr(struct file *file)
#define F_ALL_SEALS (F_SEAL_SEAL | \
static int memfd_add_seals(struct file *file, unsigned int seals)