[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 06/12] util/filemonitor-inotify: qemu_file_monitor_watch(): assert
|
From: |
Peter Maydell |
|
Subject: |
[PULL 06/12] util/filemonitor-inotify: qemu_file_monitor_watch(): assert no overflow |
|
Date: |
Mon, 6 Nov 2023 15:32:32 +0000 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Prefer clear assertions instead of [im]possible array overflow.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Maksim Davydov <davydov-max@yandex-team.ru>
Message-id: 20231017125941.810461-3-vsementsov@yandex-team.ru
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
util/filemonitor-inotify.c | 25 +++++++++++++++++--------
1 file changed, 17 insertions(+), 8 deletions(-)
diff --git a/util/filemonitor-inotify.c b/util/filemonitor-inotify.c
index 2c45f7f1764..2121111f38b 100644
--- a/util/filemonitor-inotify.c
+++ b/util/filemonitor-inotify.c
@@ -81,16 +81,25 @@ static void qemu_file_monitor_watch(void *arg)
/* Loop over all events in the buffer */
while (used < len) {
- struct inotify_event *ev =
- (struct inotify_event *)(buf + used);
- const char *name = ev->len ? ev->name : "";
- QFileMonitorDir *dir = g_hash_table_lookup(mon->idmap,
- GINT_TO_POINTER(ev->wd));
- uint32_t iev = ev->mask &
- (IN_CREATE | IN_MODIFY | IN_DELETE | IN_IGNORED |
- IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB);
+ const char *name;
+ QFileMonitorDir *dir;
+ uint32_t iev;
int qev;
gsize i;
+ struct inotify_event *ev = (struct inotify_event *)(buf + used);
+
+ /*
+ * We trust the kenel to provide valid buffer with complete event
+ * records.
+ */
+ assert(len - used >= sizeof(struct inotify_event));
+ assert(len - used - sizeof(struct inotify_event) >= ev->len);
+
+ name = ev->len ? ev->name : "";
+ dir = g_hash_table_lookup(mon->idmap, GINT_TO_POINTER(ev->wd));
+ iev = ev->mask &
+ (IN_CREATE | IN_MODIFY | IN_DELETE | IN_IGNORED |
+ IN_MOVED_TO | IN_MOVED_FROM | IN_ATTRIB);
used += sizeof(struct inotify_event) + ev->len;
--
2.34.1
- [PULL 00/12] target-arm queue, Peter Maydell, 2023/11/06
- [PULL 01/12] hw/arm/virt: fix PMU IRQ registration, Peter Maydell, 2023/11/06
- [PULL 03/12] hw/arm/virt: Report correct register sizes in ACPI DBG2/SPCR tables., Peter Maydell, 2023/11/06
- [PULL 11/12] hw/arm/vexpress-a9: Remove useless mapping of RAM at address 0, Peter Maydell, 2023/11/06
- [PULL 04/12] tests/qtest/bios-tables-test: Update virt SPCR and DBG2 golden references, Peter Maydell, 2023/11/06
- [PULL 07/12] mc146818rtc: rtc_set_time(): initialize tm to zeroes, Peter Maydell, 2023/11/06
- [PULL 05/12] hw/i386/intel_iommu: vtd_slpte_nonzero_rsvd(): assert no overflow, Peter Maydell, 2023/11/06
- [PULL 06/12] util/filemonitor-inotify: qemu_file_monitor_watch(): assert no overflow,
Peter Maydell <=
- [PULL 10/12] io/channel-socket: qio_channel_socket_flush(): improve msg validation, Peter Maydell, 2023/11/06
- [PULL 09/12] hw/core/loader: gunzip(): initialize z_stream, Peter Maydell, 2023/11/06
- [PULL 08/12] block/nvme: nvme_process_completion() fix bound for cid, Peter Maydell, 2023/11/06
- [PULL 02/12] tests/qtest/bios-tables-test: Allow changes to virt SPCR and DBG2, Peter Maydell, 2023/11/06
- [PULL 12/12] target/arm: Fix A64 LDRA immediate decode, Peter Maydell, 2023/11/06
- Re: [PULL 00/12] target-arm queue, Stefan Hajnoczi, 2023/11/06