From patchwork Mon Nov 21 22:14:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 697431 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tN2zq4zWcz9sxS for ; Tue, 22 Nov 2016 09:18:15 +1100 (AEDT) Received: from localhost ([::1]:52006 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8wui-0003P9-PR for incoming@patchwork.ozlabs.org; Mon, 21 Nov 2016 17:18:12 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45135) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c8wrm-0001Vk-2t for qemu-devel@nongnu.org; Mon, 21 Nov 2016 17:15:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c8wrl-0006mD-BF for qemu-devel@nongnu.org; Mon, 21 Nov 2016 17:15:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c8wrg-0006fr-1x; Mon, 21 Nov 2016 17:15:04 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 211D87F7C5; Mon, 21 Nov 2016 22:15:03 +0000 (UTC) Received: from localhost (ovpn-112-65.phx2.redhat.com [10.3.112.65]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uALMF1Ld013187 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 21 Nov 2016 17:15:02 -0500 From: Jeff Cody To: qemu-block@nongnu.org Date: Mon, 21 Nov 2016 17:14:59 -0500 Message-Id: <1479766499-29972-2-git-send-email-jcody@redhat.com> In-Reply-To: <1479766499-29972-1-git-send-email-jcody@redhat.com> References: <1479766499-29972-1-git-send-email-jcody@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 21 Nov 2016 22:15:03 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL for-2.8 1/1] gluster: Fix use after free in glfs_clear_preopened() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Kevin Wolf This fixes a use-after-free bug introduced in commit 6349c154. We need to use QLIST_FOREACH_SAFE() when freeing elements in the loop. Spotted by Coverity. Signed-off-by: Kevin Wolf Message-id: 1479378608-11962-1-git-send-email-kwolf@redhat.com Reviewed-by: Jeff Cody Signed-off-by: Jeff Cody --- block/gluster.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/block/gluster.c b/block/gluster.c index 0ce15f7..891c13b 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -239,12 +239,13 @@ static glfs_t *glfs_find_preopened(const char *volume) static void glfs_clear_preopened(glfs_t *fs) { ListElement *entry = NULL; + ListElement *next; if (fs == NULL) { return; } - QLIST_FOREACH(entry, &glfs_list, list) { + QLIST_FOREACH_SAFE(entry, &glfs_list, list, next) { if (entry->saved.fs == fs) { if (--entry->saved.ref) { return;