Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp678799ybv; Thu, 13 Feb 2020 07:38:07 -0800 (PST) X-Google-Smtp-Source: APXvYqxhb4l3a62WG4u3+o0GaJKBBLdyy3Jj2v0cn7tmBPVssAzawHGog2NDNRSqED1cNMca1C/t X-Received: by 2002:a05:6830:22e2:: with SMTP id t2mr14150063otc.129.1581608287229; Thu, 13 Feb 2020 07:38:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608287; cv=none; d=google.com; s=arc-20160816; b=Sw/pORKWZ7WQ7zQ/Z48d8O06/NjziGsuu2hxkgNPb3nv1UsYWy7dBH/un1qVTo3zVL 6UprjOTi65VUk6KpaXrqbbeJ0G4ZYQVUGL84XwyKi380pWpvfHqTjtSSAZPbu+g6aIl5 PnsG1dqe5sYE68F2aUyOBUMNJHukFefKZDWIgYXn+NlS6MYbVtH3UIhKHe98Pj5PowwN EPhDuKh07QuxoD1hRpbrXJurQHWMTxYieBEMD7UC3pbEer4BDLsqFiixsaDiOQlPFTh4 2ZdpGthFGrynAzjgCz/kDmoZn4AwcziWKoBbMu9l2T7ywSr8j6T8XFW/OXik1cZKDkvs 2/wA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZJ6cOkhIlPHHtXvjU0qsTBXeBvYQH0kEzydCuVoGbCg=; b=PYNgXaCxRFc/g+8pt/t1BQJpnDA9prkNR3DHRihVjFtG9zNgc8nD7e1ugD8nkjpojo nMLTF+zMA+N0lhV8M4vqFfR2Tv4uZA8oxwmRlLm5D2OHqqf+CI7LjCvHzouIcZst52TH 79OQJMKgut6tV/qrTimwsGHe1yM2ku51eBYDu4SKlTqH2UQEVkAVv1KfkIdmR09Mu77C gKrZTSYcVzPnEGlNNQA0t7tVpw9jx0+43DkZZ+j5hOQqHHS0PY2De9TXXWZbp+BlYdwJ SU0WJYxGWNoM+ELf5KMX9NZUBDRZrM7Wf+y48MzJeFGbIp2aLXGuosJsPg2AKLEnrqnM 76vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=a3Mu+nMy; 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 64si1247686otx.50.2020.02.13.07.37.54; Thu, 13 Feb 2020 07:38:07 -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=@kernel.org header.s=default header.b=a3Mu+nMy; 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 S2387785AbgBMPaL (ORCPT + 99 others); Thu, 13 Feb 2020 10:30:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:48786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728933AbgBMP1H (ORCPT ); Thu, 13 Feb 2020 10:27:07 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BCD26206DB; Thu, 13 Feb 2020 15:27:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607625; bh=BJPUC+Pua1rzB3+wAh4ZHva9Wdewqir9ahqmes+T8KA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=a3Mu+nMyTUVt/9l9I6t7CeYHhG7iNcvrxwCzPsZk+Jczh7wmIU1G9zmtxqSBUb8+1 kK6fgQCWyp4Xv87bqbaT7pRal/r1CPIANH7IBk1yq0xy/zthmleqNg5/LySDjX+gdq vAelUMOrK/Gty+aAngQ4J5pWPzOuwA8DDY8+XgOQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yishai Hadas , =?UTF-8?q?H=C3=A5kon=20Bugge?= , Jason Gunthorpe Subject: [PATCH 5.4 08/96] RDMA/core: Fix locking in ib_uverbs_event_read Date: Thu, 13 Feb 2020 07:20:15 -0800 Message-Id: <20200213151842.427279455@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151839.156309910@linuxfoundation.org> References: <20200213151839.156309910@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe commit 14e23bd6d22123f6f3b2747701fa6cd4c6d05873 upstream. This should not be using ib_dev to test for disassociation, during disassociation is_closed is set under lock and the waitq is triggered. Instead check is_closed and be sure to re-obtain the lock to test the value after the wait_event returns. Fixes: 036b10635739 ("IB/uverbs: Enable device removal when there are active user space applications") Link: https://lore.kernel.org/r/1578504126-9400-12-git-send-email-yishaih@mellanox.com Signed-off-by: Yishai Hadas Reviewed-by: HÃ¥kon Bugge Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/uverbs_main.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) --- a/drivers/infiniband/core/uverbs_main.c +++ b/drivers/infiniband/core/uverbs_main.c @@ -220,7 +220,6 @@ void ib_uverbs_release_file(struct kref } static ssize_t ib_uverbs_event_read(struct ib_uverbs_event_queue *ev_queue, - struct ib_uverbs_file *uverbs_file, struct file *filp, char __user *buf, size_t count, loff_t *pos, size_t eventsz) @@ -238,19 +237,16 @@ static ssize_t ib_uverbs_event_read(stru if (wait_event_interruptible(ev_queue->poll_wait, (!list_empty(&ev_queue->event_list) || - /* The barriers built into wait_event_interruptible() - * and wake_up() guarentee this will see the null set - * without using RCU - */ - !uverbs_file->device->ib_dev))) + ev_queue->is_closed))) return -ERESTARTSYS; + spin_lock_irq(&ev_queue->lock); + /* If device was disassociated and no event exists set an error */ - if (list_empty(&ev_queue->event_list) && - !uverbs_file->device->ib_dev) + if (list_empty(&ev_queue->event_list) && ev_queue->is_closed) { + spin_unlock_irq(&ev_queue->lock); return -EIO; - - spin_lock_irq(&ev_queue->lock); + } } event = list_entry(ev_queue->event_list.next, struct ib_uverbs_event, list); @@ -285,8 +281,7 @@ static ssize_t ib_uverbs_async_event_rea { struct ib_uverbs_async_event_file *file = filp->private_data; - return ib_uverbs_event_read(&file->ev_queue, file->uverbs_file, filp, - buf, count, pos, + return ib_uverbs_event_read(&file->ev_queue, filp, buf, count, pos, sizeof(struct ib_uverbs_async_event_desc)); } @@ -296,9 +291,8 @@ static ssize_t ib_uverbs_comp_event_read struct ib_uverbs_completion_event_file *comp_ev_file = filp->private_data; - return ib_uverbs_event_read(&comp_ev_file->ev_queue, - comp_ev_file->uobj.ufile, filp, - buf, count, pos, + return ib_uverbs_event_read(&comp_ev_file->ev_queue, filp, buf, count, + pos, sizeof(struct ib_uverbs_comp_event_desc)); } @@ -321,7 +315,9 @@ static __poll_t ib_uverbs_event_poll(str static __poll_t ib_uverbs_async_event_poll(struct file *filp, struct poll_table_struct *wait) { - return ib_uverbs_event_poll(filp->private_data, filp, wait); + struct ib_uverbs_async_event_file *file = filp->private_data; + + return ib_uverbs_event_poll(&file->ev_queue, filp, wait); } static __poll_t ib_uverbs_comp_event_poll(struct file *filp, @@ -335,9 +331,9 @@ static __poll_t ib_uverbs_comp_event_pol static int ib_uverbs_async_event_fasync(int fd, struct file *filp, int on) { - struct ib_uverbs_event_queue *ev_queue = filp->private_data; + struct ib_uverbs_async_event_file *file = filp->private_data; - return fasync_helper(fd, filp, on, &ev_queue->async_queue); + return fasync_helper(fd, filp, on, &file->ev_queue.async_queue); } static int ib_uverbs_comp_event_fasync(int fd, struct file *filp, int on)