Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2288405imc; Tue, 12 Mar 2019 10:38:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwfpabHM1sI+OwilABwFKXdzopebKzUmgglQgpLhv3euAucyyF3EcMOZJu8CLnILyixTFo X-Received: by 2002:a62:4414:: with SMTP id r20mr39852095pfa.37.1552412337935; Tue, 12 Mar 2019 10:38:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552412337; cv=none; d=google.com; s=arc-20160816; b=gg73e/EEZyB3UDdtoj8bByVdND+YjFkL6hUaX/FZXCfgWVHAdOJPUe3ZJMo8d8CSwG 6/buIkRgbo+6/Ka+cLz5kJNXcTRtcBfbmJ+U3UCxqQKH/8g4iYVrhSJs9sc7D8vY2rlC U+zU31Y2NAokanuYXLeyEAPouBaxo7cWTcVAI3frIDq3XzfCqfKct55/iqFZTcONWPkM agUUErwazRwZ/YbJ3X9zPHuG+RdRRtli7+X8T3ADoXVnNkjSW35If0tb81/7lyhdc/a+ QTvOridBDlSVhGuUe/k67sLou1O0CQiKFreCHTPRZl9NynMI/isOXHi2fvPAjcy4LoJC PdrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=92QZ2+H0WkwAbMDJqMc4VZvtJmGVtic4NrU4AoYbTog=; b=mrrhiSYVbG4yfUsS9kz4yzIqsgloR6IcxvphsHDyarZ5gYEJVyQhX1t+VaEt7LgBoH QusvJ4thR9MTTGn0geIt+ToMv1x5woMg+1M11k5VaQ+mh/gLeDobwmJUdeGw0HATCxfu XNw7h1siT4QISc4fLGpKfKAE4bafv6xvAfzGesPqtZVI5/6whYmVZR18yAWbH+bjRHWj UExA2yk0Nd+KANknhb8RcgR6F59bxZHyeljUq9s1E2gTr4+vor7ejW7njkl0OzJMVkjs 2q0OK5nMtWHGglspmGRL4FoMLhtkD+oIdTT3w3QXIM3vcS2XXhbn9K0L/n4brvUuvzha olTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IyiAIXpi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be11si8247687plb.355.2019.03.12.10.38.42; Tue, 12 Mar 2019 10:38:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IyiAIXpi; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729172AbfCLRg3 (ORCPT + 99 others); Tue, 12 Mar 2019 13:36:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:59284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729264AbfCLRQo (ORCPT ); Tue, 12 Mar 2019 13:16:44 -0400 Received: from localhost (unknown [104.133.8.98]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BE70B217F5; Tue, 12 Mar 2019 17:16:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1552411003; bh=ghKeEAkvRomxATNUfmzL7HQ+0WHitDSNiahtHMWWKlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IyiAIXpiXofkG2EhQoU29KUzaglDMmInNIdUil9l2EJB+3FezkaqOK60q0pZU5+QT LS9Yn/0ufaGQyuYgKxwrhedT1Il8+diN8JqQzpFRHyEZQhtZjPMcyW6ueczOzegACi VZEQhpLI/H3nUHfphmUCY9hEJ5aRxWx7AUv8O9Wk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yan Fu , Stefano Garzarella , Stefan Hajnoczi , "David S. Miller" , Sasha Levin Subject: [PATCH 4.14 105/135] vsock/virtio: fix kernel panic after device hot-unplug Date: Tue, 12 Mar 2019 10:09:12 -0700 Message-Id: <20190312170350.860962497@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190312170341.127810985@linuxfoundation.org> References: <20190312170341.127810985@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 22b5c0b63f32568e130fa2df4ba23efce3eb495b ] virtio_vsock_remove() invokes the vsock_core_exit() also if there are opened sockets for the AF_VSOCK protocol family. In this way the vsock "transport" pointer is set to NULL, triggering the kernel panic at the first socket activity. This patch move the vsock_core_init()/vsock_core_exit() in the virtio_vsock respectively in module_init and module_exit functions, that cannot be invoked until there are open sockets. Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1609699 Reported-by: Yan Fu Signed-off-by: Stefano Garzarella Acked-by: Stefan Hajnoczi Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/vmw_vsock/virtio_transport.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/net/vmw_vsock/virtio_transport.c b/net/vmw_vsock/virtio_transport.c index fdb294441682..8cdf6ddec9b7 100644 --- a/net/vmw_vsock/virtio_transport.c +++ b/net/vmw_vsock/virtio_transport.c @@ -75,6 +75,9 @@ static u32 virtio_transport_get_local_cid(void) { struct virtio_vsock *vsock = virtio_vsock_get(); + if (!vsock) + return VMADDR_CID_ANY; + return vsock->guest_cid; } @@ -584,10 +587,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) virtio_vsock_update_guest_cid(vsock); - ret = vsock_core_init(&virtio_transport.transport); - if (ret < 0) - goto out_vqs; - vsock->rx_buf_nr = 0; vsock->rx_buf_max_nr = 0; atomic_set(&vsock->queued_replies, 0); @@ -618,8 +617,6 @@ static int virtio_vsock_probe(struct virtio_device *vdev) mutex_unlock(&the_virtio_vsock_mutex); return 0; -out_vqs: - vsock->vdev->config->del_vqs(vsock->vdev); out: kfree(vsock); mutex_unlock(&the_virtio_vsock_mutex); @@ -669,7 +666,6 @@ static void virtio_vsock_remove(struct virtio_device *vdev) mutex_lock(&the_virtio_vsock_mutex); the_virtio_vsock = NULL; - vsock_core_exit(); mutex_unlock(&the_virtio_vsock_mutex); vdev->config->del_vqs(vdev); @@ -702,14 +698,28 @@ static int __init virtio_vsock_init(void) virtio_vsock_workqueue = alloc_workqueue("virtio_vsock", 0, 0); if (!virtio_vsock_workqueue) return -ENOMEM; + ret = register_virtio_driver(&virtio_vsock_driver); if (ret) - destroy_workqueue(virtio_vsock_workqueue); + goto out_wq; + + ret = vsock_core_init(&virtio_transport.transport); + if (ret) + goto out_vdr; + + return 0; + +out_vdr: + unregister_virtio_driver(&virtio_vsock_driver); +out_wq: + destroy_workqueue(virtio_vsock_workqueue); return ret; + } static void __exit virtio_vsock_exit(void) { + vsock_core_exit(); unregister_virtio_driver(&virtio_vsock_driver); destroy_workqueue(virtio_vsock_workqueue); } -- 2.19.1