RISC-V: hwprobe: Fix vDSO SIGSEGV
authorAndrew Jones <ajones@ventanamicro.com>
Tue, 10 Oct 2023 16:51:02 +0000 (18:51 +0200)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 2 Nov 2023 21:05:30 +0000 (14:05 -0700)
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")
Signed-off-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Evan Green <evan@rivosinc.com>
Link: https://lore.kernel.org/r/20231010165101.14942-2-ajones@ventanamicro.com
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/include/asm/hwprobe.h
arch/riscv/kernel/vdso/hwprobe.c

index 39df8604fea181b2f207d5a512264f975168b300..5c48f48e79a67823707806a3e7872e1ed6f3388c 100644 (file)
@@ -10,4 +10,9 @@
 
 #define RISCV_HWPROBE_MAX_KEY 6
 
+static inline bool riscv_hwprobe_key_is_valid(__s64 key)
+{
+       return key >= 0 && key <= RISCV_HWPROBE_MAX_KEY;
+}
+
 #endif
index d40bec6ac0786690374b8fde5eaddda928c788d2..cadf725ef798370bbe248f80dcf207c7fd439e7b 100644 (file)
@@ -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 {