From patchwork Mon Sep 5 18:13:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9315061 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD9FA60760 for ; Mon, 5 Sep 2016 18:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C185E2881A for ; Mon, 5 Sep 2016 18:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B68A02894D; Mon, 5 Sep 2016 18:59:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3A7822881A for ; Mon, 5 Sep 2016 18:59:23 +0000 (UTC) Received: from localhost ([::1]:56383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgz74-0007AK-97 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 05 Sep 2016 14:59:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgyPx-0003Hh-Li for qemu-devel@nongnu.org; Mon, 05 Sep 2016 14:14:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bgyPq-00015Q-65 for qemu-devel@nongnu.org; Mon, 05 Sep 2016 14:14:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bgyPj-00010s-6w; Mon, 05 Sep 2016 14:14:35 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (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 DCF287DD39; Mon, 5 Sep 2016 18:14:34 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-62.ams2.redhat.com [10.36.116.62]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u85IDt7s020627; Mon, 5 Sep 2016 14:14:33 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Mon, 5 Sep 2016 20:13:42 +0200 Message-Id: <1473099234-10882-31-git-send-email-kwolf@redhat.com> In-Reply-To: <1473099234-10882-1-git-send-email-kwolf@redhat.com> References: <1473099234-10882-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Mon, 05 Sep 2016 18:14:34 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 30/42] test-coroutine: Fix coroutine pool corruption 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: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The test case overwrites the Coroutine object with 0xff as a way to assert that the coroutine isn't used any more. However, this means that the coroutine pool now contains a corrupted object and later test cases may get this corrupted object and crash. This patch saves the real content of the object and restores it after completing the test. The only use of the coroutine pool between those two points is the deletion of co2. As this only means an insertion at the head of an SLIST (release_pool or alloc_pool), it doesn't access the invalid list pointers that co1 has during this period. Signed-off-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi --- tests/test-coroutine.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c index ee5e06d..6431dd6 100644 --- a/tests/test-coroutine.c +++ b/tests/test-coroutine.c @@ -139,13 +139,20 @@ static void test_co_queue(void) { Coroutine *c1; Coroutine *c2; + Coroutine tmp; c2 = qemu_coroutine_create(c2_fn, NULL); c1 = qemu_coroutine_create(c1_fn, c2); qemu_coroutine_enter(c1); + + /* c1 shouldn't be used any more now; make sure we segfault if it is */ + tmp = *c1; memset(c1, 0xff, sizeof(Coroutine)); qemu_coroutine_enter(c2); + + /* Must restore the coroutine now to avoid corrupted pool */ + *c1 = tmp; } /*