Skip to contentSkip to conversation

exec: set map length to zero when returning NULL

PATCH Superseded P J P 3 participants 5 messages May 26, 2020

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH v3 1/1 exec: set map length to zero when returning NULL

From: Prasad J Pandit <[email protected]>

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.

---
 exec.c | 1 +
 1 file changed, 1 insertion(+)

Update v3: set *plen = 0;
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg06249.html

exec.c +1 -0
index 5162f0d12f..4eea84bf66 100644
@@ -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 */
Signature · 1 line
2.26.2
Reviewed-by on v3 1/1
#1 lore raw
Quoted 22 lines · P J P

From: Prasad J Pandit <[email protected]>

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.

---
 exec.c | 1 +
 1 file changed, 1 insertion(+)

Update v3: set *plen = 0;
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg06249.html

exec.c +0 -0
index 5162f0d12f..4eea84bf66 100644

exec.c void *address_space_map(AddressSpace *as, · line 3544

Quoted 7 lines
exec.c +1 -0
@@ -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 */
#2 lore raw
In reply to P J P
Quoted 8 lines · P J P

From: Prasad J Pandit <[email protected]>

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.

Quoted 24 lines
---
 exec.c | 1 +
 1 file changed, 1 insertion(+)

Update v3: set *plen = 0;
-> https://lists.gnu.org/archive/html/qemu-devel/2020-05/msg06249.html

exec.c +1 -1
index 5162f0d12f..4eea84bf66 100644
@@ -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 */
--

2.26.2

#3 lore raw
In reply to P J P
Quoted 10 lines · P J P

From: Prasad J Pandit <[email protected]>

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.

The doc comment for this function in include/exec/memory.h currently says
"May return %NULL if resources needed to perform the mapping
are exhausted."

If we're tightening the API to guarantee to also set *plen to 0 in this failure case it would be good to capture that in the documentation, eg:

"May return %NULL (and set *@plen to 0) if resources needed
to perform the mapping are exhausted.)"

thanks
-- PMM

author
#4 lore raw
+-- On Tue, 26 May 2020, Peter Maydell wrote --+
| The doc comment for this function in include/exec/memory.h currently says
| 
| "May return %NULL if resources needed to perform the mapping
|  are exhausted."
| 
| If we're tightening the API to guarantee to also set *plen to 0 in this 
| failure case it would be good to capture that in the documentation, eg:
| 
| "May return %NULL (and set *@plen to 0) if resources needed
|  to perform the mapping are exhausted.)"

Sending patch v4. Thank you.
--
Prasad J Pandit / Red Hat Product Security Team
8685 545E B54C 486B C6EB 271E E285 8B5A F050 DE8D