Skip to content

Commit

Permalink
RISC-V: hwprobe: Fix vDSO SIGSEGV
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Evan Green <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Palmer Dabbelt <[email protected]>
  • Loading branch information
jones-drew authored and palmer-dabbelt committed Nov 2, 2023
1 parent 6533010 commit e1c05b3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions arch/riscv/include/asm/hwprobe.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion arch/riscv/kernel/vdso/hwprobe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e1c05b3

Please sign in to comment.