Skip to content

Commit 87066fd

Browse files
committed
Revert "mm/secretmem: use refcount_t instead of atomic_t"
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]>
1 parent b20078f commit 87066fd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mm/secretmem.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/secretmem.h>
1919
#include <linux/set_memory.h>
2020
#include <linux/sched/signal.h>
21-
#include <linux/refcount.h>
2221

2322
#include <uapi/linux/magic.h>
2423

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

44-
static refcount_t secretmem_users;
43+
static atomic_t secretmem_users;
4544

4645
bool secretmem_active(void)
4746
{
48-
return !!refcount_read(&secretmem_users);
47+
return !!atomic_read(&secretmem_users);
4948
}
5049

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

105104
static int secretmem_release(struct inode *inode, struct file *file)
106105
{
107-
refcount_dec(&secretmem_users);
106+
atomic_dec(&secretmem_users);
108107
return 0;
109108
}
110109

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

220219
fd_install(fd, file);
221-
refcount_inc(&secretmem_users);
220+
atomic_inc(&secretmem_users);
222221
return fd;
223222

224223
err_put_fd:

0 commit comments

Comments
 (0)