Skip to content

Commit 19791a7

Browse files
mrutland-armwildea01
authored andcommitted
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: Mark Rutland <mark.rutland@arm.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Will Deacon <will.deacon@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
1 parent ad40bda commit 19791a7

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/sched/signal.h>
2626
#include <linux/sched/task_stack.h>
2727
#include <linux/mm.h>
28+
#include <linux/nospec.h>
2829
#include <linux/smp.h>
2930
#include <linux/ptrace.h>
3031
#include <linux/user.h>
@@ -249,15 +250,20 @@ static struct perf_event *ptrace_hbp_get_event(unsigned int note_type,
249250

250251
switch (note_type) {
251252
case NT_ARM_HW_BREAK:
252-
if (idx < ARM_MAX_BRP)
253-
bp = tsk->thread.debug.hbp_break[idx];
253+
if (idx >= ARM_MAX_BRP)
254+
goto out;
255+
idx = array_index_nospec(idx, ARM_MAX_BRP);
256+
bp = tsk->thread.debug.hbp_break[idx];
254257
break;
255258
case NT_ARM_HW_WATCH:
256-
if (idx < ARM_MAX_WRP)
257-
bp = tsk->thread.debug.hbp_watch[idx];
259+
if (idx >= ARM_MAX_WRP)
260+
goto out;
261+
idx = array_index_nospec(idx, ARM_MAX_WRP);
262+
bp = tsk->thread.debug.hbp_watch[idx];
258263
break;
259264
}
260265

266+
out:
261267
return bp;
262268
}
263269

0 commit comments

Comments
 (0)