Skip to content

Commit 935d44a

Browse files
robertosassuakpm00
authored andcommitted
memfd: check for non-NULL file_seals in memfd_create() syscall
Ensure that file_seals is non-NULL before using it in the memfd_create() syscall. One situation in which memfd_file_seals_ptr() could return a NULL pointer when CONFIG_SHMEM=n, oopsing the kernel. Link: https://lkml.kernel.org/r/[email protected] Fixes: 47b9012 ("shmem: add sealing support to hugetlb-backed memfd") Signed-off-by: Roberto Sassu <[email protected]> Cc: Marc-Andr Lureau <[email protected]> Cc: Mike Kravetz <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 95a301e commit 935d44a

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

mm/memfd.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,12 +371,15 @@ SYSCALL_DEFINE2(memfd_create,
371371

372372
inode->i_mode &= ~0111;
373373
file_seals = memfd_file_seals_ptr(file);
374-
*file_seals &= ~F_SEAL_SEAL;
375-
*file_seals |= F_SEAL_EXEC;
374+
if (file_seals) {
375+
*file_seals &= ~F_SEAL_SEAL;
376+
*file_seals |= F_SEAL_EXEC;
377+
}
376378
} else if (flags & MFD_ALLOW_SEALING) {
377379
/* MFD_EXEC and MFD_ALLOW_SEALING are set */
378380
file_seals = memfd_file_seals_ptr(file);
379-
*file_seals &= ~F_SEAL_SEAL;
381+
if (file_seals)
382+
*file_seals &= ~F_SEAL_SEAL;
380383
}
381384

382385
fd_install(fd, file);

0 commit comments

Comments
 (0)