Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7049769imu; Mon, 21 Jan 2019 22:44:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN5D3UwIWDWamSA14y0Ja5h1qhUMwt+GpPNaschNgBjqK1QEOuYDGFo5JyP+8iPrImosTQ4t X-Received: by 2002:a17:902:2a66:: with SMTP id i93mr32438921plb.113.1548139492759; Mon, 21 Jan 2019 22:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548139492; cv=none; d=google.com; s=arc-20160816; b=RZpu6N/K4GstoQMQLSIXEvC6kj9RsiWpfppL7D0FYiFGZkvnkJZtbwgvLBQzqcVBx1 78Xb8B7Pu5Awl8axqmvWCnAW+IfRkuZMXtZTAGiuH63+PQ9SCBoy6JRauPPPSMppyBpp 4jWG/O2KEc5NkOoSLAtiyEfyhfWbZhaRaQGa77301cmrmR9LutjutUMRC6yVytpoPT2J 7gfMuf9UR3Ix9lvv/uxv8GtuqvzTLSwZ7WPlCArLQu4zntSZygJfZJNSwBcTKLnf3tEr MqIRrBfu9Qre77TBvi8nzgCSOOYPeN+ukZCixR84ll2THrGKoYSnmm4evNyFVbjIXeE6 +kRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ndWGJy7fWM7SEDYQT9UtimesU13A7WSjjIXUhm+p4kw=; b=xhf5uFQOp6s1pPw0akYpA3X2H8Zh+p/YbGSaakCfhilhGBTxUJiQO5AiCIm3rNQ/mR 7Yo3rk0SzqsSNfXxBTThjvZJY9LaUdLkuDYt6FPkn0ZYZbkWHMr9Qg3rvbOeL9O6AS6X eVWuJKxLILOCz5uZuZgCfMh0t+EZbGSi/NelptTyuwYR7HJrXAe8iGd5ihz+VQCjdjgm XrcFEEgUQYnaFXAWIsV2uu5QubLPQfGk8/qUS71rvdWvIrIEdvq8IDJJ/NOpR/r23TR+ M40VI0i+Bo2zaC7MYLduJCdOUZLkmC8jHHNb5IrupEjas91KHjnZxrNJ5VHrebWa1TdI /YJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HMXBbatg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i6si6041308pgq.207.2019.01.21.22.44.37; Mon, 21 Jan 2019 22:44:52 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=HMXBbatg; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727036AbfAVGmv (ORCPT + 99 others); Tue, 22 Jan 2019 01:42:51 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:36121 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726127AbfAVGmu (ORCPT ); Tue, 22 Jan 2019 01:42:50 -0500 Received: by mail-it1-f193.google.com with SMTP id c9so18696196itj.1 for ; Mon, 21 Jan 2019 22:42:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=ndWGJy7fWM7SEDYQT9UtimesU13A7WSjjIXUhm+p4kw=; b=HMXBbatgpTHWNYlUjPDxEbtCJN2vqrNWbWG5lSa+uPssbhwYP+3zlxGkV6kN0FQ4Mr t3uM4tILFgVhtzFna1nVaZGdb+XWtEiMQZn3sv3/OD1061pOZXvhL7dO3DmVtbyhAaB4 YSgxiKaytlowdZ7+YBW0i549c083TaPHaUQdYKMLWGVp6aVm+09K5QrBCIBT1sbNfE5k MdTYTqRnSxr8ZV47Exf+kFJg15QEVI0dYOwk24MM8BAvMCacnkll1qL0C3O7R6myzyYr R0zfiMQFBdWRiIloPjbBmXsHhbw4jM7n9ZrDbOmIwPNUjPp1eAwn4Xtl6GmAY9HNwA+G BQ6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=ndWGJy7fWM7SEDYQT9UtimesU13A7WSjjIXUhm+p4kw=; b=JleJB/T1KC9Kbg+AHOErG5KhRtcjk4R36EgCh3SX9b+75PhVtr/VXjGWxGKNLupbbX WRyjR70OyboUTdN0G4CDBlNltHXOHQsPcezPrBjISsW9JXhKd5PfFlaI6DIK3hk5+BVw ITGe/UsRRCmq0jN5p9unmm5QE7tb5xV85nkta6igQaBZWpXKEK9ysDE2OAGvRn/cXQpn jF/vDsV+LfXT8LVlBWlJE9HOKK56mS/4Z5SPx0FDTf9YJFtnbAfNf2Zg5uHO0KsT4l4H anHpDqdiiQB4irMJ27iItTPwJ4G0e57maLx+yI/H6kAG3IUlcu2/H1w+JElyi0Y94S2w Badg== X-Gm-Message-State: AJcUukdK2zqRV6TjmzTtlq0ZmU2oIM3mI5OUErvhKt+amNzyyuHlVX3A 8MXz/sQNgriqrG9Mnco/oa8= X-Received: by 2002:a24:e302:: with SMTP id d2mr1432723ith.155.1548139369635; Mon, 21 Jan 2019 22:42:49 -0800 (PST) Received: from ubu-Virtual-Machine (66-188-57-61.dhcp.bycy.mi.charter.com. [66.188.57.61]) by smtp.gmail.com with ESMTPSA id t7sm5790313iom.27.2019.01.21.22.42.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 22:42:49 -0800 (PST) Date: Tue, 22 Jan 2019 01:42:46 -0500 From: Kimberly Brown To: Dexuan Cui Cc: Michael Kelley , Long Li , Sasha Levin , Stephen Hemminger , KY Srinivasan , Haiyang Zhang , "devel@linuxdriverproject.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] Drivers: hv: vmbus: Add mutex lock to channel show functions Message-ID: <20190122064246.GA28613@ubu-Virtual-Machine> References: <20190122020759.GA4054@ubu-Virtual-Machine> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 22, 2019 at 03:46:48AM +0000, Dexuan Cui wrote: > > From: Kimberly Brown > > Sent: Monday, January 21, 2019 6:08 PM > > Subject: [PATCH] Drivers: hv: vmbus: Add mutex lock to channel show functions > > > > The channel level "_show" functions are vulnerable to race conditions. > > Add a mutex lock and unlock around the call to the channel level "_show" > > functions in vmbus_chan_attr_show(). > > > > This problem was discussed here: > > https://lkml.org/lkml/2018/10/18/830 > > > > --- a/drivers/hv/vmbus_drv.c > > +++ b/drivers/hv/vmbus_drv.c > > @@ -1414,6 +1414,7 @@ static ssize_t vmbus_chan_attr_show(struct kobject > > *kobj, > > = container_of(attr, struct vmbus_chan_attribute, attr); > > const struct vmbus_channel *chan > > = container_of(kobj, struct vmbus_channel, kobj); > > + ssize_t ret; > > > > if (!attribute->show) > > return -EIO; > > @@ -1421,7 +1422,10 @@ static ssize_t vmbus_chan_attr_show(struct > > kobject *kobj, > > if (chan->state != CHANNEL_OPENED_STATE) > > return -EINVAL; > > > > - return attribute->show(chan, buf); > > + mutex_lock(&vmbus_connection.channel_mutex); > > + ret = attribute->show(chan, buf); > > + mutex_unlock(&vmbus_connection.channel_mutex); > > + return ret; > > } > > It looks this patch is already able to fix the original issue: > 6712cc9c2211 ("vmbus: don't return values for uninitalized channels"), > as chan->state can't be CHANNEL_OPENED_STATE when > channel->ringbuffer_page is not set up yet, or has been freed. > > Thanks, > -- Dexuan I think that patch 6712cc9c2211 fixes the problem when the channel is not set up yet, but it doesn't fix the problem when the channel is being closed. The channel could be freed after the check that "chan->state" is CHANNEL_OPENED_STATE, while the "attribute->show()" function is running. Actually, there should be checks that "chan" is not null and that "chan->state" is CHANNEL_OPENED_STATE within the locked section. I'll need to fix that.