From: Peter Maydell <peter.maydell@linaro.org>
To: Chalapathi V <chalapathi.v@linux.ibm.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
fbarrat@linux.ibm.com, npiggin@gmail.com, clg@kaod.org,
calebs@linux.ibm.com, chalapathi.v@ibm.com,
saif.abrar@linux.ibm.com, dantan@us.ibm.com,
milesg@linux.ibm.com
Subject: Re: [PATCH v1 1/2] Fixes: Coverity CID 1558827
Date: Thu, 8 Aug 2024 15:11:09 +0100 [thread overview]
Message-ID: <CAFEAcA_AXzTbgC9chFoaYU_XxFSxGA5OE+iwHJn=X23idZRd0Q@mail.gmail.com> (raw)
In-Reply-To: <20240806134829.351703-2-chalapathi.v@linux.ibm.com>
On Tue, 6 Aug 2024 at 14:50, Chalapathi V <chalapathi.v@linux.ibm.com> wrote:
The Subject email for a patch should say what it does
in terms of code changes, not just list the bug number
or coverity issue number, and it should start with the
prefix showing what part of the codebase it is changing.
You can look through other commit messages with "git log"
to see the general style.
> In this commit the following coverity scan defect has been fixed.
> CID 1558827: (OVERRUN)
> Overrunning array "s->seq_op" of 8 bytes at byte offset 16
> using index "get_seq_index(s) + 1" (which evaluates to 16).
>
> Signed-off-by: Chalapathi V <chalapathi.v@linux.ibm.com>
> ---
> hw/ssi/pnv_spi.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/hw/ssi/pnv_spi.c b/hw/ssi/pnv_spi.c
> index c1297ab733..a33f682897 100644
> --- a/hw/ssi/pnv_spi.c
> +++ b/hw/ssi/pnv_spi.c
> @@ -729,7 +729,7 @@ static void operation_sequencer(PnvSpi *s)
> * some operations may cause more than one frame to be sequenced.
> */
> while (get_seq_index(s) < NUM_SEQ_OPS) {
> - opcode = s->seq_op[get_seq_index(s)];
> + opcode = s->seq_op[(get_seq_index(s) & 0x7)];
This doesn't seem like the right fix, as Philippe points out.
It's also not any of the possible approaches I suggested
in my email in the other thread.
* if we're confident that this value really can't be more than
7, then we should assert() that
* if the value might be more than 7 if the guest has done something
silly, we should arrange to detect and handle that error
* if the hardware really ignores the high bit of the field,
that should be implemented in get_seq_index(), not in its callers
* we should consider whether using a local variable instead
of repeatedly calling get_seq_index() might make the code
easier to read (as well as helping Coverity)
> /* Set sequencer state to decode */
> s->status = SETFIELD(SPI_STS_SEQ_FSM, s->status, SEQ_STATE_DECODE);
> /*
> @@ -834,8 +834,8 @@ static void operation_sequencer(PnvSpi *s)
> * transmission to the responder without requiring a refill of
> * the TDR between the two operations.
> */
> - if (PNV_SPI_MASKED_OPCODE(s->seq_op[get_seq_index(s) + 1])
> - == SEQ_OP_SHIFT_N2) {
> + if (PNV_SPI_MASKED_OPCODE(s->seq_op[((get_seq_index(s) + 1) &
> + 0x7)]) == SEQ_OP_SHIFT_N2) {
This doesn't look right. If operation 7 is SHIFT_N1 then we
do not want to look at operation 0 (which is what
"(get_seq_index(s) + 1) & 0x7" will cause us to look at), because
operation 0 is unrelated. What we want to do is have this condition
be "if (sequence index != 7 && s->seq_op[sequence index + 1] is SHIFT_N2)".
> send_n1_alone = false;
> }
> s->status = SETFIELD(SPI_STS_SHIFTER_FSM, s->status,
thanks
-- PMM
next prev parent reply other threads:[~2024-08-08 14:12 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 13:48 [PATCH v1 0/2] hw/ppc: SPI model - coverity fixes Chalapathi V
2024-08-06 13:48 ` [PATCH v1 1/2] Fixes: Coverity CID 1558827 Chalapathi V
2024-08-06 14:10 ` Philippe Mathieu-Daudé
2024-08-08 14:11 ` Peter Maydell [this message]
2024-08-06 13:48 ` [PATCH v1 2/2] Fixes: Coverity CID 1558831 Chalapathi V
2024-08-06 14:11 ` Philippe Mathieu-Daudé
2024-08-07 20:12 ` Philippe Mathieu-Daudé
2024-08-08 14:33 ` 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='CAFEAcA_AXzTbgC9chFoaYU_XxFSxGA5OE+iwHJn=X23idZRd0Q@mail.gmail.com' \
--to=peter.maydell@linaro.org \
--cc=calebs@linux.ibm.com \
--cc=chalapathi.v@ibm.com \
--cc=chalapathi.v@linux.ibm.com \
--cc=clg@kaod.org \
--cc=dantan@us.ibm.com \
--cc=fbarrat@linux.ibm.com \
--cc=milesg@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=saif.abrar@linux.ibm.com \
/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).