From nobody Sat Oct 25 21:45:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521194054346527.4493710270687; Fri, 16 Mar 2018 02:54:14 -0700 (PDT) Received: from localhost ([::1]:55807 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewm3x-0007xB-HJ for importer@patchew.org; Fri, 16 Mar 2018 05:54:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36529) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ewm1g-0006YV-L6 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ewm1d-00049r-J5 for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:52 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:40713 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ewm1d-000498-Ec for qemu-devel@nongnu.org; Fri, 16 Mar 2018 05:51:49 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B6377C6CC; Fri, 16 Mar 2018 09:51:44 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-92.ams2.redhat.com [10.36.116.92]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1A05CC1234; Fri, 16 Mar 2018 09:51:42 +0000 (UTC) From: Thomas Huth To: qemu-devel@nongnu.org Date: Fri, 16 Mar 2018 10:51:29 +0100 Message-Id: <1521193892-15552-2-git-send-email-thuth@redhat.com> In-Reply-To: <1521193892-15552-1-git-send-email-thuth@redhat.com> References: <1521193892-15552-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 09:51:44 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 16 Mar 2018 09:51:44 +0000 (UTC) for IP:'10.11.54.5' DOMAIN:'int-mx05.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 1/4] hw/net/can: Fix segfaults when using the devices without bus 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: Eduardo Habkost , Alexey Kardashevskiy , Jason Wang , Gerd Hoffmann , Paolo Bonzini , John Snow , Pavel Pisa Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The CAN devices can currently be used to crash QEMU, e.g.: $ x86_64-softmmu/qemu-system-x86_64 -device kvaser_pci Segmentation fault (core dumped) So we've got to add a proper check here that the corresponding bus is available. Signed-off-by: Thomas Huth --- hw/net/can/can_sja1000.c | 4 ++++ scripts/device-crash-test | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/hw/net/can/can_sja1000.c b/hw/net/can/can_sja1000.c index 6293233..9a85038 100644 --- a/hw/net/can/can_sja1000.c +++ b/hw/net/can/can_sja1000.c @@ -866,6 +866,10 @@ int can_sja_connect_to_bus(CanSJA1000State *s, CanBusS= tate *bus) { s->bus_client.info =3D &can_sja_bus_client_info; =20 + if (!bus) { + return -EINVAL; + } + if (can_bus_insert_client(bus, &s->bus_client) < 0) { return -1; } diff --git a/scripts/device-crash-test b/scripts/device-crash-test index f04f349..7ff351d 100755 --- a/scripts/device-crash-test +++ b/scripts/device-crash-test @@ -223,9 +223,6 @@ ERROR_WHITELIST =3D [ {'exitcode':-11, 'device':'sb16', 'loglevel':logging.ERROR, 'expected'= :True}, {'exitcode':-11, 'device':'cs4231a', 'loglevel':logging.ERROR, 'expect= ed':True}, {'exitcode':-11, 'machine':'isapc', 'device':'.*-iommu', 'loglevel':lo= gging.ERROR, 'expected':True}, - {'exitcode':-11, 'device':'mioe3680_pci', 'loglevel':logging.ERROR, 'e= xpected':True}, - {'exitcode':-11, 'device':'pcm3680_pci', 'loglevel':logging.ERROR, 'ex= pected':True}, - {'exitcode':-11, 'device':'kvaser_pci', 'loglevel':logging.ERROR, 'exp= ected':True}, =20 # everything else (including SIGABRT and SIGSEGV) will be a fatal erro= r: {'exitcode':None, 'fatal':True, 'loglevel':logging.FATAL}, --=20 1.8.3.1