qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Richard Henderson <richard.henderson@linaro.org>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Eduardo Habkost <ehabkost@redhat.com>
Subject: Re: [PATCH v2] target/i386: Use assert() to sanity-check b1 in SSE decode
Date: Fri, 3 Sep 2021 15:10:40 +0200	[thread overview]
Message-ID: <70abf140-1074-f11b-d723-0649e1690fd3@linaro.org> (raw)
In-Reply-To: <20210901141008.17203-1-peter.maydell@linaro.org>

On 9/1/21 4:10 PM, Peter Maydell wrote:
> In the SSE decode function gen_sse(), we combine a byte
> 'b' and a value 'b1' which can be [0..3], and switch on them:
>     b |= (b1 << 8);
>     switch (b) {
>     ...
>     default:
>     unknown_op:
>         gen_unknown_opcode(env, s);
>         return;
>     }
> 
> In three cases inside this switch, we were then also checking for
>   "if (b1 >= 2) { goto unknown_op; }".
> However, this can never happen, because the 'case' values in each place
> are 0x0nn or 0x1nn and the switch will have directed the b1 == (2, 3)
> cases to the default already.
> 
> This check was added in commit c045af25a52e9 in 2010; the added code
> was unnecessary then as well, and was apparently intended only to
> ensure that we never accidentally ended up indexing off the end
> of an sse_op_table with only 2 entries as a result of future bugs
> in the decode logic.
> 
> Change the checks to assert() instead, and make sure they're always
> immediately before the array access they are protecting.
> 
> Fixes: Coverity CID 1460207
> Signed-off-by: Peter Maydell<peter.maydell@linaro.org>
> ---
> v1->v2: use assert() rather than just deleting the if()s

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~


  reply	other threads:[~2021-09-03 13:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-01 14:10 [PATCH v2] target/i386: Use assert() to sanity-check b1 in SSE decode Peter Maydell
2021-09-03 13:10 ` Richard Henderson [this message]
2021-09-13 12:34 ` Peter Maydell
2021-09-27 10:03   ` Peter Maydell
2021-11-01 16:18     ` Peter Maydell
2021-11-15 14:38       ` Peter Maydell
2021-12-09 20:01         ` Peter Maydell

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=70abf140-1074-f11b-d723-0649e1690fd3@linaro.org \
    --to=richard.henderson@linaro.org \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).