All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] migration: fix RAMBlock add NULL check
@ 2023-10-10 10:48 Dmitry Frolov
  2023-10-10 13:36 ` Fabiano Rosas
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Dmitry Frolov @ 2023-10-10 10:48 UTC (permalink / raw)
  To: Juan Quintela, Peter Xu, Fabiano Rosas, Leonardo Bras, qemu-devel
  Cc: sdl.qemu, Dmitry Frolov

qemu_ram_block_from_host() may return NULL, which will be dereferenced w/o
check. Usualy return value is checked for this function.
Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: c7c0e72408df5e7821c0e995122fb2fe0ac001f1 ("migration/ram: Handle RAM block resizes during precopy")
Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
---
 migration/ram.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/migration/ram.c b/migration/ram.c
index e4bfd39f08..bd4b7574e1 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4281,6 +4281,11 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host,
     RAMBlock *rb = qemu_ram_block_from_host(host, false, &offset);
     Error *err = NULL;
 
+    if (!rb) {
+        error_report("RAM block not found");
+        return;
+    }
+
     if (migrate_ram_is_ignored(rb)) {
         return;
     }
-- 
2.34.1



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-10 10:48 [PATCH v1] migration: fix RAMBlock add NULL check Dmitry Frolov
@ 2023-10-10 13:36 ` Fabiano Rosas
  2023-10-10 19:23 ` Peter Xu
  2023-10-11 13:07 ` Juan Quintela
  2 siblings, 0 replies; 8+ messages in thread
From: Fabiano Rosas @ 2023-10-10 13:36 UTC (permalink / raw)
  To: Dmitry Frolov, Juan Quintela, Peter Xu, Leonardo Bras, qemu-devel
  Cc: sdl.qemu, Dmitry Frolov

Dmitry Frolov <frolov@swemel.ru> writes:

> qemu_ram_block_from_host() may return NULL, which will be dereferenced w/o
> check. Usualy return value is checked for this function.
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: c7c0e72408df5e7821c0e995122fb2fe0ac001f1 ("migration/ram: Handle RAM block resizes during precopy")
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> ---
>  migration/ram.c | 5 +++++
>  1 file changed, 5 insertions(+)
>
> diff --git a/migration/ram.c b/migration/ram.c
> index e4bfd39f08..bd4b7574e1 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -4281,6 +4281,11 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host,
>      RAMBlock *rb = qemu_ram_block_from_host(host, false, &offset);
>      Error *err = NULL;
>  
> +    if (!rb) {
> +        error_report("RAM block not found");
> +        return;
> +    }
> +
>      if (migrate_ram_is_ignored(rb)) {
>          return;
>      }

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


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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-10 10:48 [PATCH v1] migration: fix RAMBlock add NULL check Dmitry Frolov
  2023-10-10 13:36 ` Fabiano Rosas
@ 2023-10-10 19:23 ` Peter Xu
  2023-10-11 13:20   ` Дмитрий Фролов
  2023-10-11 13:07 ` Juan Quintela
  2 siblings, 1 reply; 8+ messages in thread
From: Peter Xu @ 2023-10-10 19:23 UTC (permalink / raw)
  To: Dmitry Frolov
  Cc: Juan Quintela, Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu

On Tue, Oct 10, 2023 at 01:48:53PM +0300, Dmitry Frolov wrote:
> qemu_ram_block_from_host() may return NULL, which will be dereferenced w/o

AFAIU this path is only called from trusted sites, so I don't see why it
can be NULL?  Do you have any scenario that can trigger this?

> check. Usualy return value is checked for this function.
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Fixes: c7c0e72408df5e7821c0e995122fb2fe0ac001f1 ("migration/ram: Handle RAM block resizes during precopy")

Normally if we attach Fixes it means we want to backport it to stable.
Here I'd like to double check on above to see whether we'd need a Fixes.

> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>

The patch itself looks all fine; though if I'm going to add some print, I'd
print something more to make it at least try to be more useful (host,
old_size, new_size).  I had a feeling that we can already assert.

Thanks,

> ---
>  migration/ram.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/migration/ram.c b/migration/ram.c
> index e4bfd39f08..bd4b7574e1 100644
> --- a/migration/ram.c
> +++ b/migration/ram.c
> @@ -4281,6 +4281,11 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host,
>      RAMBlock *rb = qemu_ram_block_from_host(host, false, &offset);
>      Error *err = NULL;
>  
> +    if (!rb) {
> +        error_report("RAM block not found");
> +        return;
> +    }
> +
>      if (migrate_ram_is_ignored(rb)) {
>          return;
>      }
> -- 
> 2.34.1
> 
> 

-- 
Peter Xu



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-10 10:48 [PATCH v1] migration: fix RAMBlock add NULL check Dmitry Frolov
  2023-10-10 13:36 ` Fabiano Rosas
  2023-10-10 19:23 ` Peter Xu
@ 2023-10-11 13:07 ` Juan Quintela
  2 siblings, 0 replies; 8+ messages in thread
From: Juan Quintela @ 2023-10-11 13:07 UTC (permalink / raw)
  To: Dmitry Frolov
  Cc: Peter Xu, Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu

Dmitry Frolov <frolov@swemel.ru> wrote:
> qemu_ram_block_from_host() may return NULL, which will be dereferenced w/o
> check. Usualy return value is checked for this function.
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: c7c0e72408df5e7821c0e995122fb2fe0ac001f1 ("migration/ram: Handle RAM block resizes during precopy")
> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>

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



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-10 19:23 ` Peter Xu
@ 2023-10-11 13:20   ` Дмитрий Фролов
  2023-10-11 14:24     ` Peter Xu
  0 siblings, 1 reply; 8+ messages in thread
