From patchwork Fri Aug 5 14:56:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12937351 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 44943C25B0C for ; Fri, 5 Aug 2022 14:57:50 +0000 (UTC) Received: from localhost ([::1]:52166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJylp-0006pt-A0 for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 10:57:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJykT-0005PY-9C for qemu-devel@nongnu.org; Fri, 05 Aug 2022 10:56:25 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:43974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJykR-0003Vp-RE for qemu-devel@nongnu.org; Fri, 05 Aug 2022 10:56:25 -0400 Received: by mail-pl1-x635.google.com with SMTP id 17so2836718plj.10 for ; Fri, 05 Aug 2022 07:56:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc; bh=7bCQ8cKqB7t3fSWKcCDxs4sfPXXEO07MKgBZafJIlOY=; b=K/+ibLDmsjan1uOI/ETWRsit/RQBuxX6e6iLHRO/LfwwfpaKJTSZlBdsTmKYTvZ8zj mtIyEunSsk9nR8jD6eBYPhU5dppW+JdkDgKC8nPpEMradWzY9Qfo/LCxXcMS3309dfLP kQmKjhLFcgtH7LgejottDIJZky0/k9t8bwsW8ePq61ALdaCu/3z6drPcrkaT2Yc3FMLq z5BDyeyT6UqrMIsGO0jp4S1YExtfCfGlmItB6OilP0c2/22PRkvQEgB2jIeUT0YvDpki BKytL4YCV8TpTfWZoRF84PKBLN2zxyyngoVnFFnZ6T8a5hRyEGiKvIZq49UYblP4JHW+ a8HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc; bh=7bCQ8cKqB7t3fSWKcCDxs4sfPXXEO07MKgBZafJIlOY=; b=hTAoLLp2xERR0mrxtCqOAC2omGNL+acwm5fD00cnzaXf15Igg+5xi/MyB3x/ZpFxAG emDvwaaaImpQXIHKo/wvfeDTqVEBDObeh1hruyCvDggwHSwEE0Pq4x9BhlzRhpkdKCNH LkLt3fxtUAcUqqVlikNd/eeA3EmG6EircbldgjdE7kPKUFFPmbtegAN52wYxF7xpk/LY 1tX8663M+Dl3oiZ4XouK1y5Ac0VfCCKqwzbHx+uljMFFt8L0Sqb3/8KX60UF4ufeH+9T jbNBhYcB3WbhgvUF0b8FoemV1u7KdoTOXjkZKeAtuykwYYM5ldnEzrHe1uyzJB/muZmj wwIw== X-Gm-Message-State: ACgBeo1OowodED7kjZVzCiiwXoMKSFUiD0nVFlWAclml5Iet+0Cwj6xk LqmFmrcuYISF0O3y1oQCZSuVzzDvdvY= X-Google-Smtp-Source: AA6agR5iHlqj2IKA9utIKO/QJglkRD6NK6hztWWxBM7i4PUK89vVeRyI36ggXnGyOgW8UZJUQDWSPg== X-Received: by 2002:a17:90b:1bc7:b0:1f5:37a6:e473 with SMTP id oa7-20020a17090b1bc700b001f537a6e473mr7808393pjb.87.1659711381774; Fri, 05 Aug 2022 07:56:21 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id c18-20020a170902d49200b0016bfafffa0esm3166814plg.227.2022.08.05.07.56.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 07:56:21 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , Paolo Bonzini Subject: [PATCH 1/2] util/main-loop: Fix maximum number of wait objects for win32 Date: Fri, 5 Aug 2022 22:56:16 +0800 Message-Id: <20220805145617.952881-1-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::635; envelope-from=bmeng.cn@gmail.com; helo=mail-pl1-x635.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng The maximum number of wait objects for win32 should be MAXIMUM_WAIT_OBJECTS, not MAXIMUM_WAIT_OBJECTS + 1. Signed-off-by: Bin Meng Reviewed-by: Philippe Mathieu-Daudé --- util/main-loop.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/util/main-loop.c b/util/main-loop.c index f00a25451b..f15d8e7d12 100644 --- a/util/main-loop.c +++ b/util/main-loop.c @@ -363,10 +363,10 @@ void qemu_del_polling_cb(PollingFunc *func, void *opaque) /* Wait objects support */ typedef struct WaitObjects { int num; - int revents[MAXIMUM_WAIT_OBJECTS + 1]; - HANDLE events[MAXIMUM_WAIT_OBJECTS + 1]; - WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS + 1]; - void *opaque[MAXIMUM_WAIT_OBJECTS + 1]; + int revents[MAXIMUM_WAIT_OBJECTS]; + HANDLE events[MAXIMUM_WAIT_OBJECTS]; + WaitObjectFunc *func[MAXIMUM_WAIT_OBJECTS]; + void *opaque[MAXIMUM_WAIT_OBJECTS]; } WaitObjects; static WaitObjects wait_objects = {0}; From patchwork Fri Aug 5 14:56:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 12937352 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 242C5C00140 for ; Fri, 5 Aug 2022 14:58:03 +0000 (UTC) Received: from localhost ([::1]:52296 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oJym1-0006vD-0F for qemu-devel@archiver.kernel.org; Fri, 05 Aug 2022 10:58:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oJykV-0005RT-KB; Fri, 05 Aug 2022 10:56:27 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:44586) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oJykU-0003W2-A8; Fri, 05 Aug 2022 10:56:27 -0400 Received: by mail-pj1-x102b.google.com with SMTP id e8-20020a17090a280800b001f2fef7886eso3069571pjd.3; Fri, 05 Aug 2022 07:56:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=JCf8BpsoGS5qqjGfLu/HY6lWex7KsOE/xca4FpD4SY0=; b=MsT6Ao39JkeGMyqg8pd306nlMPbRKJm33PccBY/OUjaEzBTmdkTmAWzlB/ye3tze3Z Dedb6n1KKW5nfLh9R/zXk5/0iTW74j5dMFu5autU1k1JEWY4JvyJPO22eIySgJZXBtdI 8YHP/z5qlvmjYAAE4xw+bD3pIW12gRwZEw/qJ3iq1FW0T9tYl5AKTWt3KDGDWx2h/yCZ Yb1lYCV6n4kD7OC8eP+FQWvqFtZb1YQr2+mV/z/MDUOCxfGoGm/A8eBcNT5soiD4z1VP k1vLMM9HdjCCshW4ArSe4XwzqrUYU/958zSOrsZerVSGqi96l3mGi4mnptwPX2xzOB9z qghg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=JCf8BpsoGS5qqjGfLu/HY6lWex7KsOE/xca4FpD4SY0=; b=uGs29aSS7mg9v/k0McO285CDZrgAFzY9SmizNyRozxCvy+uespBsDrfoY+GqLeS36L qCk4Pl9md/u1sg9ZMwXHaThzn4X6WadRfxc/e3snAlNTis19p0syZwUxRg4b4hHHwRPo SU2B+mflvjsSF1DIRDEq8XrpND/Nfba+0MxoethennYOeDBibJPpgO/EDttKAsFuoDdY z2y61C5+OV6OCFTZKuWGhhm+zdyj+Hgu6pOWHTHS4eeWZm4PXwyxdnpWqnG8bk42ZIuY IRFlD69FjCaIpdFDDl8UDO4cVzxRpHJFfDB1lUFsI0rGLKBZITQLx41eRXLAC/8yrz8p T5pQ== X-Gm-Message-State: ACgBeo2eH5fztgGAegxJdXMcH1XS8od5XknPeUvW3h14ITWNdiIBvZaz e2ebLXegU9jPWBx28bxYCEHKsDWL+CM= X-Google-Smtp-Source: AA6agR6n97o+BSt0ro2OuRjZoYCbtck5wqOeClah+MAfg4r48RmelX2Diht9+idO2gUvZy3soTlRkQ== X-Received: by 2002:a17:90b:4d91:b0:1f5:2073:6cfd with SMTP id oj17-20020a17090b4d9100b001f520736cfdmr16288936pjb.175.1659711384374; Fri, 05 Aug 2022 07:56:24 -0700 (PDT) Received: from ubuntu.. (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id c18-20020a170902d49200b0016bfafffa0esm3166814plg.227.2022.08.05.07.56.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 07:56:24 -0700 (PDT) From: Bin Meng To: qemu-devel@nongnu.org Cc: Bin Meng , Fam Zheng , Stefan Hajnoczi , Stefan Weil , qemu-block@nongnu.org Subject: [PATCH 2/2] util/aio-win32: Correct the event array size in aio_poll() Date: Fri, 5 Aug 2022 22:56:17 +0800 Message-Id: <20220805145617.952881-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220805145617.952881-1-bmeng.cn@gmail.com> References: <20220805145617.952881-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=bmeng.cn@gmail.com; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" From: Bin Meng WaitForMultipleObjects() can only wait for MAXIMUM_WAIT_OBJECTS object handles. Correct the event array size in aio_poll() and add a assert() to ensure it does not cause out of bound access. Signed-off-by: Bin Meng Reviewed-by: Stefan Weil --- util/aio-win32.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/aio-win32.c b/util/aio-win32.c index 44003d645e..8cf5779567 100644 --- a/util/aio-win32.c +++ b/util/aio-win32.c @@ -326,7 +326,7 @@ void aio_dispatch(AioContext *ctx) bool aio_poll(AioContext *ctx, bool blocking) { AioHandler *node; - HANDLE events[MAXIMUM_WAIT_OBJECTS + 1]; + HANDLE events[MAXIMUM_WAIT_OBJECTS]; bool progress, have_select_revents, first; int count; int timeout; @@ -369,6 +369,7 @@ bool aio_poll(AioContext *ctx, bool blocking) QLIST_FOREACH_RCU(node, &ctx->aio_handlers, node) { if (!node->deleted && node->io_notify && aio_node_check(ctx, node->is_external)) { + assert(count < MAXIMUM_WAIT_OBJECTS); events[count++] = event_notifier_get_handle(node->e); } }