From patchwork Tue Apr 12 15:06:42 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 8811381 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 94FB69F39A for ; Tue, 12 Apr 2016 15:07:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DC11720357 for ; Tue, 12 Apr 2016 15:07:09 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 3873720306 for ; Tue, 12 Apr 2016 15:07:09 +0000 (UTC) Received: from localhost ([::1]:51525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apzuG-0000Uw-9t for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 11:07:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apzu5-0000Nw-NO for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:07:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apzu2-0005Nw-EV for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:06:57 -0400 Received: from mail-qg0-x22b.google.com ([2607:f8b0:400d:c04::22b]:33743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apzu2-0005Nr-8m for qemu-devel@nongnu.org; Tue, 12 Apr 2016 11:06:54 -0400 Received: by mail-qg0-x22b.google.com with SMTP id j35so18263038qge.0 for ; Tue, 12 Apr 2016 08:06:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=S7kfmcV3hXqxbrtyZwOpIbG+XUnPAjE1c6Ov+DCSnt4=; b=AVXHlWiVIUbxk7atYjtPrqK4/OopJQGZzpAvr6xB8MCIed+scz8HS8/h+QSQLcS5cM QbYOt9CWyozR1pqCEWkieDdv2jnMiushfG1t9CP+/e/y4fq6lCh0UwdXbFbpYa1j6i61 sHKniHMVWxOdkrREjkDRv7Gx/MnKap5hw9N1iIcQD+eec0eYkP6KTm8rh3yGC2fPAbwr RdWD58XMqzO35emGeWbViKYDo7Or31amKTV2NRcFyYre8pd2HVQiZLEdHuh0iy2oPeGN q6ecy3bUk2Ha2o0aZLQQA39nZBZDqExquCPebPioKmEwg3qrpd14xHUwqSwnXYKsSIRx cPWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=S7kfmcV3hXqxbrtyZwOpIbG+XUnPAjE1c6Ov+DCSnt4=; b=YYNisiQXPw0vR3c1EQ/0qTz/CJ6s5YRs0QS5k7LFjpaW9aOYziAY0f68g8Rx9os3Z+ pNIXFNLni3YsEy6pixwPtGOVT37JnPyMOGY/bameXp7TrzU5V4L1CHX2k/HGmBES3Q/j /FfUeR1foDwIhUu8lfQaxffJOihsbbu4IbzafEXa3bY+nqP/0ejHiGvWzmFP4jw1kqSO dfrv+kiy94HVtGxHea7l5bsfrozfpQiTiIFy0Shq+uLE6JHLn4Aajfr6IR2+PVtnBSRs +gmzuOvuzAE0G+bF/LBUD7Si7OBtrodTmkW+U9y6zEtMnPuvnXdgyVK+c9iqpNv5jGr5 vNuQ== X-Gm-Message-State: AOPr4FWckdS4rTsm7sIXdwzIJ9do4Hv9arK1Bzfd0ZGZiBqOrjBkaTTmVAENQy9x4jRcdQ== X-Received: by 10.140.161.135 with SMTP id h129mr4775918qhh.66.1460473613862; Tue, 12 Apr 2016 08:06:53 -0700 (PDT) Received: from localhost (bne75-h02-31-39-163-232.dsl.sta.abo.bbox.fr. [31.39.163.232]) by smtp.gmail.com with ESMTPSA id o111sm12815842qge.23.2016.04.12.08.06.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 08:06:52 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 17:06:42 +0200 Message-Id: <1460473602-4830-1-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.5.5 MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::22b Subject: [Qemu-devel] [PATCHv2 for-2.6] ivshmem: fix ivshmem-{plain, doorbell} crash without arg 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: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , armbru@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau "qemu -device ivshmem-{plain,doorbell}" will crash, because the device doesn't check that the required argument is provided. Signed-off-by: Marc-André Lureau Reviewed-by: Markus Armbruster --- hw/misc/ivshmem.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 2eb8668..e40f23b 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -872,6 +872,8 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem, &error_abort); } else { + assert(s->server_chr); + IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", s->server_chr->filename); @@ -1051,10 +1053,24 @@ static void ivshmem_plain_init(Object *obj) &error_abort); } +static void ivshmem_plain_realize(PCIDevice *dev, Error **errp) +{ + IVShmemState *s = IVSHMEM_COMMON(dev); + + if (!s->hostmem) { + error_setg(errp, "You must specify a 'memdev'"); + return; + } + + ivshmem_common_realize(dev, errp); +} + static void ivshmem_plain_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + k->realize = ivshmem_plain_realize; dc->props = ivshmem_plain_properties; dc->vmsd = &ivshmem_plain_vmsd; } @@ -1099,10 +1115,24 @@ static void ivshmem_doorbell_init(Object *obj) s->legacy_size = SIZE_MAX; /* whatever the server sends */ } +static void ivshmem_doorbell_realize(PCIDevice *dev, Error **errp) +{ + IVShmemState *s = IVSHMEM_COMMON(dev); + + if (!s->server_chr) { + error_setg(errp, "You must specify a 'chardev'"); + return; + } + + ivshmem_common_realize(dev, errp); +} + static void ivshmem_doorbell_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); + k->realize = ivshmem_doorbell_realize; dc->props = ivshmem_doorbell_properties; dc->vmsd = &ivshmem_doorbell_vmsd; }