Skip to contentSkip to conversation

rseq: Fix rseq registration with CONFIG_DEBUG_RSEQ

PATCH Applied Michael Jeanson 2 participants 2 messages Feb 19, 2025 – Feb 21, 2025 Restartable sequences support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rseq: Fix rseq registration with CONFIG_DEBUG_RSEQ

With CONFIG_DEBUG_RSEQ at 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.

Move the activation of the registration after the copy of the fields to ensure this.

Fixes 7d5265ffcd8b ("rseq: Validate read-only fields under DEBUG_RSEQ config")
---
 kernel/rseq.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/rseq.c +8 -3
index 442aba29bc4c..2cb16091ec0a 100644
@@ -507,9 +507,6 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
 		return -EINVAL;
 	if (!access_ok(rseq, rseq_len))
 		return -EFAULT;
-	current->rseq = rseq;
-	current->rseq_len = rseq_len;
-	current->rseq_sig = sig;
 #ifdef CONFIG_DEBUG_RSEQ
 	/*
 	 * Initialize the in-kernel rseq fields copy for validation of
@@ -521,6 +518,14 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
 	    get_user(rseq_kernel_fields(current)->mm_cid, &rseq->mm_cid))
 		return -EFAULT;
 #endif
+	/*
+	 * Activate the registration by setting the rseq area address, length
+	 * and signature in the task struct.
+	 */
+	current->rseq = rseq;
+	current->rseq_len = rseq_len;
+	current->rseq_sig = sig;
+
 	/*
 	 * If rseq was previously inactive, and has just been
 	 * registered, ensure the cpu_id_start and cpu_id fields
Signature · 1 line
2.43.0
#1 lore raw
The following commit has been merged into the sched/urgent branch of tip:

The following commit has been merged into the sched/urgent branch of tip:

Commit-ID:     dc0a241ceaf3b7df6f1a7658b020c92682b75bfc
Gitweb:        https://git.kernel.org/tip/dc0a241ceaf3b7df6f1a7658b020c92682b75bfc
Author:        Michael Jeanson <[email protected]>
AuthorDate:    Wed, 19 Feb 2025 15:53:26 -05:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 21 Feb 2025 14:21:02 +01:00

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 7d5265ffcd8b ("rseq: Validate read-only fields under DEBUG_RSEQ config")
---
 kernel/rseq.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
kernel/rseq.c +8 -3
index 442aba2..2cb1609 100644
@@ -507,9 +507,6 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
 		return -EINVAL;
 	if (!access_ok(rseq, rseq_len))
 		return -EFAULT;
-	current->rseq = rseq;
-	current->rseq_len = rseq_len;
-	current->rseq_sig = sig;
 #ifdef CONFIG_DEBUG_RSEQ
 	/*
 	 * Initialize the in-kernel rseq fields copy for validation of
@@ -522,6 +519,14 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
 		return -EFAULT;
 #endif
 	/*
+	 * Activate the registration by setting the rseq area address, length
+	 * and signature in the task struct.
+	 */
+	current->rseq = rseq;
+	current->rseq_len = rseq_len;
+	current->rseq_sig = sig;
+
+	/*
 	 * If rseq was previously inactive, and has just been
 	 * registered, ensure the cpu_id_start and cpu_id fields
 	 * are updated before returning to user-space.