Skip to content

Commit

Permalink
Revert "mm/secretmem: use refcount_t instead of atomic_t"
Browse files Browse the repository at this point in the history
This reverts commit 1108605.

Converting the "secretmem_users" counter to a refcount is incorrect,
because a refcount is special in zero and can't just be incremented (but
a count of users is not, and "no users" is actually perfectly valid and
not a sign of a free'd resource).

Reported-by: [email protected]
Cc: Jordy Zomer <[email protected]>
Cc: Kees Cook <[email protected]>,
Cc: Jordy Zomer <[email protected]>
Cc: James Bottomley <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
torvalds committed Oct 24, 2021
1 parent b20078f commit 87066fd
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions mm/secretmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <linux/secretmem.h>
#include <linux/set_memory.h>
#include <linux/sched/signal.h>
#include <linux/refcount.h>

#include <uapi/linux/magic.h>

Expand All @@ -41,11 +40,11 @@ module_param_named(enable, secretmem_enable, bool, 0400);
MODULE_PARM_DESC(secretmem_enable,
"Enable secretmem and memfd_secret(2) system call");

static refcount_t secretmem_users;
static atomic_t secretmem_users;

bool secretmem_active(void)
{
return !!refcount_read(&secretmem_users);
return !!atomic_read(&secretmem_users);
}

static vm_fault_t secretmem_fault(struct vm_fault *vmf)
Expand Down Expand Up @@ -104,7 +103,7 @@ static const struct vm_operations_struct secretmem_vm_ops = {

static int secretmem_release(struct inode *inode, struct file *file)
{
refcount_dec(&secretmem_users);
atomic_dec(&secretmem_users);
return 0;
}

Expand Down Expand Up @@ -218,7 +217,7 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)
file->f_flags |= O_LARGEFILE;

fd_install(fd, file);
refcount_inc(&secretmem_users);
atomic_inc(&secretmem_users);
return fd;

err_put_fd:
Expand Down

0 comments on commit 87066fd

Please sign in to comment.