Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1867775ybz; Thu, 23 Apr 2020 07:25:05 -0700 (PDT) X-Google-Smtp-Source: APiQypIQKt48CCUTckw7K7qMKnZlH3AU7swmVbWRPkSQRLooX5y1fzkgBm5xMFQrff75HBT+j0KM X-Received: by 2002:a17:907:2645:: with SMTP id ar5mr2907962ejc.75.1587651905548; Thu, 23 Apr 2020 07:25:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587651905; cv=none; d=google.com; s=arc-20160816; b=QuiUSoYgyC4XVZh1WbAKVn27dEffZIB5zkWJzKJYJyH43TKHrdgrLGoFr+sNkLHI8F 0pLyoiE9ioiU/GiZTMzjMzFhJSFynPnbPEd2IhbtkDTw9mLfsGM7rAbmXYNSwLG+ILRL 0S8+HKnzx5tjFcGlg35xdziraESCuedCcrLcjd0TYbDIo7lvQXJ2HZfc+OpwVWHCR7TK Fjl0niejgF50TYG/tlDYhB6dvIec4N9ZSyT4hyuYFRqA5RpI9JWUtCNP2AF88LHq8GFp co5BdhuHD4CDSAM8h64+qIDlA8wsTwvz6i0SqH+uCLMbUeJxR/GBZK9Bc/Nh5dgcr5Le 4LEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=F6RH6jVuqtLpOUJiHYNSU4twCT8kCbptB6JR+OvixTE=; b=SlBBCkIrUkoB3WLjFpNMKcyAMXhpFWaFiJNd3+4sJnhyIPwSbR2CzjfBMi2U/SkLR4 Okk1uMD4OmAbwTVbcbDrG8iwhXbqFUXJ7RoaCTi2pCX76vXvp4PQxfz3i43n/wlS+u6R XOXKBvRKJMOOOcJy/Iloh7LsCqh9SP7ahTck4MoSmrx18wo9a8lpMeh3sowal2IYUd3o PR904mx6Pu5xGdpEJwDzoMraLEciLo8Xz+XB1XNfRDYqygnCQqfLc1Q0W38GyFCySpP7 ihzrAFA6dWASX+/67rsbe9oCLIerPxeRwSZZmfGiOQ02LrPe0DomEjmOk8WNq5smare1 PhJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=swS5ZZWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si1205351eje.262.2020.04.23.07.24.41; Thu, 23 Apr 2020 07:25:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=swS5ZZWP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728204AbgDWONp (ORCPT + 99 others); Thu, 23 Apr 2020 10:13:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726450AbgDWONo (ORCPT ); Thu, 23 Apr 2020 10:13:44 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3E20C08E934; Thu, 23 Apr 2020 07:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=F6RH6jVuqtLpOUJiHYNSU4twCT8kCbptB6JR+OvixTE=; b=swS5ZZWPVv2ZNdoDtEloS7FPCQ 9VkH59EYRVFIGHIQ09n/4DelunQqbADmE9Evrr/bW9PmjLiilFLbtcfkK7SlwD1TNafToBkXgOj05 IRTrRzfdX1SfmG7lnggi89FfUNGkWhiBdYTuBTi0rYtmeXBHsS6zpMdgCi+qzCXZjNNv9n4pXcR/8 l4vlwVRO7bAa2EKKMjjzCQPliiKoZivwbxj//NA3ToOeg8WNIqwi9m0E0pyv7peSyw5kM0s3Pz9nn pzCP9kKWcCGw/lOQsT4dl49x6yAAwbnlgvfdIlBaA1CcWthIuB0nNxkXspepp69INe8Yrv3AaR68K wsmwjKVA==; Received: from hch by bombadil.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jRcbi-0002wR-FU; Thu, 23 Apr 2020 14:13:38 +0000 Date: Thu, 23 Apr 2020 07:13:38 -0700 From: Christoph Hellwig To: Stefan Hajnoczi Cc: virtualization@lists.linux-foundation.org, Jens Axboe , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Jason Wang , "Michael S. Tsirkin" , Lance Digby Subject: Re: [PATCH] virtio-blk: handle block_device_operations callbacks after hot unplug Message-ID: <20200423141338.GA29646@infradead.org> References: <20200423123717.139141-1-stefanha@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200423123717.139141-1-stefanha@redhat.com> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 23, 2020 at 01:37:17PM +0100, Stefan Hajnoczi wrote: > A virtio_blk block device can still be referenced after hot unplug by > userspace processes that hold the file descriptor. In this case > virtblk_getgeo() can be invoked after virtblk_remove() was called. For > example, a program that has /dev/vdb open can call ioctl(HDIO_GETGEO) > after hot unplug. > > Fix this by clearing vblk->disk->private_data and checking that the > virtio_blk driver instance is still around in virtblk_getgeo(). > > Note that the virtblk_getgeo() function itself is guaranteed to remain > in memory after hot unplug because the virtio_blk module refcount is > still held while a block device reference exists. > > Originally-by: Lance Digby > Signed-off-by: Stefan Hajnoczi > --- > drivers/block/virtio_blk.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c > index 93468b7c6701..b50cdf37a6f7 100644 > --- a/drivers/block/virtio_blk.c > +++ b/drivers/block/virtio_blk.c > @@ -300,6 +300,10 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) > { > struct virtio_blk *vblk = bd->bd_disk->private_data; > > + /* Driver instance has been removed */ > + if (!vblk) > + return -ENOTTY; If this ever hits you have a nasty race condition and this is not going to fix it, as it could be removed just after this check as well.