From: Дмитрий Фролов @ 2023-10-11 13:20 UTC (permalink / raw)
  To: Peter Xu
  Cc: Juan Quintela, Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu



On 10.10.2023 22:23, Peter Xu wrote:
> On Tue, Oct 10, 2023 at 01:48:53PM +0300, Dmitry Frolov wrote:
>> qemu_ram_block_from_host() may return NULL, which will be dereferenced w/o
> AFAIU this path is only called from trusted sites, so I don't see why it
> can be NULL?  Do you have any scenario that can trigger this?
No, actually no exact case. This was found by static analyzer.
I am also not sure, if NULL is possible here.
>
>> check. Usualy return value is checked for this function.
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: c7c0e72408df5e7821c0e995122fb2fe0ac001f1 ("migration/ram: Handle RAM block resizes during precopy")
> Normally if we attach Fixes it means we want to backport it to stable.
> Here I'd like to double check on above to see whether we'd need a Fixes.
>
>> Signed-off-by: Dmitry Frolov <frolov@swemel.ru>
> The patch itself looks all fine; though if I'm going to add some print, I'd
> print something more to make it at least try to be more useful (host,
> old_size, new_size).  I had a feeling that we can already assert.
I do not insist on accepting this patch - it is more like RFC.
Also, i can add more verbose message and assert, if necessary.
> Thanks,
>
>> ---
>>   migration/ram.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/migration/ram.c b/migration/ram.c
>> index e4bfd39f08..bd4b7574e1 100644
>> --- a/migration/ram.c
>> +++ b/migration/ram.c
>> @@ -4281,6 +4281,11 @@ static void ram_mig_ram_block_resized(RAMBlockNotifier *n, void *host,
>>       RAMBlock *rb = qemu_ram_block_from_host(host, false, &offset);
>>       Error *err = NULL;
>>   
>> +    if (!rb) {
>> +        error_report("RAM block not found");
>> +        return;
>> +    }
>> +
>>       if (migrate_ram_is_ignored(rb)) {
>>           return;
>>       }
>> -- 
>> 2.34.1
>>
>>



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-11 13:20   ` Дмитрий Фролов
@ 2023-10-11 14:24     ` Peter Xu
  2023-10-11 14:33       ` Juan Quintela
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Xu @ 2023-10-11 14:24 UTC (permalink / raw)
  To: Дмитрий
	Фролов
  Cc: Juan Quintela, Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu

On Wed, Oct 11, 2023 at 04:20:42PM +0300, Дмитрий Фролов wrote:
> I do not insist on accepting this patch - it is more like RFC.
> Also, i can add more verbose message and assert, if necessary.

That's totally fine. It's just that then we should drop the Fixes line
above because it doesn't need to be backported to stable.

Also feel free to add more verbose print message or assert if you're
posting a new version.

Thanks,

-- 
Peter Xu



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-11 14:24     ` Peter Xu
@ 2023-10-11 14:33       ` Juan Quintela
  2023-10-11 14:36         ` Дмитрий Фролов
  0 siblings, 1 reply; 8+ messages in thread
From: Juan Quintela @ 2023-10-11 14:33 UTC (permalink / raw)
  To: Peter Xu
  Cc: Дмитрий
	Фролов,
	Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu

Peter Xu <peterx@redhat.com> wrote:
> On Wed, Oct 11, 2023 at 04:20:42PM +0300, Дмитрий Фролов wrote:
>> I do not insist on accepting this patch - it is more like RFC.
>> Also, i can add more verbose message and assert, if necessary.
>
> That's totally fine. It's just that then we should drop the Fixes line
> above because it doesn't need to be backported to stable.
>
> Also feel free to add more verbose print message or assert if you're
> posting a new version.

I queued it as it is.

I can drop the Fixes if required.

Later, Juan.



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

* Re: [PATCH v1] migration: fix RAMBlock add NULL check
  2023-10-11 14:33       ` Juan Quintela
@ 2023-10-11 14:36         ` Дмитрий Фролов
  0 siblings, 0 replies; 8+ messages in thread
From: Дмитрий Фролов @ 2023-10-11 14:36 UTC (permalink / raw)
  To: quintela, Peter Xu; +Cc: Fabiano Rosas, Leonardo Bras, qemu-devel, sdl.qemu

On 11.10.2023 17:33, Juan Quintela wrote:
> Peter Xu <peterx@redhat.com> wrote:
>> On Wed, Oct 11, 2023 at 04:20:42PM +0300, Дмитрий Фролов wrote:
>>> I do not insist on accepting this patch - it is more like RFC.
>>> Also, i can add more verbose message and assert, if necessary.
>> That's totally fine. It's just that then we should drop the Fixes line
>> above because it doesn't need to be backported to stable.
>>
>> Also feel free to add more verbose print message or assert if you're
>> posting a new version.
> I queued it as it is.
Many thanks!
>
> I can drop the Fixes if required.
Would be nice. Thanks a lot!
> Later, Juan.
>
Regards, Dmitry.


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

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

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-10 10:48 [PATCH v1] migration: fix RAMBlock add NULL check Dmitry Frolov
2023-10-10 13:36 ` Fabiano Rosas
2023-10-10 19:23 ` Peter Xu
2023-10-11 13:20   ` Дмитрий Фролов
2023-10-11 14:24     ` Peter Xu
2023-10-11 14:33       ` Juan Quintela
2023-10-11 14:36         ` Дмитрий Фролов
2023-10-11 13:07 ` Juan Quintela

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.