Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp780022ybj; Thu, 7 May 2020 07:30:08 -0700 (PDT) X-Google-Smtp-Source: APiQypK+kHtZw1aWmsD+8DwHVtULFSzKvvplCsmIJpJfe6ErRy6N1PMMsDKA+54jT9pksi6qHEG9 X-Received: by 2002:a17:906:4ecb:: with SMTP id i11mr11918490ejv.79.1588861808548; Thu, 07 May 2020 07:30:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588861808; cv=none; d=google.com; s=arc-20160816; b=tShHTTcsMRPSEtqVQrscFkOhjZ3Q7o+MTyPVI7MEZg1/uGjovzH0AlTxeRVfjZbdlX TxllqzsI/1jR6wDrX4jaThr6qFOAFFf2Whccwe6wp6mqr+S0Rmd5xLg6dFjTAH9LyfLT HBzTGRnCyan1G3RdltQyBsx27ZdXOPNPt4V0PpLA9z754x4/71O6lnx2Ym71CRs/budQ MiVu+ru2KBGTH7nbTwgBnavOjspvREsHODgBE+/wbZYg3yVsmmbPPQXrk8jR7ii1w+ml 7r+LU+7NYmEPNGcXmwXhOd5Xy4JkiUlMPSrG5xQ31degXhxCv2d7JqGo3sLaHBKWZv6P t++w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=byUHZPHGcM5haqEOG+kuRsyQ7sh3HlZAvNYu0UZo9MU=; b=hGYuN+RGVnIYyaFcTnFBqpSkkgeur8FCAPvabh/3UAbv+zEO//I91DaJFR1fTC7jbW io2tQi7nmwTGQ+HElsf8fRXo6GeZRwQGbuf9yx2Xg3hW3kN72AfUBlTRBWuUtzOADX7p xnaXavM7S0JfTqcvBS/F9crzRPmZRTpUIK9YgovUR/Mjip8LeP59oqgBQHYxJaJVZ/VB Ey3BrD65v2u6/8SAt51V1D2XHXCU2ZF2lcuuwIz+Z3Gu/3pAE7i0hD0dLOrRaIDr3dYw nJKwWJt9hFpRX5mxMOgxzHTW5FxPE32EA5hhSj6rDVs/6/ELD4VRat7LX5iF4w5xfPnY qjcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=eNapZzGt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g26si2841029edu.55.2020.05.07.07.29.43; Thu, 07 May 2020 07:30:08 -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=pass header.i=@kernel.org header.s=default header.b=eNapZzGt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727869AbgEGO16 (ORCPT + 99 others); Thu, 7 May 2020 10:27:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:53934 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727834AbgEGO1z (ORCPT ); Thu, 7 May 2020 10:27:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4925A215A4; Thu, 7 May 2020 14:27:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861675; bh=fFjPDlSYqtZsiNtwI2hwcFmM5WH27agQGBfvGvrioZI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eNapZzGt+QBZNoGi1313IquHPl94YEhPMSm2lEZvQHTQoCrmdwJrClXb6kGdNnH6a t11m+u7DRwtMTBDoMyKouH/02WMQZoLZ7jZCn1ZF5UYA+bpMWIE2oPo8kZnzhI3MiS mlu0CDoFSTlU1INTJcREE5sAi0xB41kAma4KzC1s= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Leon Romanovsky , Jason Gunthorpe , Sasha Levin , linux-rdma@vger.kernel.org Subject: [PATCH AUTOSEL 5.6 23/50] RDMA/core: Fix race between destroy and release FD object Date: Thu, 7 May 2020 10:26:59 -0400 Message-Id: <20200507142726.25751-23-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200507142726.25751-1-sashal@kernel.org> References: <20200507142726.25751-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Leon Romanovsky [ Upstream commit f0abc761bbb9418876cc4d1ebc473e4ea6352e42 ] The call to ->lookup_put() was too early and it caused an unlock of the read/write protection of the uobject after the FD was put. This allows a race: CPU1 CPU2 rdma_lookup_put_uobject() lookup_put_fd_uobject() fput() fput() uverbs_uobject_fd_release() WARN_ON(uverbs_try_lock_object(uobj, UVERBS_LOOKUP_WRITE)); atomic_dec(usecnt) Fix the code by changing the order, first unlock and call to ->lookup_put() after that. Fixes: 3832125624b7 ("IB/core: Add support for idr types") Link: https://lore.kernel.org/r/20200423060122.6182-1-leon@kernel.org Suggested-by: Jason Gunthorpe Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/rdma_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/core/rdma_core.c b/drivers/infiniband/core/rdma_core.c index 2947f4f83561d..177333d8bcdae 100644 --- a/drivers/infiniband/core/rdma_core.c +++ b/drivers/infiniband/core/rdma_core.c @@ -678,7 +678,6 @@ void rdma_lookup_put_uobject(struct ib_uobject *uobj, enum rdma_lookup_mode mode) { assert_uverbs_usecnt(uobj, mode); - uobj->uapi_object->type_class->lookup_put(uobj, mode); /* * In order to unlock an object, either decrease its usecnt for * read access or zero it in case of exclusive access. See @@ -695,6 +694,7 @@ void rdma_lookup_put_uobject(struct ib_uobject *uobj, break; } + uobj->uapi_object->type_class->lookup_put(uobj, mode); /* Pairs with the kref obtained by type->lookup_get */ uverbs_uobject_put(uobj); } -- 2.20.1