Skip to contentSkip to conversation

arm64/gcs: Fix error handling in arch_set_shadow_stack_status()

PATCH Applied Breno Leitao 2 participants 2 messages Feb 2 – Feb 3 arm64

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 arm64/gcs: Fix error handling in arch_set_shadow_stack_status()

alloc_gcs() returns an error-encoded pointer on failure, which comes from do_mmap(), not NULL.

The current NULL check fails to detect errors, which could lead to using an invalid GCS address.

Use IS_ERR_VALUE() to properly detect errors, consistent with the check in gcs_alloc_thread_stack().

Fixes b57180c75c7eb ("arm64/gcs: Implement shadow stack prctl() interface")

---
Changes in v2:
- Remove unnecessary PTR_ERR() conversion (Will)
- Link to v1: https://patch.msgid.link/[email protected]

---
 arch/arm64/mm/gcs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/mm/gcs.c +2 -2
index 6e93f78de79b1..04a23a497f205 100644
@@ -199,8 +199,8 @@ int arch_set_shadow_stack_status(struct task_struct *task, unsigned long arg)
 
 		size = gcs_size(0);
 		gcs = alloc_gcs(0, size);
-		if (!gcs)
-			return -ENOMEM;
+		if (IS_ERR_VALUE(gcs))
+			return gcs;
 
 		task->thread.gcspr_el0 = gcs + size - sizeof(u64);
 		task->thread.gcs_base = gcs;

---
base-commit: 8dfce8991b95d8625d0a1d2896e42f93b9d7f68d
change-id: 20260129-arm64_cgs-496817025d1e

Best regards,

Signature · 1 line
Breno Leitao <[email protected]>
maintainer Applied
#1 lore raw
Quoted 10 lines · Breno Leitao

alloc_gcs() returns an error-encoded pointer on failure, which comes from do_mmap(), not NULL.

The current NULL check fails to detect errors, which could lead to using an invalid GCS address.

Use IS_ERR_VALUE() to properly detect errors, consistent with the check in gcs_alloc_thread_stack().

[...]

Applied to arm64 (for-next/core), thanks!

[1/1] arm64/gcs: Fix error handling in arch_set_shadow_stack_status()

      https://git.kernel.org/arm64/c/53c998527ffa

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev