mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] memfd: Check for non-NULL file_seals in memfd_create() syscall
@ 2023-06-07 13:24 Roberto Sassu
  2023-06-07 17:21 ` Andrew Morton
  0 siblings, 1 reply; 4+ messages in thread
From: Roberto Sassu @ 2023-06-07 13:24 UTC (permalink / raw)
  To: akpm; +Cc: linux-kernel, Roberto Sassu, stable

From: Roberto Sassu <roberto.sassu@huawei.com>

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 is when CONFIG_SHMEM=n.

Cc: stable@vger.kernel.org # 4.16.x
Fixes: 47b9012ecdc7 ("shmem: add sealing support to hugetlb-backed memfd")
Signed-off-by: Roberto Sassu <roberto.sassu@huawei.com>
---
 mm/memfd.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/mm/memfd.c b/mm/memfd.c
index 69b90c31d38..e763e76f110 100644
--- a/mm/memfd.c
+++ b/mm/memfd.c
@@ -371,12 +371,15 @@ SYSCALL_DEFINE2(memfd_create,
 
 		inode->i_mode &= ~0111;
 		file_seals = memfd_file_seals_ptr(file);
-		*file_seals &= ~F_SEAL_SEAL;
-		*file_seals |= F_SEAL_EXEC;
+		if (file_seals) {
+			*file_seals &= ~F_SEAL_SEAL;
+			*file_seals |= F_SEAL_EXEC;
+		}
 	} else if (flags & MFD_ALLOW_SEALING) {
 		/* MFD_EXEC and MFD_ALLOW_SEALING are set */
 		file_seals = memfd_file_seals_ptr(file);
-		*file_seals &= ~F_SEAL_SEAL;
+		if (file_seals)
+			*file_seals &= ~F_SEAL_SEAL;
 	}
 
 	fd_install(fd, file);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-06-08 21:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-07 13:24 [PATCH] memfd: Check for non-NULL file_seals in memfd_create() syscall Roberto Sassu
2023-06-07 17:21 ` Andrew Morton
2023-06-08 21:05   ` Roberto Sassu
2023-06-08 21:29     ` Roberto Sassu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®