Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6867970imu; Mon, 21 Jan 2019 18:09:25 -0800 (PST) X-Google-Smtp-Source: ALg8bN5ag80u697j9PdbquLSw8fDkBjtRvkQr+uSqlBGgeoRofAwDV4RVFpAPm1GLAwlq72QefmS X-Received: by 2002:a17:902:4324:: with SMTP id i33mr31834450pld.227.1548122965364; Mon, 21 Jan 2019 18:09:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548122965; cv=none; d=google.com; s=arc-20160816; b=FW8m6t/fRiy3NfK/DDZ7jdrK1Y5jgxveTiiU8Hn37ulFAUyLe8NdYInjgSprY+fxd9 RFrGBiCDHsMJy+Ca8UU/FNI3bTgdUKyLNtsTx4PBMXEBfI/IUYRhAKWo7oDQETClraHT SaQ9maIjXOehO3g2RuWNi4WSu/whhGTCiXIAiu9wPB2DfDdNqMssR6FPewfIbF3wiMx1 AEcMg8z/YUMSvVH8xHwZeh+XSh0Ii/FVNO9G6YxEH1H6ZYv6JR+drDZ7j2F9twOiQkWi L00irBFp+awO3K8120dGH4wpk41ZrwTpIBb6qChyRSXHd1ltCDbDILbjOPX8+PjAVoHR 59RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=uOAmpQ8tpNpwSSe+DsGaIGiIc0oKaybcAwK6+WCbZcw=; b=Sqm3WJufzzekSrP0ABBeMFKiQIP9TQ7vCLSZ94NQ6gdqYPMhtqpJl5BRqDjVOtrM1w whMKGzHoNp324EQE8EVAiSuc2xgwQcjDI/bLpvEjXcxsAy73XlmKYYNYFOpFdgz9G295 E5yZiwowNMh7/exVOqiORd04Yr+T/mb0lakJSUMSmh858Hg32J6W/BIj1+2KI8KbDRCq 3AxwLKUlvFDfw29VQ4G3+Wk3HzLndRZoApPuZGw9N1wFfg8eLeBbTiCc7T42lX4bOivo W1ZXtWpZE4J5I3RrCvskJh9OEHclfHU4pbYb/jHXSVhC293QZg5BEre4rIJZ85uXc8wz uECA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=jpsaCZIA; 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 j1si13438226pff.42.2019.01.21.18.09.09; Mon, 21 Jan 2019 18:09:25 -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=jpsaCZIA; 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 S1726804AbfAVCIE (ORCPT + 99 others); Mon, 21 Jan 2019 21:08:04 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:51647 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726648AbfAVCID (ORCPT ); Mon, 21 Jan 2019 21:08:03 -0500 Received: by mail-it1-f194.google.com with SMTP id w18so19280197ite.1 for ; Mon, 21 Jan 2019 18:08:03 -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:mime-version:content-disposition :user-agent; bh=uOAmpQ8tpNpwSSe+DsGaIGiIc0oKaybcAwK6+WCbZcw=; b=jpsaCZIAqTHZdmFnwF/0lMYHzTVvGF/JksLa305TJQ6Qv8Jz4X5dK6KaDRWyXICuTw UBU6p3fIr4FfYYeikWlaH3wmbpsSTFgzJVgz9naGL/sqcniFQTST24FImgimyq58AOCK 6T87GhqF19DLUGTy9duceB549cu3mUivZQkY1U/fdlj9+F4uvLlisPd6tdiswz+c8+59 RaRvtY+VrLm9IE2kuxrfR3tkRt0BldfV9ST6/2vngPucE3B0+P22phmun6ugjJUkjM8H +UwsJ+OGGDjbbMr8wkqnL+GKssDFJXooSFhj3dSHZbJi+ZZLQWOgyyvkxDzZlVeUo0+i F9ZQ== 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:mime-version :content-disposition:user-agent; bh=uOAmpQ8tpNpwSSe+DsGaIGiIc0oKaybcAwK6+WCbZcw=; b=iPqkHcP0qo2GAM2Gpq5RPOS7wIQwV/4UoUQlmPlzmOUr+P9cdShoUZAJ/kbfYWIMwX dN1+S0N6uTEfvAtLroUsGSI2y8Pmrc8oDu93fDNjp9Hj3uqy9p7gFaFGA/JemIA1R1vv wTiRETbjlsLQyRz1ocKo+TSuWx6pYtCu7anf8KunquhBCqAzka4AYfOi/h1MpV2lPdRF mNSCOVZxXJWM+5bPzmVNWuAJYlZN3MagdtVVj9zNFPHfL8ZgP1b3cVWN2UxziTDhA1+p wcQModvvuYx1+CDOXoglQ2bSTqABhVSMmxQj/dhSAgAumMgi9kszPjVb/7ozpCKOolL3 i1Qg== X-Gm-Message-State: AHQUAubH2V3x3kr6C9AHmEwWI0ky299PweoinFTLU7YIbc23ZVcSzHL0 ivYdYOduwX7gk+La6COzY4c= X-Received: by 2002:a24:88:: with SMTP id 130mr1116696ita.92.1548122882689; Mon, 21 Jan 2019 18:08:02 -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 w24sm5912958ioc.11.2019.01.21.18.08.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 21 Jan 2019 18:08:02 -0800 (PST) Date: Mon, 21 Jan 2019 21:07:59 -0500 From: Kimberly Brown To: Michael Kelley , Long Li , Sasha Levin , Dexuan Cui , Stephen Hemminger Cc: "K. Y. Srinivasan" , Haiyang Zhang , devel@linuxdriverproject.org, linux-kernel@vger.kernel.org Subject: [PATCH] Drivers: hv: vmbus: Add mutex lock to channel show functions Message-ID: <20190122020759.GA4054@ubu-Virtual-Machine> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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 Signed-off-by: Kimberly Brown --- drivers/hv/vmbus_drv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 403fee01572c..e8189bc168da 100644 --- 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; } static const struct sysfs_ops vmbus_chan_sysfs_ops = { -- 2.17.1