re: LoongArch: Add hardware breakpoints/watchpoints support

From: Colin King (gmail)
Date: Thu Jun 08 2023 - 03:48:05 EST


Hi,

Static analysis with cppcheck has found an issue in arch/loongarch/kernel/hw_breakpoint.c function hw_breakpoint_arch_parse with the following commit:

commit edffa33c7bb5a73e90c754c7a497162b77d7c55f
Author: Qing Zhang <zhangqing@xxxxxxxxxxx>
Date: Sat Feb 25 15:52:57 2023 +0800

LoongArch: Add hardware breakpoints/watchpoints support


/*
* Validate the arch-specific HW Breakpoint register settings.
*/
int hw_breakpoint_arch_parse(struct perf_event *bp,
const struct perf_event_attr *attr,
struct arch_hw_breakpoint *hw)
{
int ret;
u64 alignment_mask, offset;

^^ alignment mask is not initialized

/* Build the arch_hw_breakpoint. */
ret = arch_build_bp_info(bp, attr, hw);
if (ret)
return ret;

if (hw->ctrl.type != LOONGARCH_BREAKPOINT_EXECUTE)
alignment_mask = 0x7;
^^ only on this if path is alignment_mask being assigned

offset = hw->address & alignment_mask;
hw->address &= ~alignment_mask;

^^ offset and hw->address being modified by potentially uninitialized alignment_mask

hw->ctrl.len <<= offset;

return 0;
}


Regards,

Colin