Commit 19791a7c authored by Mark Rutland's avatar Mark Rutland Committed by Will Deacon

arm64: fix possible spectre-v1 in ptrace_hbp_get_event()

It's possible for userspace to control idx. Sanitize idx when using it
as an array index.

Found by smatch.
Signed-off-by: default avatarMark Rutland <mark.rutland@arm.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Will Deacon <will.deacon@arm.com>
Signed-off-by: default avatarWill Deacon <will.deacon@arm.com>
parent ad40bdaf
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <linux/sched/signal.h> #include <linux/sched/signal.h>
#include <linux/sched/task_stack.h> #include <linux/sched/task_stack.h>
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/nospec.h>
#include <linux/smp.h> #include <linux/smp.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/user.h> #include <linux/user.h>
...@@ -249,15 +250,20 @@ static struct perf_event *ptrace_hbp_get_event(unsigned int note_type, ...@@ -249,15 +250,20 @@ static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
switch (note_type) { switch (note_type) {
case NT_ARM_HW_BREAK: case NT_ARM_HW_BREAK:
if (idx < ARM_MAX_BRP) if (idx >= ARM_MAX_BRP)
goto out;
idx = array_index_nospec(idx, ARM_MAX_BRP);
bp = tsk->thread.debug.hbp_break[idx]; bp = tsk->thread.debug.hbp_break[idx];
break; break;
case NT_ARM_HW_WATCH: case NT_ARM_HW_WATCH:
if (idx < ARM_MAX_WRP) if (idx >= ARM_MAX_WRP)
goto out;
idx = array_index_nospec(idx, ARM_MAX_WRP);
bp = tsk->thread.debug.hbp_watch[idx]; bp = tsk->thread.debug.hbp_watch[idx];
break; break;
} }
out:
return bp; return bp;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment