Skip to content

Commit cb68543

Browse files
Matthew Wilcox (Oracle)torvalds
authored andcommitted
secretmem: Prevent secretmem_users from wrapping to zero
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. But it was reverted in commit 87066fd ("Revert 'mm/secretmem: use refcount_t instead of atomic_t'") because of the problems it caused - a refcount_t was not semantically the right type to use. Instead 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 where it wraps to zero again, 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) <[email protected]> Cc: Jordy Zomer <[email protected]> Cc: Kees Cook <[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 ac8a6eb commit cb68543

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

mm/secretmem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ SYSCALL_DEFINE1(memfd_secret, unsigned int, flags)
203203

204204
if (flags & ~(SECRETMEM_FLAGS_MASK | O_CLOEXEC))
205205
return -EINVAL;
206+
if (atomic_read(&secretmem_users) < 0)
207+
return -ENFILE;
206208

207209
fd = get_unused_fd_flags(flags & O_CLOEXEC);
208210
if (fd < 0)

0 commit comments

Comments
 (0)