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)
committerJoel Fernandes <joelaf@google.com>
Wed, 19 Dec 2018 18:28:04 +0000 (10:28 -0800)
commit2eaa69bd84cf14406f10514b70cb034d4d011ba6
treeb00138b5bbec55a18e1765dc1cdca0e71b77f565
parent3c9f3e0b62ad4ceca4da628708597f4cb0afe54a
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
tools/include/uapi/linux/fcntl.h