Skip to contentSkip to conversation

RISC-V: hwprobe: Fix vDSO SIGSEGV

PATCH Applied Andrew Jones 3 participants 3 messages Oct 10, 2023 – Nov 2, 2023 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 RISC-V: hwprobe: Fix vDSO SIGSEGV

A hwprobe pair key is signed, but the hwprobe vDSO function was only checking that the upper bound was valid. In order to help avoid this type of problem in the future, and in anticipation of this check becoming more complicated with sparse keys, introduce and use a "key is valid" predicate function for the check.

Fixes aa5af0aa90ba ("RISC-V: Add hwprobe vDSO function and data")
---
 arch/riscv/include/asm/hwprobe.h | 5 +++++
 arch/riscv/kernel/vdso/hwprobe.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)
arch/riscv/include/asm/hwprobe.h +5 -0
index 78936f4ff513..7cad513538d8 100644
@@ -10,4 +10,9 @@
 
 #define RISCV_HWPROBE_MAX_KEY 5
 
+static inline bool riscv_hwprobe_key_is_valid(__s64 key)
+{
+	return key >= 0 && key <= RISCV_HWPROBE_MAX_KEY;
+}
+
 #endif
arch/riscv/kernel/vdso/hwprobe.c +1 -1
index d40bec6ac078..cadf725ef798 100644
@@ -37,7 +37,7 @@ int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
 
 	/* This is something we can handle, fill out the pairs. */
 	while (p < end) {
-		if (p->key <= RISCV_HWPROBE_MAX_KEY) {
+		if (riscv_hwprobe_key_is_valid(p->key)) {
 			p->value = avd->all_cpu_hwprobe_values[p->key];
 
 		} else {
Signature · 7 lines
2.41.0


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Andrew Jones

A hwprobe pair key is signed, but the hwprobe vDSO function was only checking that the upper bound was valid. In order to help avoid this type of problem in the future, and in anticipation of this check becoming more complicated with sparse keys, introduce and use a "key is valid" predicate function for the check.

Fixes aa5af0aa90ba ("RISC-V: Add hwprobe vDSO function and data")

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

#2 lore raw
In reply to Andrew Jones
This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Hello:

This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <[email protected]>:

Quoted 10 lines · On Tue, 10 Oct 2023 18:51:02 +0200 you wrote:

A hwprobe pair key is signed, but the hwprobe vDSO function was only checking that the upper bound was valid. In order to help avoid this type of problem in the future, and in anticipation of this check becoming more complicated with sparse keys, introduce and use a "key is valid" predicate function for the check.

Fixes aa5af0aa90ba ("RISC-V: Add hwprobe vDSO function and data")

[...]

Here is the summary with links:
- RISC-V: hwprobe: Fix vDSO SIGSEGV

    https://git.kernel.org/riscv/c/899376e85ae5

You are awesome, thank you!

Signature · 9 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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