public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Colin King (gmail)" <colin.i.king@gmail.com>
To: Qing Zhang <zhangqing@loongson.cn>, loongarch@lists.linux.dev
Cc: Huacai Chen <chenhuacai@kernel.org>,
	WANG Xuerui <kernel@xen0n.name>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: re: LoongArch: Add hardware breakpoints/watchpoints support
Date: Thu, 8 Jun 2023 08:47:27 +0100	[thread overview]
Message-ID: <f0265d75-d0e9-9f03-c730-dcc32fcccc69@gmail.com> (raw)

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@loongson.cn>
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




                 reply	other threads:[~2023-06-08  7:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f0265d75-d0e9-9f03-c730-dcc32fcccc69@gmail.com \
    --to=colin.i.king@gmail.com \
    --cc=chenhuacai@kernel.org \
    --cc=kernel@xen0n.name \
    --cc=linux-kernel@vger.kernel.org \
    --cc=loongarch@lists.linux.dev \
    --cc=zhangqing@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox