util/iov: Avoid dynamic stack allocation
PATCH 1/1 util/iov: Avoid dynamic stack allocation
From: Philippe Mathieu-Daudé <[email protected]>
Use autofree heap allocation instead of variable-length array on the stack.
The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527).
---
Usual "only tested with make check/make check-avocado" caveat.
util/iov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
util/iov.c +1 -1
@@ -571,7 +571,7 @@ static int sortelem_cmp_src_index(const void *a, const void *b)*/ void qemu_iovec_clone (QEMUIOVector *dest,const QEMUIOVector *src,void *buf) { -IOVectorSortElem sortelems[src->niov]; + g_autofree IOVectorSortElem *sortelems = g_new(IOVectorSortElem, src->niov);void *last_end;int i;
Signature · 1 line
2.34.1
Quoted 10 lines · Peter Maydell
From: Philippe Mathieu-Daudé <[email protected]>
Use autofree heap allocation instead of variable-length array on the stack.
The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527).
Quoted 7 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Maydell <[email protected]>---
Usual "only tested with make check/make check-avocado" caveat.util/iov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines
util/iov.c +1
-1@@ -571,7 +571,7 @@ static int sortelem_cmp_src_index(const void *a, const void *b)*/ void qemu_iovec_clone (QEMUIOVector *dest,const QEMUIOVector *src,void *buf) { -IOVectorSortElem sortelems[src->niov]; + g_autofree IOVectorSortElem *sortelems = g_new(IOVectorSortElem, src->niov);void *last_end;int i;Signature · 1 line
2.34.1
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Cc'ing qemu-block@ (I suppose this will go via a block tree)
Quoted 31 lines · Peter Maydell
From: Philippe Mathieu-Daudé <[email protected]>
Use autofree heap allocation instead of variable-length array on the stack.
The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Peter Maydell <[email protected]>---
Usual "only tested with make check/make check-avocado" caveat.util/iov.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)util/iov.c +1
-1@@ -571,7 +571,7 @@ static int sortelem_cmp_src_index(const void *a, const void *b)*/ void qemu_iovec_clone (QEMUIOVector *dest,const QEMUIOVector *src,void *buf) { -IOVectorSortElem sortelems[src->niov]; + g_autofree IOVectorSortElem *sortelems = g_new(IOVectorSortElem, src->niov);void *last_end;int i;
Quoted 1 line · Philippe Mathieu-Daudé
Cc'ing qemu-block@ (I suppose this will go via a block tree)
Makes sense.
I can queue it through my NBD tree if no one else beats me (since the nbd code is a heavy user of iovs).
Quoted 12 lines · Peter Maydell
Quoted 10 lines
From: Philippe Mathieu-Daudé <[email protected]>
Use autofree heap allocation instead of variable-length array on the stack.
The codebase has very few VLAs, and if we can get rid of them all we can make the compiler error on new additions. This is a defensive measure against security bugs where an on-stack dynamic allocation isn't correctly size-checked (e.g. CVE-2021-3527).
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org