[Qemu-devel] [PATCH for-4.0] target/i386: Generate #UD for LOCK on a register increment

Peter Maydell posted 1 patch 5 years ago
Test docker-mingw@fedora passed
Test docker-clang@ubuntu passed
Test checkpatch passed
Test asan passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20190328104750.25046-1-peter.maydell@linaro.org
Maintainers: Paolo Bonzini <pbonzini@redhat.com>, Richard Henderson <rth@twiddle.net>, Eduardo Habkost <ehabkost@redhat.com>
target/i386/translate.c | 5 +++++
1 file changed, 5 insertions(+)
[Qemu-devel] [PATCH for-4.0] target/i386: Generate #UD for LOCK on a register increment
Posted by Peter Maydell 5 years ago
Fix a TCG crash due to attempting an atomic increment
operation without having set up the address first.
This is a similar case to that dealt with in commit
e84fcd7f662a0d8198703, and we fix it in the same way.

Fixes: https://bugs.launchpad.net/qemu/+bug/1807675
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 target/i386/translate.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/target/i386/translate.c b/target/i386/translate.c
index 49cd298374b..b725bec37cd 100644
--- a/target/i386/translate.c
+++ b/target/i386/translate.c
@@ -1398,6 +1398,11 @@ static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d)
 static void gen_inc(DisasContext *s1, TCGMemOp ot, int d, int c)
 {
     if (s1->prefix & PREFIX_LOCK) {
+        if (d != OR_TMP0) {
+            /* Lock prefix when destination is not memory */
+            gen_illegal_opcode(s1);
+            return;
+        }
         tcg_gen_movi_tl(s1->T0, c > 0 ? 1 : -1);
         tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0,
                                     s1->mem_index, ot | MO_LE);
-- 
2.20.1


Re: [Qemu-devel] [PATCH for-4.0] target/i386: Generate #UD for LOCK on a register increment
Posted by Paolo Bonzini 5 years ago
On 28/03/19 11:47, Peter Maydell wrote:
> Fix a TCG crash due to attempting an atomic increment
> operation without having set up the address first.
> This is a similar case to that dealt with in commit
> e84fcd7f662a0d8198703, and we fix it in the same way.
> 
> Fixes: https://bugs.launchpad.net/qemu/+bug/1807675
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
>  target/i386/translate.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/target/i386/translate.c b/target/i386/translate.c
> index 49cd298374b..b725bec37cd 100644
> --- a/target/i386/translate.c
> +++ b/target/i386/translate.c
> @@ -1398,6 +1398,11 @@ static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d)
>  static void gen_inc(DisasContext *s1, TCGMemOp ot, int d, int c)
>  {
>      if (s1->prefix & PREFIX_LOCK) {
> +        if (d != OR_TMP0) {
> +            /* Lock prefix when destination is not memory */
> +            gen_illegal_opcode(s1);
> +            return;
> +        }
>          tcg_gen_movi_tl(s1->T0, c > 0 ? 1 : -1);
>          tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0,
>                                      s1->mem_index, ot | MO_LE);
> 

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Feel free to apply it yourself.

Paolo

Re: [Qemu-devel] [PATCH for-4.0] target/i386: Generate #UD for LOCK on a register increment
Posted by Peter Maydell 5 years ago
On Thu, 28 Mar 2019 at 11:14, Paolo Bonzini <pbonzini@redhat.com> wrote:
>
> On 28/03/19 11:47, Peter Maydell wrote:
> > Fix a TCG crash due to attempting an atomic increment
> > operation without having set up the address first.
> > This is a similar case to that dealt with in commit
> > e84fcd7f662a0d8198703, and we fix it in the same way.
> >
> > Fixes: https://bugs.launchpad.net/qemu/+bug/1807675
> > Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> > ---
> >  target/i386/translate.c | 5 +++++
> >  1 file changed, 5 insertions(+)
> >
> > diff --git a/target/i386/translate.c b/target/i386/translate.c
> > index 49cd298374b..b725bec37cd 100644
> > --- a/target/i386/translate.c
> > +++ b/target/i386/translate.c
> > @@ -1398,6 +1398,11 @@ static void gen_op(DisasContext *s1, int op, TCGMemOp ot, int d)
> >  static void gen_inc(DisasContext *s1, TCGMemOp ot, int d, int c)
> >  {
> >      if (s1->prefix & PREFIX_LOCK) {
> > +        if (d != OR_TMP0) {
> > +            /* Lock prefix when destination is not memory */
> > +            gen_illegal_opcode(s1);
> > +            return;
> > +        }
> >          tcg_gen_movi_tl(s1->T0, c > 0 ? 1 : -1);
> >          tcg_gen_atomic_add_fetch_tl(s1->T0, s1->A0, s1->T0,
> >                                      s1->mem_index, ot | MO_LE);
> >
>
> Acked-by: Paolo Bonzini <pbonzini@redhat.com>
>
> Feel free to apply it yourself.

Applied to master, thanks.

-- PMM