Skip to content

Commit

Permalink
secretmem: Prevent secretmem_users from wrapping to zero
Browse files Browse the repository at this point in the history
Commit 1108605 ("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>
  • Loading branch information
Matthew Wilcox (Oracle) authored and intel-lab-lkp committed Oct 25, 2021
1 parent 2f111a6 commit dc8e700
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mm/secretmem.c
Expand Up @@ -204,6 +204,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)
Expand Down

0 comments on commit dc8e700

Please sign in to comment.