Skip to content

Commit 14d6e28

Browse files
mrutland-armwildea01
authored andcommitted
arm64: fix possible spectre-v1 write in ptrace_hbp_set_event()
It's possible for userspace to control idx. Sanitize idx when using it as an array index, to inhibit the potential spectre-v1 write gadget. 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 11527b3 commit 14d6e28

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

arch/arm64/kernel/ptrace.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,19 +277,22 @@ static int ptrace_hbp_set_event(unsigned int note_type,
277277

278278
switch (note_type) {
279279
case NT_ARM_HW_BREAK:
280-
if (idx < ARM_MAX_BRP) {
281-
tsk->thread.debug.hbp_break[idx] = bp;
282-
err = 0;
283-
}
280+
if (idx >= ARM_MAX_BRP)
281+
goto out;
282+
idx = array_index_nospec(idx, ARM_MAX_BRP);
283+
tsk->thread.debug.hbp_break[idx] = bp;
284+
err = 0;
284285
break;
285286
case NT_ARM_HW_WATCH:
286-
if (idx < ARM_MAX_WRP) {
287-
tsk->thread.debug.hbp_watch[idx] = bp;
288-
err = 0;
289-
}
287+
if (idx >= ARM_MAX_WRP)
288+
goto out;
289+
idx = array_index_nospec(idx, ARM_MAX_WRP);
290+
tsk->thread.debug.hbp_watch[idx] = bp;
291+
err = 0;
290292
break;
291293
}
292294

295+
out:
293296
return err;
294297
}
295298

0 commit comments

Comments
 (0)