From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Mansour Ahmadi" <mansourweb@gmail.com>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Fabien Chouteau" <chouteau@adacore.com>,
"Max Filippov" <jcmvbkbc@gmail.com>,
"KONRAD Frederic" <frederic.konrad@adacore.com>,
qemu-arm@nongnu.org, qemu-ppc@nongnu.org,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Stafford Horne" <shorne@gmail.com>,
"Max Reitz" <mreitz@redhat.com>,
"Aurelien Jarno" <aurelien@aurel32.net>
Subject: Re: [PATCH-for-5.0 10/12] hw/block/pflash: Check return value of blk_pwrite()
Date: Wed, 15 Apr 2020 10:08:22 +0200 [thread overview]
Message-ID: <e32b3082-6e6d-8dd0-f74c-3add72a3173d@redhat.com> (raw)
In-Reply-To: <20200414133052.13712-11-philmd@redhat.com>
On 4/14/20 3:30 PM, Philippe Mathieu-Daudé wrote:
> From: Mansour Ahmadi <mansourweb@gmail.com>
>
> When updating the PFLASH file contents, we should check for a
> possible failure of blk_pwrite(). Similar to commit 3a688294e.
>
There is actually a Coverity report for this issue, CID 1357678
(Unchecked return value) from 2016-07-15 06:28:48:
CID 1357678 (#2 of 2): Unchecked return value (CHECKED_RETURN).
check_return: Calling blk_pwrite without checking return value (as is
done elsewhere 52 out of 59 times).
So it seems fair to add:
Reported-by: Coverity (CID 1357678 CHECKED_RETURN)
> Signed-off-by: Mansour Ahmadi <mansourweb@gmail.com>
> Message-Id: <20200408003552.58095-1-mansourweb@gmail.com>
> [PMD: Add missing "qemu/error-report.h" include and TODO comment]
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> ---
> hw/block/pflash_cfi01.c | 8 +++++++-
> hw/block/pflash_cfi02.c | 8 +++++++-
> 2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
> index 24f3bce7ef..be1954c5d8 100644
> --- a/hw/block/pflash_cfi01.c
> +++ b/hw/block/pflash_cfi01.c
> @@ -42,6 +42,7 @@
> #include "hw/qdev-properties.h"
> #include "sysemu/block-backend.h"
> #include "qapi/error.h"
> +#include "qemu/error-report.h"
> #include "qemu/timer.h"
> #include "qemu/bitops.h"
> #include "qemu/error-report.h"
> @@ -399,13 +400,18 @@ static void pflash_update(PFlashCFI01 *pfl, int offset,
> int size)
> {
> int offset_end;
> + int ret;
> if (pfl->blk) {
> offset_end = offset + size;
> /* widen to sector boundaries */
> offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
> offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
> - blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> + ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> offset_end - offset, 0);
> + if (ret < 0) {
> + /* TODO set error bit in status */
> + error_report("Could not update PFLASH: %s", strerror(-ret));
> + }
> }
> }
>
> diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
> index 12f18d401a..c6b6f2d082 100644
> --- a/hw/block/pflash_cfi02.c
> +++ b/hw/block/pflash_cfi02.c
> @@ -37,6 +37,7 @@
> #include "hw/block/flash.h"
> #include "hw/qdev-properties.h"
> #include "qapi/error.h"
> +#include "qemu/error-report.h"
> #include "qemu/bitmap.h"
> #include "qemu/timer.h"
> #include "sysemu/block-backend.h"
> @@ -393,13 +394,18 @@ static uint64_t pflash_read(void *opaque, hwaddr offset, unsigned int width)
> static void pflash_update(PFlashCFI02 *pfl, int offset, int size)
> {
> int offset_end;
> + int ret;
> if (pfl->blk) {
> offset_end = offset + size;
> /* widen to sector boundaries */
> offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
> offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
> - blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> + ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
> offset_end - offset, 0);
> + if (ret < 0) {
> + /* TODO set error bit in status */
> + error_report("Could not update PFLASH: %s", strerror(-ret));
> + }
> }
> }
>
>
next prev parent reply other threads:[~2020-04-15 8:09 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-14 13:30 [PATCH-for-5.0 00/12] various bugfixes Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 01/12] Revert "prevent crash when executing guest-file-read with large count" Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 02/12] qga: Extract guest_file_handle_find() to commands-common.h Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 03/12] qga: Extract qmp_guest_file_read() to common commands.c Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 04/12] qga: Restrict guest-file-read count to 48 MB to avoid crashes Philippe Mathieu-Daudé
2020-04-15 12:34 ` Daniel P. Berrangé
2020-04-15 13:02 ` Philippe Mathieu-Daudé
2020-04-15 15:23 ` Michael Roth
2020-04-14 13:30 ` [PATCH-for-5.0 05/12] vhost-user-gpu: Release memory returned by vu_queue_pop() with free() Philippe Mathieu-Daudé
2020-04-17 6:39 ` Michael S. Tsirkin
2020-04-14 13:30 ` [PATCH-for-5.0 06/12] hw/openrisc/pic_cpu: Use qdev gpio rather than qemu_allocate_irqs() Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 07/12] hw/misc/grlib_ahb_apb_pnp: Avoid crash when writing to AHB PnP registers Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 08/12] hw/misc/grlib_ahb_apb_pnp: Fix AHB PnP 8-bit accesses Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 09/12] hw/display/sm501: Avoid heap overflow in sm501_2d_operation() Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 10/12] hw/block/pflash: Check return value of blk_pwrite() Philippe Mathieu-Daudé
2020-04-14 18:34 ` Mansour Ahmadi
2020-04-15 8:08 ` Philippe Mathieu-Daudé [this message]
2020-04-14 13:30 ` [PATCH-for-5.0 11/12] gdbstub: Do not use memset() on GByteArray Philippe Mathieu-Daudé
2020-04-14 13:30 ` [PATCH-for-5.0 12/12] gdbstub: Introduce gdb_get_freg32() to get float32 registers Philippe Mathieu-Daudé
2020-04-17 6:40 ` [PATCH-for-5.0 00/12] various bugfixes Michael S. Tsirkin
2020-04-17 8:30 ` 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=e32b3082-6e6d-8dd0-f74c-3add72a3173d@redhat.com \
--to=philmd@redhat.com \
--cc=aurelien@aurel32.net \
--cc=chouteau@adacore.com \
--cc=frederic.konrad@adacore.com \
--cc=jcmvbkbc@gmail.com \
--cc=kraxel@redhat.com \
--cc=kwolf@redhat.com \
--cc=mansourweb@gmail.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=shorne@gmail.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).