Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp684978ybv; Thu, 13 Feb 2020 07:44:29 -0800 (PST) X-Google-Smtp-Source: APXvYqyp5QewRrsTukcvxablayBOEHwv0dUMFA44GY2uaSA01orcgRly3FUNfsDoQ29ZfBTBJgUd X-Received: by 2002:aca:4ad8:: with SMTP id x207mr3174379oia.55.1581608669733; Thu, 13 Feb 2020 07:44:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608669; cv=none; d=google.com; s=arc-20160816; b=TI2g69jQZBaEyVHWJQHrQZ/tPwVK04Zv85p7hYfASXWXvVoeRjmhGdkLe/l8/b2JcB WVxMk5KyE841ydFrhr014i4pZBHbcBFqAUuQb+REBozrMMEgqKjrDzGpuK62s2ropfgi P+K7xeF7QuoaxWJxVLHGw6LXELvp60zo8hlWX7fsBCcom7jLCMiOQkDe7kG+Lac3M8Qt +kSWOMmJg7X+elaQZWVrwEvqDNXGEQm+lt8Mf9FrMnNjX7R3vPUUM3U8VZF2chEKVLHq QWo4moKgqBcDLz5IGh0PDeawElCFNsKlL3zM2X89PKBm0KFm+151hAnMB/zr4uNyoGU7 6l/g== 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=NekXMhKTGIG0BN6gmDhOLdoMag5cPGYQxfXlMzumJgo=; b=mvTHSVXSXpN3jEhIrgkN3tC61VRZrIZvpYM0pM00O+7PdzWB6LfJtl9OpdCmhNLdYs 6VkfYbIDk9cR7QRby7sP6dlCV+BQL4/xwal8IBkzymSqFA2mltG/khBlwVFNTDWE9gC9 Usd+eyC5Y4fAp3LZiJ6rLvDQpaddEZ4GxU2uaO62QfsE9K5zEOTlFu/P+SAShRf9TjoI pJC39MgAZYyUeD/E2Mm7frV2mLWWQ1J8ohYloYJ9er+uCykz4Ly7mCKYmDErl5sMpoAU jIBiiRyT/D1Le4wUIRTuK0uD8vwit2tmRU7CBzlQj4Zstq28dknZaOmhZhVRRM4ljm7t 9UAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=n1beVZ+f; 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 f187si1314513oia.218.2020.02.13.07.44.16; Thu, 13 Feb 2020 07:44:29 -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=n1beVZ+f; 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 S2387715AbgBMPnE (ORCPT + 99 others); Thu, 13 Feb 2020 10:43:04 -0500 Received: from mail.kernel.org ([198.145.29.99]:53844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729530AbgBMP2A (ORCPT ); Thu, 13 Feb 2020 10:28:00 -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 9B39D206DB; Thu, 13 Feb 2020 15:27:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607679; bh=X/HxYEGkzOyCx1UWSmnVMY8V7OZ+LRSGbtAvaH+Zfso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n1beVZ+f0BQyJz7hTpPaTOnZTdbkozeBpxGwYMNqIzJejg8G0C5jgHiP8VU3AhsCH Tnsfo0D5YPVThX9rb771RO1upflGXYW1F3+uvdFKQw9M9/CTGnTEwYixuxMxWRnt8c 10FY+UWbQqbMwpCcwF/iALFKiPCY06DJm/KKGSKk= 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.5 011/120] RDMA/cma: Fix unbalanced cm_id reference count during address resolve Date: Thu, 13 Feb 2020 07:20:07 -0800 Message-Id: <20200213151905.332258945@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151901.039700531@linuxfoundation.org> References: <20200213151901.039700531@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 @@ -3118,6 +3118,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; @@ -3144,6 +3145,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;