[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/14] block/vpc: Avoid dynamic stack allocation
From: |
Kevin Wolf |
Subject: |
[PULL 01/14] block/vpc: Avoid dynamic stack allocation |
Date: |
Mon, 4 Sep 2023 16:36:30 +0200 |
From: Philippe Mathieu-Daudé <philmd@redhat.com>
Use autofree heap allocation instead of variable-length array on the
stack. Here we don't expect the bitmap size to be enormous, and
since we're about to read/write it to disk the overhead of the
allocation should be fine.
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é <philmd@redhat.com>
[PMM: expanded commit message]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-ID: <20230811175229.808139-1-peter.maydell@linaro.org>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vpc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/vpc.c b/block/vpc.c
index 3810a601a3..ceb87dd3d8 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -510,7 +510,7 @@ get_image_offset(BlockDriverState *bs, uint64_t offset,
bool write, int *err)
miss sparse read optimization, but it's not a problem in terms of
correctness. */
if (write && (s->last_bitmap_offset != bitmap_offset)) {
- uint8_t bitmap[s->bitmap_size];
+ g_autofree uint8_t *bitmap = g_malloc(s->bitmap_size);
int r;
s->last_bitmap_offset = bitmap_offset;
@@ -558,7 +558,7 @@ alloc_block(BlockDriverState *bs, int64_t offset)
int64_t bat_offset;
uint32_t index, bat_value;
int ret;
- uint8_t bitmap[s->bitmap_size];
+ g_autofree uint8_t *bitmap = g_malloc(s->bitmap_size);
/* Check if sector_num is valid */
if ((offset < 0) || (offset > bs->total_sectors * BDRV_SECTOR_SIZE)) {
--
2.41.0
- [PULL 00/14] Block layer patches, Kevin Wolf, 2023/09/04
- [PULL 02/14] iotests: adapt test output for new qemu_cleanup() behavior, Kevin Wolf, 2023/09/04
- [PULL 01/14] block/vpc: Avoid dynamic stack allocation,
Kevin Wolf <=
- [PULL 03/14] block: minimize bs->reqs_lock section in tracked_request_end(), Kevin Wolf, 2023/09/04
- [PULL 04/14] block: change reqs_lock to QemuMutex, Kevin Wolf, 2023/09/04
- [PULL 06/14] block/iscsi: Document why we use raw malloc(), Kevin Wolf, 2023/09/04
- [PULL 07/14] block: Be more verbose in create fallback, Kevin Wolf, 2023/09/04
- [PULL 05/14] qemu-img: omit errno value in error message, Kevin Wolf, 2023/09/04
- [PULL 09/14] vmdk: Clean up bdrv_open_child() return value check, Kevin Wolf, 2023/09/04
- [PULL 08/14] qemu-img: Update documentation for compressed images, Kevin Wolf, 2023/09/04
- [PULL 10/14] block: remove AIOCBInfo->get_aio_context(), Kevin Wolf, 2023/09/04
- [PULL 13/14] block: Remove bdrv_query_block_node_info, Kevin Wolf, 2023/09/04
- [PULL 14/14] block: Remove unnecessary variable in bdrv_block_device_info, Kevin Wolf, 2023/09/04