Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3924445imm; Mon, 15 Oct 2018 06:27:35 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ZlTpGW2z32Ku7qmw4M0pe6GKoLg6FjnMUyYKa/Q0mjUOAKeCw0basLGxyiYSyEqq5riAc X-Received: by 2002:a63:e141:: with SMTP id h1-v6mr16104701pgk.47.1539610055145; Mon, 15 Oct 2018 06:27:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539610055; cv=none; d=google.com; s=arc-20160816; b=k8DUkYT7M7t7SNO4Z/VrpxY8iywvnl7arC5aARrQZ2BO0N3b+E7nEYX80nZcPO+D/C lb8o47pnwqI69BBxBcE4CqxzCViPFoZGtsdckcaw97yxiaEEANOhbAfdNxrPQU3XuGv2 jFrXxzc98AAs/o5R2lz3edBOXv+ByPbW+Z/bPdfGWLdBPJjr+1S172aR0JmQQKvw031b vohffmwqr/MOTV7qsogD9MJuCHpkkJc+ohR1ojVLv0c4+JOe89DvTjH5EcDoJsk+sQ4g y1A2pDfZvy08xDfQgvev4MSzS0SAATpjbhWOGrnKxB+Q1a/MS2glAjxnG/txMkPiOZSX wcGw== 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 :message-id:date:subject:cc:to:from; bh=lQc2PUmNfqYC6gsd/uUYGFD+i1VCJNQAEJK9rsEf9K0=; b=Nj3hsZUDZ41mMUJRgezQ+8RGSHE9MkwYd7hmtIW1Fy9UEGP9JuHPSio4aXkZfPWJkp xREYC7hvXa4ml5S1cr3TmC7I2ofYge3ZcItSw0NGq1GeYJNBXVxKUIYZazMWAn4ETQSh LUH9CBTY1BfPQmEGlFZ+4FL3HRQRaZkDmLLoH8mNGPQv664HRZOhC24FRGbohlkdzYWR zCEIynw3qEvvtmnrLDJJ76y7RkL9KCRSekAeZ4Xy04tWMsuNQHBBYlYFnUJ9DT2iwB2w ZgArbDN47jHYwTfApAogTajkSABrLnAYYrU2wLr6dn8tCEXPbj0dgjWIm0JLnneMfP34 xHJQ== ARC-Authentication-Results: i=1; mx.google.com; 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 d28-v6si10919800pgn.203.2018.10.15.06.27.19; Mon, 15 Oct 2018 06:27:35 -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; 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 S1726562AbeJOVLA (ORCPT + 99 others); Mon, 15 Oct 2018 17:11:00 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:48545 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726422AbeJOVLA (ORCPT ); Mon, 15 Oct 2018 17:11:00 -0400 Received: from emea4-mta.ukb.novell.com ([10.120.13.87]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Mon, 15 Oct 2018 15:25:40 +0200 Received: from linux-nq5u.suse.de (nwb-a10-snat.microfocus.com [10.120.13.202]) by emea4-mta.ukb.novell.com with ESMTP (NOT encrypted); Mon, 15 Oct 2018 14:25:14 +0100 From: Vasilis Liaskovitis To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, linux-block@vger.kernel.org Cc: jgross@suse.com, boris.ostrovsky@oracle.com, roger.pau@citrix.com, konrad.wilk@oracle.com, axboe@kernel.dk Subject: [PATCH v2] xen/blkfront: avoid NULL blkfront_info dereference on device removal Date: Mon, 15 Oct 2018 15:25:08 +0200 Message-Id: <20181015132508.23293-1-vliaskovitis@suse.com> X-Mailer: git-send-email 2.19.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a block device is hot-added when we are out of grants, gnttab_grant_foreign_access fails with -ENOSPC (log message "28 granting access to ring page") in this code path: talk_to_blkback -> setup_blkring -> xenbus_grant_ring -> gnttab_grant_foreign_access and the failing path in talk_to_blkback sets the driver_data to NULL: destroy_blkring: blkif_free(info, 0); mutex_lock(&blkfront_mutex); free_info(info); mutex_unlock(&blkfront_mutex); dev_set_drvdata(&dev->dev, NULL); This results in a NULL pointer BUG when blkfront_remove and blkif_free try to access the failing device's NULL struct blkfront_info. Signed-off-by: Vasilis Liaskovitis --- drivers/block/xen-blkfront.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 429d20131c7e..8871bf4c8a2e 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -2493,6 +2493,9 @@ static int blkfront_remove(struct xenbus_device *xbdev) dev_dbg(&xbdev->dev, "%s removed", xbdev->nodename); + if (!info) + return 0; + blkif_free(info, 0); mutex_lock(&info->mutex); -- 2.19.0