Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp688919ybv; Thu, 13 Feb 2020 07:48:31 -0800 (PST) X-Google-Smtp-Source: APXvYqx7IfQVE9qaFsc20dyhIRE2YEXI10kCXRLjmQODlkAQRwZfik1GIHGAnXbz7r1GIZf3Rq4o X-Received: by 2002:a9d:7851:: with SMTP id c17mr14207011otm.58.1581608911703; Thu, 13 Feb 2020 07:48:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608911; cv=none; d=google.com; s=arc-20160816; b=TxmrkrkNQ+vcg1ccBne8i0KvIFTdOyGH4GlEYqfAHvYT4LxecGl44nAj2zR3Ij9yUB 7fg3ih9Mf6n5gBxZeQWM1SRydnJD9FqDUbJ18sdHLMmNKfS339a3QK9g1sYxVT1xoQ21 A6djDPGmbLE4sX12KIxvSgKZthLo0vkvUfK+qwpKjKsYPlPAq/VCL1tFtge1EjYzRox+ 5PS85CJv+FluGusXt1yXa2XyFQYAOe5/k13nbk1080eboRI7jQsXKxuTCrbn8I1H8yYY 0rWdIwlsGfu1AfzwDU3PJft2IJ7VNxpqakw5W3OI5QsNTgYVdi79Eag/P7toBRoMh/3M rvpg== 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=TcRALJu1TSPfojoSY2lgvIgghCnBbo7ZkoQPoM0Ism0=; b=ERkkTL3986eTcteovHAKent0opivwtOE1mTmMesq8p1QkxrN2b9aGAwmpPEwk6a18R MdzW0Yd7et+ZX65cElC1X0zCcdzZvglZCM7btIb8hTRe6ljL0iYUquDES/mP7bCkO0et 0JfJx29a6quLXg+M5h0nnSIDOAGTjkQnMZqRskOPkWKLyYqtgsku4mrBzIbuAb83PCy7 pxA2+t9dBrKz1H+zeGLvi/oWZ85XZAA7VnRuriW9E+mI2zbrsESXp9ewI9MHRmafH5m8 FuVXQi+MqmAW4vNvr7ZFRoYfQ8ivNKTj3HDf+o461Rnu0BNa9rxdU9QKbGH4jQhBdq9l PRkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=zkePcH6o; 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 p186si1357999oih.172.2020.02.13.07.48.19; Thu, 13 Feb 2020 07:48:31 -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=zkePcH6o; 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 S2387682AbgBMPsN (ORCPT + 99 others); Thu, 13 Feb 2020 10:48:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:48080 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728096AbgBMP06 (ORCPT ); Thu, 13 Feb 2020 10:26:58 -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 7DD5E24676; Thu, 13 Feb 2020 15:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607617; bh=yrSeCG0uOthnJMH+3IwbUqpd3QyT4TGEU1r7Ewtx6oo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zkePcH6oYtfy0D1FDTHHzLWuR+72Zm+maQHZszpyjZJaYASKK4AUz1rltUPhtdVkV pRJfAjrQqvUKlLhckQGPwJh8fHVaVtaUDQQHZm9qCyLp6UeWIZ/sHVnAtnl2sOgB0E Znao6EuEVjLQIiKdL3THzMSCwf25lgk26CKAGifo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Parav Pandit , Leon Romanovsky , Jason Gunthorpe Subject: [PATCH 5.4 10/96] RDMA/cma: Fix unbalanced cm_id reference count during address resolve Date: Thu, 13 Feb 2020 07:20:17 -0800 Message-Id: <20200213151843.267090680@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: Parav Pandit commit b4fb4cc5ba83b20dae13cef116c33648e81d2f44 upstream. Below commit missed the AF_IB and loopback code flow in rdma_resolve_addr(). This leads to an unbalanced cm_id refcount in cma_work_handler() which puts the refcount which was not incremented prior to queuing the work. A call trace is observed with such code flow: BUG: unable to handle kernel NULL pointer dereference at (null) [] __mutex_lock_slowpath+0x166/0x1d0 [] mutex_lock+0x1f/0x2f [] cma_work_handler+0x25/0xa0 [] process_one_work+0x17f/0x440 [] worker_thread+0x126/0x3c0 Hence, hold the cm_id reference when scheduling the resolve work item. Fixes: 722c7b2bfead ("RDMA/{cma, core}: Avoid callback on rdma_addr_cancel()") Link: https://lore.kernel.org/r/20200126142652.104803-2-leon@kernel.org Signed-off-by: Parav Pandit Signed-off-by: Leon Romanovsky Reviewed-by: Jason Gunthorpe Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/core/cma.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -3091,6 +3091,7 @@ static int cma_resolve_loopback(struct r rdma_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid); rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid); + atomic_inc(&id_priv->refcount); cma_init_resolve_addr_work(work, id_priv); queue_work(cma_wq, &work->work); return 0; @@ -3117,6 +3118,7 @@ static int cma_resolve_ib_addr(struct rd rdma_addr_set_dgid(&id_priv->id.route.addr.dev_addr, (union ib_gid *) &(((struct sockaddr_ib *) &id_priv->id.route.addr.dst_addr)->sib_addr)); + atomic_inc(&id_priv->refcount); cma_init_resolve_addr_work(work, id_priv); queue_work(cma_wq, &work->work); return 0;