qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from l


From: Jan Kiszka
Subject: Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp
Date: Sat, 02 Jul 2011 11:43:19 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

On 2011-07-02 11:08, Blue Swirl wrote:
> On Sat, Jul 2, 2011 at 10:50 AM, Jan Kiszka <address@hidden> wrote:
>> From: Jan Kiszka <address@hidden>
>>
>> Recent compilers look deep into cpu_exec, find longjmp as a noreturn
>> function and decide to smash some stack variables as they won't be used
>> again. This may lead to env becoming invalid after return from setjmp,
>> causing crashes. Fix it by reloading env from cpu_single_env in that
>> case.
> 
> Nice. Could you try if gcc flag -Wclobbered catches something using
> your compiler without your patch:
> 
> commit f826f0d0f5cf5dd18a0d34159c1a3bc8f2e6ddf4
> Author: Blue Swirl <address@hidden>
> Date:   Sun Sep 26 11:58:38 2010 +0000
> 
>     Add gcc warning -Wclobbered
> 
>     Signed-off-by: Blue Swirl <address@hidden>
> 
> diff --git a/configure b/configure
> index 88159ac..2417205 100755
> --- a/configure
> +++ b/configure
> @@ -1038,7 +1038,7 @@ fi
>  gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
>  gcc_flags="-Wformat-security -Wformat-y2k -Winit-self
> -Wignored-qualifiers $gcc_flags"
>  gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
> -gcc_flags="-fstack-protector-all -Wendif-labels $gcc_flags"
> +gcc_flags="-fstack-protector-all -Wendif-labels -Wclobbered $gcc_flags"
>  cat > $TMPC << EOF
>  int main(void) { return 0; }
>  EOF

Neither native gcc 4.5.0 nor mingw's 4.6.0 detect this issue. However,
4.6 found this - and 3 false positives:

diff --git a/monitor.c b/monitor.c
index 67ceb46..d7edbbb 100644
--- a/monitor.c
+++ b/monitor.c
@@ -3253,6 +3253,7 @@ static const mon_cmd_t qmp_query_cmds[] = {
 /*******************************************************************/
 
 static const char *pch;
+static char *saved_key;
 static jmp_buf expr_env;
 
 #define MD_TLONG 0
@@ -4254,8 +4255,11 @@ static const mon_cmd_t *monitor_parse_command(Monitor 
*mon,
                     }
                     typestr++;
                 }
-                if (get_expr(mon, &val, &p))
+                saved_key = key;
+                if (get_expr(mon, &val, &p)) {
+                    key = saved_key;
                     goto fail;
+                }
                 /* Check if 'i' is greater than 32-bit */
                 if ((c == 'i') && ((val >> 32) & 0xffffffff)) {
                     monitor_printf(mon, "\'%s\' has failed: ", cmdname);


But the right way to deal with it is to return error codes and get rid
of this setjmp/longjmp mess for get_expr.

Jan

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]