mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
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/20230607132427.2867435-1-roberto.sassu@huaweicloud.com
Fixes: 47b9012ecd
("shmem: add sealing support to hugetlb-backed memfd")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
Cc: Marc-Andr Lureau <marcandre.lureau@redhat.com>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
committed by
Andrew Morton
parent
95a301eefa
commit
935d44acf6
@@ -371,12 +371,15 @@ SYSCALL_DEFINE2(memfd_create,
|
|||||||
|
|
||||||
inode->i_mode &= ~0111;
|
inode->i_mode &= ~0111;
|
||||||
file_seals = memfd_file_seals_ptr(file);
|
file_seals = memfd_file_seals_ptr(file);
|
||||||
*file_seals &= ~F_SEAL_SEAL;
|
if (file_seals) {
|
||||||
*file_seals |= F_SEAL_EXEC;
|
*file_seals &= ~F_SEAL_SEAL;
|
||||||
|
*file_seals |= F_SEAL_EXEC;
|
||||||
|
}
|
||||||
} else if (flags & MFD_ALLOW_SEALING) {
|
} else if (flags & MFD_ALLOW_SEALING) {
|
||||||
/* MFD_EXEC and MFD_ALLOW_SEALING are set */
|
/* MFD_EXEC and MFD_ALLOW_SEALING are set */
|
||||||
file_seals = memfd_file_seals_ptr(file);
|
file_seals = memfd_file_seals_ptr(file);
|
||||||
*file_seals &= ~F_SEAL_SEAL;
|
if (file_seals)
|
||||||
|
*file_seals &= ~F_SEAL_SEAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd_install(fd, file);
|
fd_install(fd, file);
|
||||||
|
Reference in New Issue
Block a user