From patchwork Tue Apr 12 13:38:37 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: 8810631 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 AA4A79F54F for ; Tue, 12 Apr 2016 13:39:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0B17C20374 for ; Tue, 12 Apr 2016 13:39:32 +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 38B8C20357 for ; Tue, 12 Apr 2016 13:39:19 +0000 (UTC) Received: from localhost ([::1]:49760 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apyXG-0004Xb-LS for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Apr 2016 09:39:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apyX0-0004R7-41 for qemu-devel@nongnu.org; Tue, 12 Apr 2016 09:39:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1apyWw-0000jg-Mu for qemu-devel@nongnu.org; Tue, 12 Apr 2016 09:39:02 -0400 Received: from mail-qk0-x231.google.com ([2607:f8b0:400d:c09::231]:34830) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1apyWw-0000jc-Ii for qemu-devel@nongnu.org; Tue, 12 Apr 2016 09:38:58 -0400 Received: by mail-qk0-x231.google.com with SMTP id o6so6127072qkc.2 for ; Tue, 12 Apr 2016 06:38:58 -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=gVURRYuJSEaJzlbFGWMiXmZbTK8XoUSCppjw5vd49nU=; b=oJ9yl9al6n1LS9HTWB4MxwI4egqyGicV7VmhRDhvOmr589Iz0ULuLK+L2ifdnakQXi pX40h8/IbLG5xJlATI6oD3jhnz4VCNUo8ukcNHI2Tq69POapz5HrwQT/IhykbC4mkdXn Pate+4OUj8yJud/iYQJ9lzeFwsCvmusHKBOc2jz8zubNNTD9BA+QYHqzjJYUlzUD1CFJ N3JE8QdESiPmAcEdTDkFj+GNhCCx3J2zeBGjHhsD8ydmof7I0FHaqXp67OyLz7BCUwuF Hpx79zEnFHy1sPEartZ/T9+kVr96V/tBgvdnwjUkgAu1MBlruXrTx+MhpcnIVHoj2fCt a1xQ== 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=gVURRYuJSEaJzlbFGWMiXmZbTK8XoUSCppjw5vd49nU=; b=U6iOIvlbZKitGsRccJ4xGdWIeSmTI5diM9kJns+zILtOWbjQGg4/AMvyw/8XIwQQcP 3py9pz4KmrO8ZFj8Q1QioN/DjF/LbNgx0wCFQAabsUfWDBTm03f1nw4W3h5Z6tHJonkd 0I69/JRD+SPEhsccxxDxjLgzg6JOxE6RCefuZLNvhcmAtBWP9GBOEwQxBtF+VcaBB+YQ n43xx8qQyibqRorE1Q8NCd8PxvMAKU8D+32VgT75r4YwJkT65NzE9tQ1/OObi3iJc/3H y3U/XTgvE/cKLLmY2Oi8Lv4DtJk3ijDsQUsT85H3y4yuq6KpuJrc4oCJJsgkgBCHTVVo AZmQ== X-Gm-Message-State: AOPr4FX57kpV2CYsN8uka+VZUf/S6kVh6/kkJSTtRIq2Yy7QSHOZS0BSZdl/FOS1n2Av0g== X-Received: by 10.55.52.142 with SMTP id b136mr3527586qka.5.1460468338143; Tue, 12 Apr 2016 06:38:58 -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 130sm7144826qki.6.2016.04.12.06.38.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Apr 2016 06:38:57 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Tue, 12 Apr 2016 15:38:37 +0200 Message-Id: <1460468317-11863-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:c09::231 Subject: [Qemu-devel] [PATCH for-2.6] ivshmem: fix crash with ivshmem-plain 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" will crash, because it doesn't check that 'memdev' was provided. Signed-off-by: Marc-André Lureau --- hw/misc/ivshmem.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 08bf5c6..fae4d08 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -868,7 +868,7 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) s->ivshmem_bar2 = host_memory_backend_get_memory(s->hostmem, &error_abort); - } else { + } else if (s->server_chr) { IVSHMEM_DPRINTF("using shared memory server (socket = %s)\n", s->server_chr->filename); @@ -899,6 +899,8 @@ static void ivshmem_common_realize(PCIDevice *dev, Error **errp) error_setg(errp, "failed to initialize interrupts"); return; } + } else { + g_assert_not_reached(); } vmstate_register_ram(s->ivshmem_bar2, DEVICE(s)); @@ -1048,10 +1050,25 @@ 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; }