All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] secretmem: Prevent secretmem_users from wrapping to zero
@ 2021-10-25 18:16 Matthew Wilcox (Oracle)
  2021-10-25 19:29 ` Kees Cook
  2021-10-31  1:42 ` kernel test robot
  0 siblings, 2 replies; 12+ messages in thread
From: Matthew Wilcox (Oracle) @ 2021-10-25 18:16 UTC (permalink / raw)
  To: Linus Torvalds, linux-kernel, linux-mm
  Cc: Matthew Wilcox (Oracle),
	Jordy Zomer, Kees Cook, James Bottomley, Mike Rapoport,
	Andrew Morton

Commit 110860541f44 ("mm/secretmem: use refcount_t instead of atomic_t")
attempted to fix the problem of secretmem_users wrapping to zero and
allowing suspend once again.  Prevent secretmem_users from wrapping to
zero by forbidding new users if the number of users has wrapped from
positive to negative.  This stops a long way short of reaching the
necessary 4 billion users, so there's no need to be clever with special
anti-wrap types or checking the return value from atomic_inc().

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Jordy Zomer <jordy@pwning.systems>
Cc: Kees Cook <keescook@chromium.org>,
Cc: James Bottomley <James.Bottomley@HansenPartnership.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 mm/secretmem.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/mm/secretmem.c b/mm/secretmem.c
index 030f02ddc7c1..c2dda408bb36 100644
--- a/mm/secretmem.c
+++ b/mm/secretmem.c
@@ -203,6 +203,8 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)
 
 	if (flags & ~(SECRETMEM_FLAGS_MASK | O_CLOEXEC))
 		return -EINVAL;
+	if (atomic_read(&secretmem_users) < 0)
+		return -ENFILE;
 
 	fd = get_unused_fd_flags(flags & O_CLOEXEC);
 	if (fd < 0)
-- 
2.33.0


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

end of thread, other threads:[~2021-10-31  1:42 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25 18:16 [PATCH] secretmem: Prevent secretmem_users from wrapping to zero Matthew Wilcox (Oracle)
2021-10-25 19:29 ` Kees Cook
2021-10-25 19:51   ` Matthew Wilcox
2021-10-25 21:04     ` Kees Cook
2021-10-25 21:17       ` Linus Torvalds
2021-10-25 22:30         ` Kees Cook
2021-10-25 23:37           ` Linus Torvalds
2021-10-26  0:02             ` Linus Torvalds
2021-10-26  0:17             ` Kees Cook
2021-10-26  1:10               ` Linus Torvalds
2021-10-26  1:34             ` Matthew Wilcox
2021-10-31  1:42 ` kernel test robot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.