All of lore.kernel.org
 help / color / mirror / Atom feed
From: Li Zhong <floridsleeves@gmail.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-kernel@vger.kernel.org, peterz@infradead.org,
	jpoimboe@kernel.org, jbaron@akamai.com, ardb@kernel.org,
	tglx@linutronix.de, mingo@redhat.com, bp@alien8.de,
	dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com
Subject: Re: [PATCH v1] arch/x86/kernel: check the return value of insn_decode_kernel()
Date: Wed, 7 Sep 2022 01:40:08 -0700	[thread overview]
Message-ID: <CAMEuxRqUsKeqtNu1+cwW0a5o_qt56+O7B3EE2sBzsAc9gKhnsQ@mail.gmail.com> (raw)
In-Reply-To: <20220906215918.3fe20cca@gandalf.local.home>

On Tue, Sep 6, 2022 at 6:58 PM Steven Rostedt <rostedt@goodmis.org> wrote:
>
> On Fri,  2 Sep 2022 00:47:06 -0700
> Li Zhong <floridsleeves@gmail.com> wrote:
>
> > @@ -20,9 +20,10 @@
> >  int arch_jump_entry_size(struct jump_entry *entry)
> >  {
> >       struct insn insn = {};
> > +     int ret;
> >
> > -     insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
> > -     BUG_ON(insn.length != 2 && insn.length != 5);
> > +     ret = insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
>
> It's highly unlikely that length will be 2 or 5 if ret is not zero (as it
> is initialized to zero going into this function).
>

In this case, I think maybe just BUG_ON(ret<0) is enough. However, the code
that decides the value of insn->length could be modified in the future. And
there are other variables insn->next_byte and insn->kaddr that are related to
insn->length, which could also be modified. So I guess we can preserve all the
assertion conditions to guarantee all assumptions are satisfied.

> > +     BUG_ON(ret < 0 || insn.length != 2 && insn.length != 5);
>
> In any case, you need parenthesis around the && condition.
>

Thanks. Will add this in v2 patch.

> -- Steve
>
>
> >
> >       return insn.length;

      reply	other threads:[~2022-09-07  8:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-02  7:47 [PATCH v1] arch/x86/kernel: check the return value of insn_decode_kernel() Li Zhong
2022-09-07  1:59 ` Steven Rostedt
2022-09-07  8:40   ` Li Zhong [this message]

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=CAMEuxRqUsKeqtNu1+cwW0a5o_qt56+O7B3EE2sBzsAc9gKhnsQ@mail.gmail.com \
    --to=floridsleeves@gmail.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.