From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=52271 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PTeMN-0001hJ-8W for qemu-devel@nongnu.org; Fri, 17 Dec 2010 12:46:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PTeLN-0002pc-1R for qemu-devel@nongnu.org; Fri, 17 Dec 2010 12:44:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51006) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PTeLM-0002pN-Ne for qemu-devel@nongnu.org; Fri, 17 Dec 2010 12:43:48 -0500 From: Kevin Wolf Date: Fri, 17 Dec 2010 18:44:16 +0100 Message-Id: <1292607893-13461-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1292607893-13461-1-git-send-email-kwolf@redhat.com> References: <1292607893-13461-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 01/38] blockdev: check dinfo ptr before using List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Ryan Harper If a user decides to punish a guest by revoking its block device via drive_del, and subsequently also attempts to remove the pci device backing it, and the device is using blockdev_auto_del() then we get a segfault when we attempt to access dinfo->auto_del.[1] The fix is to check if drive_get_by_blockdev() actually returns a valid dinfo pointer or not. 1. (qemu) pci_add auto storage file=images/test01.raw,if=virtio,id=block1,snapshot=on (qemu) drive_del block1 (qemu) pci_del 5 *segfault* Signed-off-by: Ryan Harper Tested-by: Luiz Capitulino Signed-off-by: Kevin Wolf --- blockdev.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/blockdev.c b/blockdev.c index f6ac439..3b3b82d 100644 --- a/blockdev.c +++ b/blockdev.c @@ -30,14 +30,16 @@ void blockdev_mark_auto_del(BlockDriverState *bs) { DriveInfo *dinfo = drive_get_by_blockdev(bs); - dinfo->auto_del = 1; + if (dinfo) { + dinfo->auto_del = 1; + } } void blockdev_auto_del(BlockDriverState *bs) { DriveInfo *dinfo = drive_get_by_blockdev(bs); - if (dinfo->auto_del) { + if (dinfo && dinfo->auto_del) { drive_uninit(dinfo); } } -- 1.7.2.3