Skip to content

Commit dc0a241

Browse files
mjeansonIngo Molnar
authored andcommitted
rseq: Fix rseq registration with CONFIG_DEBUG_RSEQ
With CONFIG_DEBUG_RSEQ=y, at rseq registration the read-only fields are copied from user-space, if this copy fails the syscall returns -EFAULT and the registration should not be activated - but it erroneously is. Move the activation of the registration after the copy of the fields to fix this bug. Fixes: 7d5265f ("rseq: Validate read-only fields under DEBUG_RSEQ config") Signed-off-by: Michael Jeanson <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Reviewed-by: Mathieu Desnoyers <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 02d954c commit dc0a241

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kernel/rseq.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,6 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
507507
return -EINVAL;
508508
if (!access_ok(rseq, rseq_len))
509509
return -EFAULT;
510-
current->rseq = rseq;
511-
current->rseq_len = rseq_len;
512-
current->rseq_sig = sig;
513510
#ifdef CONFIG_DEBUG_RSEQ
514511
/*
515512
* Initialize the in-kernel rseq fields copy for validation of
@@ -521,6 +518,14 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
521518
get_user(rseq_kernel_fields(current)->mm_cid, &rseq->mm_cid))
522519
return -EFAULT;
523520
#endif
521+
/*
522+
* Activate the registration by setting the rseq area address, length
523+
* and signature in the task struct.
524+
*/
525+
current->rseq = rseq;
526+
current->rseq_len = rseq_len;
527+
current->rseq_sig = sig;
528+
524529
/*
525530
* If rseq was previously inactive, and has just been
526531
* registered, ensure the cpu_id_start and cpu_id fields

0 commit comments

Comments
 (0)