From mboxrd@z Thu Jan 1 00:00:00 1970 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 From: Jeff Cody 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> Subject: [Qemu-devel] [PULL for-2.8 1/1] gluster: Fix use after free in glfs_clear_preopened() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-block@nongnu.org Cc: peter.maydell@linaro.org, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com 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; -- 2.7.4