Skip to contentSkip to conversation

arm64: signal: nofpsimd: Do not allocate fp/simd context when not available

PATCH Applied David Engraf 4 participants 6 messages Feb 25, 2022 – Mar 7, 2022 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: signal: nofpsimd: Do not allocate fp/simd context when not available

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

This may lead to an error when parse_user_sigframe() checks the fp/simd area and does not find a valid magic number.

---
 arch/arm64/kernel/signal.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/kernel/signal.c +6 -4
index d8aaf4b6f432..3d66fba69016 100644
@@ -577,10 +577,12 @@ static int setup_sigframe_layout(struct rt_sigframe_user_layout *user,
 {
 	int err;
 
-	err = sigframe_alloc(user, &user->fpsimd_offset,
-			     sizeof(struct fpsimd_context));
-	if (err)
-		return err;
+	if (system_supports_fpsimd()) {
+		err = sigframe_alloc(user, &user->fpsimd_offset,
+				     sizeof(struct fpsimd_context));
+		if (err)
+			return err;
+	}
 
 	/* fault information, if valid */
 	if (add_all || current->thread.fault_code) {
Signature · 1 line
2.25.1
#1 lore raw
Quoted 9 lines · David Engraf

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

This may lead to an error when parse_user_sigframe() checks the fp/simd area and does not find a valid magic number.

How did you spot this - do you have a system that can reproduce this? It'd be good to have coverage if there's testing but there's no easily obtainable userspace that I'm aware of.

#2 lore raw
Quoted 8 lines · Mark Brown
Quoted 7 lines · David Engraf

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

Quoted 6 lines
Quoted 2 lines

This may lead to an error when parse_user_sigframe() checks the fp/simd area and does not find a valid magic number.

How did you spot this - do you have a system that can reproduce this? It'd be good to have coverage if there's testing but there's no easily obtainable userspace that I'm aware of.

I'm using a hypervisor which reports no fp/simd support. The user space was a busybox with init and shell. The shell gets a SIGSEGV because parse_user_sigframe() returns -EINVAL (bad magic).

user->sigframe in get_sigframe() uses the user stack pointer and the area was not zeroed. Thus the magic at fpsimd_offset is invalid.

Best regards
- David

#3 lore raw
In reply to David Engraf
Quoted 6 lines · David Engraf

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

maintainer Reviewed-by on v1 1/1
#4 lore raw
In reply to David Engraf
Quoted 11 lines · David Engraf

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

This may lead to an error when parse_user_sigframe() checks the fp/simd area and does not find a valid magic number.

Given that it's not a regression, I wouldn't push it at -rc7. But if Will picks it up for 5.18, I think it's worth adding:

Fixes 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames")
Cc <[email protected]> # 5.6.x

With that:

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Applied
#5 lore raw
In reply to David Engraf
Quoted 8 lines · David Engraf

Commit 6d502b6ba1b2 ("arm64: signal: nofpsimd: Handle fp/simd context for signal frames") introduced saving the fp/simd context for signal handling only when support is available. But setup_sigframe_layout() always reserves memory for fp/simd context. The additional memory is not touched because preserve_fpsimd_context() is not called and thus the magic is invalid.

[...]

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

[1/1] arm64: signal: nofpsimd: Do not allocate fp/simd context when not available

      https://git.kernel.org/arm64/c/0a32c88ddb9a

Cheers,

Signature · 5 lines
Will

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