BACKPORT: mm: Add an F_SEAL_FUTURE_WRITE seal to memfd
authorJoel Fernandes <joelaf@google.com>
Wed, 19 Dec 2018 17:54:40 +0000 (09:54 -0800)
committerDanny Wood <danwood76@gmail.com>
Thu, 28 Jan 2021 09:32:01 +0000 (09:32 +0000)
commite970ac1f8806e7577bf5214400842452eda0c858
tree7dd6cf3d5aeeb90b3e488fe00ed4512e2c69cc71
parent931225a2c76bb00cdf1041318447d53c318bf55c
BACKPORT: mm: 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:
https://developer.android.com/reference/android/database/CursorWindow

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.

Verified with test program at: https://lore.kernel.org/patchwork/patch/1008117/
link: https://lore.kernel.org/patchwork/patch/1014892/
Bug: 113362644
Change-Id: If7424db3b64372932d455f0219cd9df613fec1d4
Signed-off-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Signed-off-by: Joel Fernandes <joelaf@google.com>
include/uapi/linux/fcntl.h
mm/shmem.c