Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14d6e289 authored by Mark Rutland's avatar Mark Rutland Committed by Will Deacon
Browse files

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: 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 11527b3e
Loading
Loading
Loading
Loading
+11 −8
Original line number Original line Diff line number Diff line
@@ -277,19 +277,22 @@ static int ptrace_hbp_set_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);
		tsk->thread.debug.hbp_break[idx] = bp;
		tsk->thread.debug.hbp_break[idx] = bp;
		err = 0;
		err = 0;
		}
		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);
		tsk->thread.debug.hbp_watch[idx] = bp;
		tsk->thread.debug.hbp_watch[idx] = bp;
		err = 0;
		err = 0;
		}
		break;
		break;
	}
	}


out:
	return err;
	return err;
}
}