Skip to contentSkip to conversation

target/s390x/translate: Do not leak stack address in translate_one()

PATCH Applied Thomas Huth 3 participants 3 messages Jan 23, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/s390x/translate: Do not leak stack address in translate_one()

The code in translate_one() leaks a stack address via "s->field" parameter:

static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)

 {
     DisasJumpType ret = DISAS_NEXT;
     DisasFields f;
     [...]
     s->fields = &f;
     [...]
     return ret;

}

It's currently harmless since the caller does not seem to use "fields" anymore, but let's better play safe (and please static code analyzers) by setting the fields back to NULL before returning.

---
 target/s390x/translate.c | 2 ++
 1 file changed, 2 insertions(+)
target/s390x/translate.c +2 -0
index 4292bb0dd0..9122fb36da 100644
@@ -6435,6 +6435,8 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)
     }
 #endif
 
+    s->fields = NULL;
+
     /* Advance to the next instruction.  */
     s->base.pc_next = s->pc_tmp;
     return ret;
Signature · 1 line
2.18.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 16 lines

Am 23.01.2020 um 08:05 schrieb Thomas Huth <[email protected]>:

The code in translate_one() leaks a stack address via "s->field" parameter:

static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)

{
    DisasJumpType ret = DISAS_NEXT;
    DisasFields f;
    [...]
    s->fields = &f;
    [...]
    return ret;
}
Quoted 6 lines

It's currently harmless since the caller does not seem to use "fields" anymore, but let's better play safe (and please static code analyzers) by setting the fields back to NULL before returning.

Quoted 20 lines

---
target/s390x/translate.c | 2 ++

1 file changed, 2 insertions(+)
target/s390x/translate.c +2 -0
index 4292bb0dd0..9122fb36da 100644
@@ -6435,6 +6435,8 @@ static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)
    }
 #endif
 
+    s->fields = NULL;
+
    /* Advance to the next instruction.  */
    s->base.pc_next = s->pc_tmp;
    return ret;
Signature · 1 line
2.18.1
#2 lore raw
In reply to Thomas Huth
Quoted 16 lines · On Thu, 23 Jan 2020 08:05:33 +0100 Thomas Huth <[email protected]> wrote:

The code in translate_one() leaks a stack address via "s->field" parameter:

static DisasJumpType translate_one(CPUS390XState *env, DisasContext *s)

 {
     DisasJumpType ret = DISAS_NEXT;
     DisasFields f;
     [...]
     s->fields = &f;
     [...]
     return ret;

}

It's currently harmless since the caller does not seem to use "fields" anymore, but let's better play safe (and please static code analyzers) by setting the fields back to NULL before returning.

Quoted 5 lines
---
 target/s390x/translate.c | 2 ++
 1 file changed, 2 insertions(+)

Thanks, applied.