qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] migration: Fix parse_ramblock() on overwritten retvals
@ 2023-10-17 20:38 Peter Xu
  2023-10-17 22:30 ` Fabiano Rosas
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Peter Xu @ 2023-10-17 20:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Juan Quintela, Fabiano Rosas, peterx

It's possible that some errors can be overwritten with success retval later
on, and then ignored.  Always capture all errors and report.

Reported by Coverity 1522861, but actually I spot one more in the same
function.

Fixes: CID 1522861
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 migration/ram.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index c844151ee9..d8bdb53a8f 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
         ret = qemu_ram_resize(block, length, &local_err);
         if (local_err) {
             error_report_err(local_err);
+            assert(ret < 0);
+            return ret;
         }
     }
     /* For postcopy we need to check hugepage sizes match */
@@ -3898,7 +3900,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
             error_report("Mismatched RAM page size %s "
                          "(local) %zd != %" PRId64, block->idstr,
                          block->page_size, remote_page_size);
-            ret = -EINVAL;
+            return -EINVAL;
         }
     }
     if (migrate_ignore_shared()) {
@@ -3908,7 +3910,7 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
             error_report("Mismatched GPAs for block %s "
                          "%" PRId64 "!= %" PRId64, block->idstr,
                          (uint64_t)addr, (uint64_t)block->mr->addr);
-            ret = -EINVAL;
+            return -EINVAL;
         }
     }
     ret = rdma_block_notification_handle(f, block->idstr);
-- 
2.41.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-17 20:38 [PATCH] migration: Fix parse_ramblock() on overwritten retvals Peter Xu
@ 2023-10-17 22:30 ` Fabiano Rosas
  2023-10-18  7:12 ` Juan Quintela
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 7+ messages in thread
From: Fabiano Rosas @ 2023-10-17 22:30 UTC (permalink / raw)
  To: Peter Xu, qemu-devel; +Cc: Juan Quintela, peterx

Peter Xu <peterx@redhat.com> writes:

> It's possible that some errors can be overwritten with success retval later
> on, and then ignored.  Always capture all errors and report.
>
> Reported by Coverity 1522861, but actually I spot one more in the same
> function.
>
> Fixes: CID 1522861
> Signed-off-by: Peter Xu <peterx@redhat.com>

Reviewed-by: Fabiano Rosas <farosas@suse.de>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-17 20:38 [PATCH] migration: Fix parse_ramblock() on overwritten retvals Peter Xu
  2023-10-17 22:30 ` Fabiano Rosas
@ 2023-10-18  7:12 ` Juan Quintela
  2023-10-18 13:16   ` Peter Xu
  2023-10-18 13:54 ` Juan Quintela
  2023-10-19 12:40 ` Peter Maydell
  3 siblings, 1 reply; 7+ messages in thread
From: Juan Quintela @ 2023-10-18  7:12 UTC (permalink / raw)
  To: Peter Xu; +Cc: qemu-devel, Fabiano Rosas

