The patch titled Subject: selftests/memfd: add tests for F_SEAL_FUTURE_WRITE seal has been added to the -mm tree. Its filename is selftests-memfd-add-tests-for-f_seal_future_write-seal.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/selftests-memfd-add-tests-for-f_seal_future_write-seal.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/selftests-memfd-add-tests-for-f_seal_future_write-seal.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: "Joel Fernandes (Google)" <joel@xxxxxxxxxxxxxxxxx> Subject: selftests/memfd: add tests for F_SEAL_FUTURE_WRITE seal Add tests to verify sealing memfds with the F_SEAL_FUTURE_WRITE works as expected. Link: http://lkml.kernel.org/r/20181108041537.39694-2-joel@xxxxxxxxxxxxxxxxx Reviewed-by: John Stultz <john.stultz@xxxxxxxxxx> Signed-off-by: Joel Fernandes (Google) <joel@xxxxxxxxxxxxxxxxx> Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx> Cc: Christoph Hellwig <hch@xxxxxxxxxxxxx> Cc: Daniel Colascione <dancol@xxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: J. Bruce Fields <bfields@xxxxxxxxxxxx> Cc: Jeff Layton <jlayton@xxxxxxxxxx> Cc: John Reck <jreck@xxxxxxxxxx> Cc: Khalid Aziz <khalid.aziz@xxxxxxxxxx> Cc: Lei Yang <Lei.Yang@xxxxxxxxxxxxx> Cc: Marc-Andr Lureau <marcandre.lureau@xxxxxxxxxx> Cc: Mike Kravetz <mike.kravetz@xxxxxxxxxx> Cc: Minchan Kim <minchan@xxxxxxxxxx> Cc: Shuah Khan <shuah@xxxxxxxxxx> Cc: Todd Kjos <tkjos@xxxxxxxxxx> Cc: Valdis Kletnieks <valdis.kletnieks@xxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- tools/testing/selftests/memfd/memfd_test.c | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) --- a/tools/testing/selftests/memfd/memfd_test.c~selftests-memfd-add-tests-for-f_seal_future_write-seal +++ a/tools/testing/selftests/memfd/memfd_test.c @@ -693,6 +693,79 @@ static void test_seal_write(void) } /* + * Test SEAL_FUTURE_WRITE + * Test whether SEAL_FUTURE_WRITE actually prevents modifications. + */ +static void test_seal_future_write(void) +{ + int fd; + void *p; + + printf("%s SEAL-FUTURE-WRITE\n", memfd_str); + + fd = mfd_assert_new("kern_memfd_seal_future_write", + mfd_def_size, + MFD_CLOEXEC | MFD_ALLOW_SEALING); + + p = mfd_assert_mmap_shared(fd); + + mfd_assert_has_seals(fd, 0); + /* Not adding grow/shrink seals makes the future write + * seal fail to get added + */ + mfd_fail_add_seals(fd, F_SEAL_FUTURE_WRITE); + + mfd_assert_add_seals(fd, F_SEAL_GROW); + mfd_assert_has_seals(fd, F_SEAL_GROW); + + /* Should still fail since shrink seal has + * not yet been added + */ + mfd_fail_add_seals(fd, F_SEAL_FUTURE_WRITE); + + mfd_assert_add_seals(fd, F_SEAL_SHRINK); + mfd_assert_has_seals(fd, F_SEAL_GROW | + F_SEAL_SHRINK); + + /* Now should succeed, also verifies that the seal + * could be added with an existing writable mmap + */ + mfd_assert_add_seals(fd, F_SEAL_FUTURE_WRITE); + mfd_assert_has_seals(fd, F_SEAL_SHRINK | + F_SEAL_GROW | + F_SEAL_FUTURE_WRITE); + + /* read should pass, writes should fail */ + mfd_assert_read(fd); + mfd_fail_write(fd); + + munmap(p, mfd_def_size); + close(fd); + + /* Test adding all seals (grow, shrink, future write) at once */ + fd = mfd_assert_new("kern_memfd_seal_future_write2", + mfd_def_size, + MFD_CLOEXEC | MFD_ALLOW_SEALING); + + p = mfd_assert_mmap_shared(fd); + + mfd_assert_has_seals(fd, 0); + mfd_assert_add_seals(fd, F_SEAL_SHRINK | + F_SEAL_GROW | + F_SEAL_FUTURE_WRITE); + mfd_assert_has_seals(fd, F_SEAL_SHRINK | + F_SEAL_GROW | + F_SEAL_FUTURE_WRITE); + + /* read should pass, writes should fail */ + mfd_assert_read(fd); + mfd_fail_write(fd); + + munmap(p, mfd_def_size); + close(fd); +} + +/* * Test SEAL_SHRINK * Test whether SEAL_SHRINK actually prevents shrinking */ @@ -945,6 +1018,7 @@ int main(int argc, char **argv) test_basic(); test_seal_write(); + test_seal_future_write(); test_seal_shrink(); test_seal_grow(); test_seal_resize(); _ Patches currently in -mm which might be from joel@xxxxxxxxxxxxxxxxx are mm-treewide-remove-unused-address-argument-from-pte_alloc-functions-v2.patch mm-speed-up-mremap-by-20x-on-large-regions-v5.patch mm-speed-up-mremap-by-20x-on-large-regions-v5-fix.patch mm-select-have_move_pmd-in-x86-for-faster-mremap.patch mm-add-an-f_seal_future_write-seal-to-memfd.patch selftests-memfd-add-tests-for-f_seal_future_write-seal.patch