From nobody Tue Feb 10 02:49:22 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1581700861497622.8224272267275; Fri, 14 Feb 2020 09:21:01 -0800 (PST) Received: from localhost ([::1]:42098 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2eeC-0006Ed-8U for importer@patchew.org; Fri, 14 Feb 2020 12:21:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49107) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j2eao-0000bn-Tx for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:17:32 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j2ean-0007FY-Rr for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:17:30 -0500 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:43050 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j2ean-0007Eq-Ns for qemu-devel@nongnu.org; Fri, 14 Feb 2020 12:17:29 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-329-ch3_E6IMPeOCiv8erYUMFg-1; Fri, 14 Feb 2020 12:17:27 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8DB0F107B273; Fri, 14 Feb 2020 17:17:26 +0000 (UTC) Received: from localhost (ovpn-116-135.ams2.redhat.com [10.36.116.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7527B5DA81; Fri, 14 Feb 2020 17:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1581700649; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Q9Ymt1qQx6vp3IXr8OqQ4TVPGWbrPBjiOimPtVWKsWE=; b=eG+cIERjQkA6qx+u1d20LV4U54rIwNW6sM+F0lUtQ3QouVYJCw47gnRy+X5AKrKkrYZ8p1 25gFeotpKZ32mpltbCjpSN7S/jvEM+fYd6Lo4/N3nmFUCN7aW3R7e4bBd9OwS+0QgvXa0c Wg29h2kyjya8REcgCDNUOzQnMkmpltg= From: Stefan Hajnoczi To: qemu-devel@nongnu.org Subject: [PATCH 1/5] aio-posix: fix use after leaving scope in aio_poll() Date: Fri, 14 Feb 2020 17:17:08 +0000 Message-Id: <20200214171712.541358-2-stefanha@redhat.com> In-Reply-To: <20200214171712.541358-1-stefanha@redhat.com> References: <20200214171712.541358-1-stefanha@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: ch3_E6IMPeOCiv8erYUMFg-1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.81 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fam Zheng , Kevin Wolf , qemu-block@nongnu.org, Max Reitz , Stefan Hajnoczi , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , Paolo Bonzini Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" epoll_handler is a stack variable and must not be accessed after it goes out of scope: if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) { AioHandler epoll_handler; ... add_pollfd(&epoll_handler); ret =3D aio_epoll(ctx, pollfds, npfd, timeout); } ... ... /* if we have any readable fds, dispatch event */ if (ret > 0) { for (i =3D 0; i < npfd; i++) { nodes[i]->pfd.revents =3D pollfds[i].revents; } } nodes[0] is &epoll_handler, which has already gone out of scope. There is no need to use pollfds[] for epoll. We don't need an AioHandler for the epoll fd. Signed-off-by: Stefan Hajnoczi Reviewed-by: Sergio Lopez --- util/aio-posix.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/util/aio-posix.c b/util/aio-posix.c index a4977f538e..31a8e03ca7 100644 --- a/util/aio-posix.c +++ b/util/aio-posix.c @@ -104,17 +104,18 @@ static void aio_epoll_update(AioContext *ctx, AioHand= ler *node, bool is_new) } } =20 -static int aio_epoll(AioContext *ctx, GPollFD *pfds, - unsigned npfd, int64_t timeout) +static int aio_epoll(AioContext *ctx, int64_t timeout) { + GPollFD pfd =3D { + .fd =3D ctx->epollfd, + .events =3D G_IO_IN | G_IO_OUT | G_IO_HUP | G_IO_ERR, + }; AioHandler *node; int i, ret =3D 0; struct epoll_event events[128]; =20 - assert(npfd =3D=3D 1); - assert(pfds[0].fd =3D=3D ctx->epollfd); if (timeout > 0) { - ret =3D qemu_poll_ns(pfds, npfd, timeout); + ret =3D qemu_poll_ns(&pfd, 1, timeout); } if (timeout <=3D 0 || ret > 0) { ret =3D epoll_wait(ctx->epollfd, events, @@ -658,13 +659,8 @@ bool aio_poll(AioContext *ctx, bool blocking) =20 /* wait until next event */ if (aio_epoll_check_poll(ctx, pollfds, npfd, timeout)) { - AioHandler epoll_handler; - - epoll_handler.pfd.fd =3D ctx->epollfd; - epoll_handler.pfd.events =3D G_IO_IN | G_IO_OUT | G_IO_HUP | G= _IO_ERR; - npfd =3D 0; - add_pollfd(&epoll_handler); - ret =3D aio_epoll(ctx, pollfds, npfd, timeout); + npfd =3D 0; /* pollfds[] is not being used */ + ret =3D aio_epoll(ctx, timeout); } else { ret =3D qemu_poll_ns(pollfds, npfd, timeout); } --=20 2.24.1