Peter Xu <peterx@redhat.com> wrote:
> It's possible that some errors can be overwritten with success retval later
> on, and then ignored.  Always capture all errors and report.
>
> Reported by Coverity 1522861, but actually I spot one more in the same
> function.
>
> Fixes: CID 1522861
> Signed-off-by: Peter Xu <peterx@redhat.com>
> ---
>  migration/ram.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index c844151ee9..d8bdb53a8f 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
>          ret = qemu_ram_resize(block, length, &local_err);
>          if (local_err) {
>              error_report_err(local_err);
> +            assert(ret < 0);
> +            return ret;

I hate that assert.  If you really want that:


         if (ret < 0) {
            error_report_err(local_err);
            assert(ret < 0);
            return ret;
         }

Rest of the patch looks ok.

Later, Juan.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-18  7:12 ` Juan Quintela
@ 2023-10-18 13:16   ` Peter Xu
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Xu @ 2023-10-18 13:16 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Fabiano Rosas

On Wed, Oct 18, 2023 at 09:12:36AM +0200, Juan Quintela wrote:
> Peter Xu <peterx@redhat.com> wrote:
> > It's possible that some errors can be overwritten with success retval later
> > on, and then ignored.  Always capture all errors and report.
> >
> > Reported by Coverity 1522861, but actually I spot one more in the same
> > function.
> >
> > Fixes: CID 1522861
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> > ---
> >  migration/ram.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/migration/ram.c b/migration/ram.c
> > index c844151ee9..d8bdb53a8f 100644
> > --- a/migration/ram.c
> > +++ b/migration/ram.c
> > @@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
> >          ret = qemu_ram_resize(block, length, &local_err);
> >          if (local_err) {
> >              error_report_err(local_err);
> > +            assert(ret < 0);
> > +            return ret;
> 
> I hate that assert.  If you really want that:

Please have a look at qemu_ram_resize().  It only contains two error paths.

> 
> 
>          if (ret < 0) {
>             error_report_err(local_err);

This will be similar to above, if qemu_ram_resize() return <0 with
err==NULL, it'll crash in error_report_err() too.. at error_get_pretty().

>             assert(ret < 0);

This is not necessary.. if in this "if" section.  So we can drop it
(instead of assert it).

>             return ret;
>          }
> 
> Rest of the patch looks ok.

I tend to prefer just merging this.. but if you strongly prefer the other
way, I can drop the assert().  But then I'll prefer "return -EINVAL" rather
than "return ret", if you're fine with it.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-17 20:38 [PATCH] migration: Fix parse_ramblock() on overwritten retvals Peter Xu
  2023-10-17 22:30 ` Fabiano Rosas
  2023-10-18  7:12 ` Juan Quintela
@ 2023-10-18 13:54 ` Juan Quintela
  2023-10-19 12:40 ` Peter Maydell
  3 siblings, 0 replies; 7+ messages in thread
From: Juan Quintela @ 2023-10-18 13:54 UTC (permalink / raw)
  To: Peter Xu; +Cc: qemu-devel, Fabiano Rosas

Peter Xu <peterx@redhat.com> wrote:
> It's possible that some errors can be overwritten with success retval later
> on, and then ignored.  Always capture all errors and report.
>
> Reported by Coverity 1522861, but actually I spot one more in the same
> function.
>
> Fixes: CID 1522861
> Signed-off-by: Peter Xu <peterx@redhat.com>


Reviewed-by: Juan Quintela <quintela@redhat.com>

queued.



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-17 20:38 [PATCH] migration: Fix parse_ramblock() on overwritten retvals Peter Xu
                   ` (2 preceding siblings ...)
  2023-10-18 13:54 ` Juan Quintela
@ 2023-10-19 12:40 ` Peter Maydell
  2023-10-19 14:50   ` Peter Xu
  3 siblings, 1 reply; 7+ messages in thread
From: Peter Maydell @ 2023-10-19 12:40 UTC (permalink / raw)
  To: Peter Xu; +Cc: qemu-devel, Juan Quintela, Fabiano Rosas

On Tue, 17 Oct 2023 at 21:40, Peter Xu <peterx@redhat.com> wrote:
>
> It's possible that some errors can be overwritten with success retval later
> on, and then ignored.  Always capture all errors and report.
>
> Reported by Coverity 1522861, but actually I spot one more in the same
> function.

The other one is CID 1522862, I think.

> Fixes: CID 1522861
> Signed-off-by: Peter Xu <peterx@redhat.com>

> ---
>  migration/ram.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index c844151ee9..d8bdb53a8f 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
>          ret = qemu_ram_resize(block, length, &local_err);
>          if (local_err) {
>              error_report_err(local_err);
> +            assert(ret < 0);

We usually don't bother asserting for this kind of "function
reports errors two ways" code.

> +            return ret;
>          }

thanks
-- PMM


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] migration: Fix parse_ramblock() on overwritten retvals
  2023-10-19 12:40 ` Peter Maydell
@ 2023-10-19 14:50   ` Peter Xu
  0 siblings, 0 replies; 7+ messages in thread
From: Peter Xu @ 2023-10-19 14:50 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel, Juan Quintela, Fabiano Rosas

On Thu, Oct 19, 2023 at 01:40:29PM +0100, Peter Maydell wrote:
> On Tue, 17 Oct 2023 at 21:40, Peter Xu <peterx@redhat.com> wrote:
> >
> > It's possible that some errors can be overwritten with success retval later
> > on, and then ignored.  Always capture all errors and report.
> >
> > Reported by Coverity 1522861, but actually I spot one more in the same
> > function.
> 
> The other one is CID 1522862, I think.

Yes..

> 
> > Fixes: CID 1522861
> > Signed-off-by: Peter Xu <peterx@redhat.com>
> 
> > ---
> >  migration/ram.c | 6 ++++--
> >  1 file changed, 4 insertions(+), 2 deletions(-)
> >
> > diff --git a/migration/ram.c b/migration/ram.c
> > index c844151ee9..d8bdb53a8f 100644
> > --- a/migration/ram.c
> > +++ b/migration/ram.c
> > @@ -3888,6 +3888,8 @@ static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
> >          ret = qemu_ram_resize(block, length, &local_err);
> >          if (local_err) {
> >              error_report_err(local_err);
> > +            assert(ret < 0);
> 
> We usually don't bother asserting for this kind of "function
> reports errors two ways" code.

Juan, please feel free to drop the assert() if it's in the queue.

After this one lands, I'll send a patch to remove qemu_ram_resize retval
and only rely on Error*.

Thanks,

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-10-19 14:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-17 20:38 [PATCH] migration: Fix parse_ramblock() on overwritten retvals Peter Xu
2023-10-17 22:30 ` Fabiano Rosas
2023-10-18  7:12 ` Juan Quintela
2023-10-18 13:16   ` Peter Xu
2023-10-18 13:54 ` Juan Quintela
2023-10-19 12:40 ` Peter Maydell
2023-10-19 14:50   ` Peter Xu

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).