* [PATCH v4] exec: set map length to zero when returning NULL
@ 2020-05-26 11:17 P J P
2020-05-26 11:21 ` Philippe Mathieu-Daudé
2020-06-04 17:58 ` Paolo Bonzini
0 siblings, 2 replies; 3+ messages in thread
From: P J P @ 2020-05-26 11:17 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Fam Zheng, Peter Maydell, Prasad J Pandit, QEMU Developers,
Alexander Bulekov, Ding Ren, Marc-André Lureau,
Philippe Mathieu-Daudé
From: Prasad J Pandit <pjp@fedoraproject.org>
When mapping physical memory into host's virtual address space,
'address_space_map' may return NULL if BounceBuffer is in_use.
Set and return '*plen = 0' to avoid later NULL pointer dereference.
Reported-by: Alexander Bulekov <alxndr@bu.edu>
Fixes: https://bugs.launchpad.net/qemu/+bug/1878259
Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
Suggested-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
exec.c | 1 +
include/exec/memory.h | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
Update v4: update address_space_map API doc text
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html
diff --git a/exec.c b/exec.c
index 5162f0d12f..4eea84bf66 100644
--- a/exec.c
+++ b/exec.c
@@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
if (!memory_access_is_direct(mr, is_write)) {
if (atomic_xchg(&bounce.in_use, true)) {
+ *plen = 0;
return NULL;
}
/* Avoid unbounded allocations */
diff --git a/include/exec/memory.h b/include/exec/memory.h
index e000bd2f97..8fa2d3cab2 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
/* address_space_map: map a physical memory region into a host virtual address
*
* May map a subset of the requested range, given by and returned in @plen.
- * May return %NULL if resources needed to perform the mapping are exhausted.
+ * May return %NULL and set *@plen to zero(0), if resources needed to perform
+ * the mapping are exhausted.
* Use only for reads OR writes - not for read-modify-write operations.
* Use cpu_register_map_client() to know when retrying the map operation is
* likely to succeed.
--
2.26.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4] exec: set map length to zero when returning NULL
2020-05-26 11:17 [PATCH v4] exec: set map length to zero when returning NULL P J P
@ 2020-05-26 11:21 ` Philippe Mathieu-Daudé
2020-06-04 17:58 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-05-26 11:21 UTC (permalink / raw)
To: P J P, Paolo Bonzini
Cc: Fam Zheng, Peter Maydell, Prasad J Pandit, QEMU Developers,
Alexander Bulekov, Ding Ren, Marc-André Lureau
On 5/26/20 1:17 PM, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> When mapping physical memory into host's virtual address space,
> 'address_space_map' may return NULL if BounceBuffer is in_use.
> Set and return '*plen = 0' to avoid later NULL pointer dereference.
>
> Reported-by: Alexander Bulekov <alxndr@bu.edu>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1878259
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> exec.c | 1 +
> include/exec/memory.h | 3 ++-
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> Update v4: update address_space_map API doc text
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html
>
> diff --git a/exec.c b/exec.c
> index 5162f0d12f..4eea84bf66 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
>
> if (!memory_access_is_direct(mr, is_write)) {
> if (atomic_xchg(&bounce.in_use, true)) {
> + *plen = 0;
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> return NULL;
> }
> /* Avoid unbounded allocations */
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index e000bd2f97..8fa2d3cab2 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
> /* address_space_map: map a physical memory region into a host virtual address
> *
> * May map a subset of the requested range, given by and returned in @plen.
> - * May return %NULL if resources needed to perform the mapping are exhausted.
> + * May return %NULL and set *@plen to zero(0), if resources needed to perform
> + * the mapping are exhausted.
> * Use only for reads OR writes - not for read-modify-write operations.
> * Use cpu_register_map_client() to know when retrying the map operation is
> * likely to succeed.
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4] exec: set map length to zero when returning NULL
2020-05-26 11:17 [PATCH v4] exec: set map length to zero when returning NULL P J P
2020-05-26 11:21 ` Philippe Mathieu-Daudé
@ 2020-06-04 17:58 ` Paolo Bonzini
1 sibling, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-06-04 17:58 UTC (permalink / raw)
To: P J P
Cc: Fam Zheng, Peter Maydell, Prasad J Pandit, QEMU Developers,
Alexander Bulekov, Ding Ren, Marc-André Lureau,
Philippe Mathieu-Daudé
On 26/05/20 13:17, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
>
> When mapping physical memory into host's virtual address space,
> 'address_space_map' may return NULL if BounceBuffer is in_use.
> Set and return '*plen = 0' to avoid later NULL pointer dereference.
>
> Reported-by: Alexander Bulekov <alxndr@bu.edu>
> Fixes: https://bugs.launchpad.net/qemu/+bug/1878259
> Suggested-by: Paolo Bonzini <pbonzini@redhat.com>
> Suggested-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
> exec.c | 1 +
> include/exec/memory.h | 3 ++-
> 2 files changed, 3 insertions(+), 1 deletion(-)
>
> Update v4: update address_space_map API doc text
> -> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg07281.html
>
> diff --git a/exec.c b/exec.c
> index 5162f0d12f..4eea84bf66 100644
> --- a/exec.c
> +++ b/exec.c
> @@ -3538,6 +3538,7 @@ void *address_space_map(AddressSpace *as,
>
> if (!memory_access_is_direct(mr, is_write)) {
> if (atomic_xchg(&bounce.in_use, true)) {
> + *plen = 0;
> return NULL;
> }
> /* Avoid unbounded allocations */
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index e000bd2f97..8fa2d3cab2 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -2303,7 +2303,8 @@ bool address_space_access_valid(AddressSpace *as, hwaddr addr, hwaddr len,
> /* address_space_map: map a physical memory region into a host virtual address
> *
> * May map a subset of the requested range, given by and returned in @plen.
> - * May return %NULL if resources needed to perform the mapping are exhausted.
> + * May return %NULL and set *@plen to zero(0), if resources needed to perform
> + * the mapping are exhausted.
> * Use only for reads OR writes - not for read-modify-write operations.
> * Use cpu_register_map_client() to know when retrying the map operation is
> * likely to succeed.
>
Queued, thanks.
Paolo
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-06-04 17:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-26 11:17 [PATCH v4] exec: set map length to zero when returning NULL P J P
2020-05-26 11:21 ` Philippe Mathieu-Daudé
2020-06-04 17:58 ` Paolo Bonzini
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).