* [PATCH v1] arch/x86/kernel: check the return value of insn_decode_kernel()
@ 2022-09-02 7:47 Li Zhong
2022-09-07 1:59 ` Steven Rostedt
0 siblings, 1 reply; 3+ messages in thread
From: Li Zhong @ 2022-09-02 7:47 UTC (permalink / raw)
To: linux-kernel
Cc: peterz, jpoimboe, jbaron, rostedt, ardb, tglx, mingo, bp,
dave.hansen, x86, hpa, Li Zhong
insn_decode() could fail and the insn.length could be invalid. So we
need to check the return value first.
Signed-off-by: Li Zhong <floridsleeves@gmail.com>
---
arch/x86/kernel/jump_label.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index f5b8ef02d172..3ecaf0cc71d0 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -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));
+ BUG_ON(ret < 0 || insn.length != 2 && insn.length != 5);
return insn.length;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v1] arch/x86/kernel: check the return value of insn_decode_kernel()
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
0 siblings, 1 reply; 3+ messages in thread
From: Steven Rostedt @ 2022-09-07 1:59 UTC (permalink / raw)
To: Li Zhong
Cc: linux-kernel, peterz, jpoimboe, jbaron, ardb, tglx, mingo, bp,
dave.hansen, x86, hpa
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).
> + BUG_ON(ret < 0 || insn.length != 2 && insn.length != 5);
In any case, you need parenthesis around the && condition.
-- Steve
>
> return insn.length;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v1] arch/x86/kernel: check the return value of insn_decode_kernel()
2022-09-07 1:59 ` Steven Rostedt
@ 2022-09-07 8:40 ` Li Zhong
0 siblings, 0 replies; 3+ messages in thread
From: Li Zhong @ 2022-09-07 8:40 UTC (permalink / raw)
To: Steven Rostedt
Cc: linux-kernel, peterz, jpoimboe, jbaron, ardb, tglx, mingo, bp,
dave.hansen, x86, hpa
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;
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-09-07 8:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.