Skip to content

Commit e1c05b3

Browse files
jones-drewpalmer-dabbelt
authored andcommitted
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: aa5af0a ("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>
1 parent 6533010 commit e1c05b3

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

arch/riscv/include/asm/hwprobe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,9 @@
1010

1111
#define RISCV_HWPROBE_MAX_KEY 6
1212

13+
static inline bool riscv_hwprobe_key_is_valid(__s64 key)
14+
{
15+
return key >= 0 && key <= RISCV_HWPROBE_MAX_KEY;
16+
}
17+
1318
#endif

arch/riscv/kernel/vdso/hwprobe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ int __vdso_riscv_hwprobe(struct riscv_hwprobe *pairs, size_t pair_count,
3737

3838
/* This is something we can handle, fill out the pairs. */
3939
while (p < end) {
40-
if (p->key <= RISCV_HWPROBE_MAX_KEY) {
40+
if (riscv_hwprobe_key_is_valid(p->key)) {
4141
p->value = avd->all_cpu_hwprobe_values[p->key];
4242

4343
} else {

0 commit comments

Comments
 (0)