Received: by 10.213.65.68 with SMTP id h4csp439231imn; Tue, 13 Mar 2018 09:05:25 -0700 (PDT) X-Google-Smtp-Source: AG47ELsqecgpoaVNODEM1cnWXCkEQcSwegc3t8aUn7oqV7doI6ZvbYAj5qqHsikTS8ieSWQ0SQ/5 X-Received: by 10.99.182.6 with SMTP id j6mr924469pgf.122.1520957125190; Tue, 13 Mar 2018 09:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520957125; cv=none; d=google.com; s=arc-20160816; b=Ra1uaikPGoZTZLIPVKO0s5Oi5I1ihQrv68wFWfgYZVAo2hufT8zG2B/HAHH/MrF9A/ aqq8TaNh1Uw59E3e9ZK98Kbg+68qJyLMHqmBSej5utDFqyjDdb9X6bCDN7mcubN5KQTv HrSuV4A/cv/97sPbO/JLI3zgxjs9dtiVKTpsqS9apzmwQg7XNZWmDzNfwJzD2JiIY4A2 1DR85nETMBT+w2n3dKUKYDc1eAarN0WMg8zBKgiWtJCNXIOddir4srpGW8hPQYaJz3Vp fJK76A3C45lfJ3qS+W/k/lDauXcr/Lu07HX6agTZswUXCJooE3GHDXZ6R6z8X+jEJwRI j4bg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Rx+ZOfbWGPWQE4HacIGogtz21AThOgPgmjNpyhrqDbI=; b=vTmTBiycmHUKf1UqJEKyLdQra1qWL2pq38EGVl/lYEfnAFyh1dyUsR/f62h0busPJ8 qrKh8Dv3+PUdkD6jC4fyQb3QrbVpmOiFtElU4zlldd/8M1NyJyvvfAz1htsKLtzBjpJn IQXvxSmc1sUBrgOk3Vg6nRgwtBaxUqVa+cvKmSWzRByPBieJaxcONzUjLyVH+7Lsxt/Y GjLuVKZ6N5iIJLPM7q7hqh9+A2ERJ3JVmXgFolfMifO0G9pAc1NpkdhjASlIgk5CngFa sN2V4L0MeV8NBDlv/91vDJHZiwbsT1YR+bslxZfO2Vg1v50zvlNFWwtL3iQ2K6ivBEYY U+EQ== ARC-Authentication-Results: i=1; mx.google.com; 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 y8-v6si281356plt.378.2018.03.13.09.05.10; Tue, 13 Mar 2018 09:05:25 -0700 (PDT) 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; 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 S934490AbeCMQCM (ORCPT + 99 others); Tue, 13 Mar 2018 12:02:12 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33904 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934350AbeCMPhQ (ORCPT ); Tue, 13 Mar 2018 11:37:16 -0400 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id B46191239; Tue, 13 Mar 2018 15:37:15 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 4.14 049/140] IB/uverbs: Improve lockdep_check Date: Tue, 13 Mar 2018 16:24:12 +0100 Message-Id: <20180313152501.583060985@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180313152458.201155692@linuxfoundation.org> References: <20180313152458.201155692@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jason Gunthorpe commit 104f268d439b3c21c83708e52946a4d8d37f3d0f upstream. This is really being used as an assert that the expected usecnt is being held and implicitly that the usecnt is valid. Rename it to assert_uverbs_usecnt and tighten the checks to only accept valid values of usecnt (eg 0 and < -1 are invalid). The tigher checkes make the assertion cover more cases and is more likely to find bugs via syzkaller/etc. Fixes: 3832125624b7 ("IB/core: Add support for idr types") Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/rdma_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/infiniband/core/rdma_core.c +++ b/drivers/infiniband/core/rdma_core.c @@ -407,13 +407,13 @@ static int __must_check remove_commit_fd return ret; } -static void lockdep_check(struct ib_uobject *uobj, bool exclusive) +static void assert_uverbs_usecnt(struct ib_uobject *uobj, bool exclusive) { #ifdef CONFIG_LOCKDEP if (exclusive) - WARN_ON(atomic_read(&uobj->usecnt) > 0); + WARN_ON(atomic_read(&uobj->usecnt) != -1); else - WARN_ON(atomic_read(&uobj->usecnt) == -1); + WARN_ON(atomic_read(&uobj->usecnt) <= 0); #endif } @@ -452,7 +452,7 @@ int __must_check rdma_remove_commit_uobj WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n"); return 0; } - lockdep_check(uobj, true); + assert_uverbs_usecnt(uobj, true); ret = _rdma_remove_commit_uobject(uobj, RDMA_REMOVE_DESTROY); up_read(&ucontext->cleanup_rwsem); @@ -482,7 +482,7 @@ int rdma_explicit_destroy(struct ib_uobj WARN(true, "ib_uverbs: Cleanup is running while removing an uobject\n"); return 0; } - lockdep_check(uobject, true); + assert_uverbs_usecnt(uobject, true); ret = uobject->type->type_class->remove_commit(uobject, RDMA_REMOVE_DESTROY); if (ret) @@ -569,7 +569,7 @@ static void lookup_put_fd_uobject(struct void rdma_lookup_put_uobject(struct ib_uobject *uobj, bool exclusive) { - lockdep_check(uobj, exclusive); + assert_uverbs_usecnt(uobj, exclusive); uobj->type->type_class->lookup_put(uobj, exclusive); /* * In order to unlock an object, either decrease its usecnt for