From patchwork Thu May 4 12:23:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitaly Kuznetsov X-Patchwork-Id: 758552 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wJZ1l6q1yz9s2P for ; Thu, 4 May 2017 22:23:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750960AbdEDMXL (ORCPT ); Thu, 4 May 2017 08:23:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34690 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750710AbdEDMXH (ORCPT ); Thu, 4 May 2017 08:23:07 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4102B80F7C; Thu, 4 May 2017 12:23:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 4102B80F7C Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=vkuznets@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 4102B80F7C Received: from vitty.brq.redhat.com (vitty.brq.redhat.com [10.34.26.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id E175617963; Thu, 4 May 2017 12:23:05 +0000 (UTC) From: Vitaly Kuznetsov To: xen-devel@lists.xenproject.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Boris Ostrovsky , Juergen Gross Subject: [PATCH] xen-netfront: avoid crashing on resume after a failure in talk_to_netback() Date: Thu, 4 May 2017 14:23:04 +0200 Message-Id: <20170504122304.11735-1-vkuznets@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 04 May 2017 12:23:07 +0000 (UTC) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Unavoidable crashes in netfront_resume() and netback_changed() after a previous fail in talk_to_netback() (e.g. when we fail to read MAC from xenstore) were discovered. The failure path in talk_to_netback() does unregister/free for netdev but we don't reset drvdata and we try accessing it again after resume. Reset drvdata in netback_changed() the same way we reset it in netfront_probe() and check for NULL in both netfront_resume() and netback_changed() to properly handle the situation. Signed-off-by: Vitaly Kuznetsov --- I apologize for sending this during the merge window, I'm not sure if this needs to go through xen or netdev tree. I think the fix is simple enough and it would make sense to squeeze it in 4.12 if possible. Thanks. --- drivers/net/xen-netfront.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c index 6ffc482..92f746c 100644 --- a/drivers/net/xen-netfront.c +++ b/drivers/net/xen-netfront.c @@ -1426,6 +1426,9 @@ static int netfront_resume(struct xenbus_device *dev) { struct netfront_info *info = dev_get_drvdata(&dev->dev); + if (!info) + return 0; + dev_dbg(&dev->dev, "%s\n", dev->nodename); xennet_disconnect_backend(info); @@ -1936,6 +1939,7 @@ static int talk_to_netback(struct xenbus_device *dev, out: unregister_netdev(info->netdev); xennet_free_netdev(info->netdev); + dev_set_drvdata(&dev->dev, NULL); return err; } @@ -1997,7 +2001,12 @@ static void netback_changed(struct xenbus_device *dev, enum xenbus_state backend_state) { struct netfront_info *np = dev_get_drvdata(&dev->dev); - struct net_device *netdev = np->netdev; + struct net_device *netdev; + + if (!np) + return; + + netdev = np->netdev; dev_dbg(&dev->dev, "%s\n", xenbus_strstate(backend_state));