Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4634334pxj; Wed, 12 May 2021 09:42:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7KUHBZ6WfLFCGd6j3AIysY8J/f8TwDmq0t0iFjPbhO8SnEwqcJnPQLrnmYsK19tb0U7VA X-Received: by 2002:aca:4ec7:: with SMTP id c190mr8355792oib.32.1620837738841; Wed, 12 May 2021 09:42:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837738; cv=none; d=google.com; s=arc-20160816; b=loUAHdnPlvZZtFMuE4KDqM2YroTb1I7x+3noK2d/x7yQIrTO//dQyBrx1Jc+U+SkSr 5Grrf5Rjrd7QC8MmeWJDMNXjSWNgGUtdM78hHyYOw9Jl2e8w5FZuE86CVKEJC9YGlMr+ x10pl74JVKxgHLI6y6KMCazRD8oggYGo7dGLQvsc8JCBMkSA6AZNVs/xsRPZS9zehuW6 +yPRC/5nX5y8zp+jiqwnMpo1V8iC+I8xi3NJar8jDSqMKhL6Eue16ZXJx9G3EeMTjm3u TtDq7HfJsybRWnBPFpCllMTD38xeSH8G3f+NtmFDKr21xEPQvPjKZsDYBAy/vXCXqYIB 44MQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZYqR77l/1/YHrQ4dz5cJ6U3QunCeH+n4IfrRnMb256w=; b=UiMDBv+T2t8PXG8qlwUVkfr4vNRI9mVPY/2Qn5PDpD8CRN1CsMVcP/uetLE8K6t99z POcc8GLKJzmgJBSqAeZdXYxy2Cs/xbi4LV0oXtsLEBTnBqI/GTsYTcdJ1wogFnUL/QNp +l0lqDWgMPZ8UDCH1VuQy9XreHwO2dgItUIDCFfuTMXYAowpAuDfYeUW44tJTuZsi2Pb i3BUhZDIr5WFvVLXR7ogWGI05fpxBpvHEAqeDZnClI7VKfMl8hyQIrVO6DAwuU7r878+ E23sp51TJrKTImW4otGDCDoxDImLBcwt5jxdlQdxbHde5DeEAi0qvHevQPSKXsvAKO6Q 7yVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fnvr2dXF; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s12si393456oth.118.2021.05.12.09.41.54; Wed, 12 May 2021 09:42:18 -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=@linuxfoundation.org header.s=korg header.b=Fnvr2dXF; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239415AbhELQjJ (ORCPT + 99 others); Wed, 12 May 2021 12:39:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:41108 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236843AbhELPqx (ORCPT ); Wed, 12 May 2021 11:46:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5520561C9A; Wed, 12 May 2021 15:23:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620833023; bh=BF5L2viBDwu4eSkX3VQPvuiAqggLe+C/IEo9a50M6WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fnvr2dXFeQKhOFLGRVgW5rz+bMI9da3XqOKcVIiKoYo6wZPW1jVRBhqWK1ePqFD2X LFrQEnaeGP4VhR9TJWz5biANtCNsqTCdKXSFnsqSN9TBlSbJmOmBniz/h0yCW6Blbx 09r+g1JVLN+WstXxklY60q8annkwk4RcY1PNRAYM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Shay Drory , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.10 484/530] RDMA/core: Add CM to restrack after successful attachment to a device Date: Wed, 12 May 2021 16:49:54 +0200 Message-Id: <20210512144835.666686773@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Shay Drory [ Upstream commit cb5cd0ea4eb3ce338a593a5331ddb4986ae20faa ] The device attach triggers addition of CM_ID to the restrack DB. However, when error occurs, we releasing this device, but defer CM_ID release. This causes to the situation where restrack sees CM_ID that is not valid anymore. As a solution, add the CM_ID to the resource tracking DB only after the attachment is finished. Found by syzcaller: infiniband syz0: added syz_tun rdma_rxe: ignoring netdev event = 10 for syz_tun infiniband syz0: set down infiniband syz0: ib_query_port failed (-19) restrack: ------------[ cut here ]------------ infiniband syz0: BUG: RESTRACK detected leak of resources restrack: User CM_ID object allocated by syz-executor716 is not freed restrack: ------------[ cut here ]------------ Fixes: b09c4d701220 ("RDMA/restrack: Improve readability in task name management") Link: https://lore.kernel.org/r/ab93e56ba831eac65c322b3256796fa1589ec0bb.1618753862.git.leonro@nvidia.com Signed-off-by: Shay Drory Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/cma.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index e3638f80e1d5..6af066a2c8c0 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c @@ -463,7 +463,6 @@ static void _cma_attach_to_dev(struct rdma_id_private *id_priv, id_priv->id.route.addr.dev_addr.transport = rdma_node_get_transport(cma_dev->device->node_type); list_add_tail(&id_priv->list, &cma_dev->id_list); - rdma_restrack_add(&id_priv->res); trace_cm_id_attach(id_priv, cma_dev->device); } @@ -700,6 +699,7 @@ static int cma_ib_acquire_dev(struct rdma_id_private *id_priv, mutex_lock(&lock); cma_attach_to_dev(id_priv, listen_id_priv->cma_dev); mutex_unlock(&lock); + rdma_restrack_add(&id_priv->res); return 0; } @@ -754,8 +754,10 @@ static int cma_iw_acquire_dev(struct rdma_id_private *id_priv, } out: - if (!ret) + if (!ret) { cma_attach_to_dev(id_priv, cma_dev); + rdma_restrack_add(&id_priv->res); + } mutex_unlock(&lock); return ret; @@ -816,6 +818,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv) found: cma_attach_to_dev(id_priv, cma_dev); + rdma_restrack_add(&id_priv->res); mutex_unlock(&lock); addr = (struct sockaddr_ib *)cma_src_addr(id_priv); memcpy(&addr->sib_addr, &sgid, sizeof(sgid)); @@ -2529,6 +2532,7 @@ static int cma_listen_on_dev(struct rdma_id_private *id_priv, rdma_addr_size(cma_src_addr(id_priv))); _cma_attach_to_dev(dev_id_priv, cma_dev); + rdma_restrack_add(&dev_id_priv->res); cma_id_get(id_priv); dev_id_priv->internal_id = 1; dev_id_priv->afonly = id_priv->afonly; @@ -3169,6 +3173,7 @@ port_found: ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey); id_priv->id.port_num = p; cma_attach_to_dev(id_priv, cma_dev); + rdma_restrack_add(&id_priv->res); cma_set_loopback(cma_src_addr(id_priv)); out: mutex_unlock(&lock); @@ -3201,6 +3206,7 @@ static void addr_handler(int status, struct sockaddr *src_addr, if (status) pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to acquire device. status %d\n", status); + rdma_restrack_add(&id_priv->res); } else if (status) { pr_debug_ratelimited("RDMA CM: ADDR_ERROR: failed to resolve IP. status %d\n", status); } @@ -3812,6 +3818,8 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr) if (ret) goto err2; + if (!cma_any_addr(addr)) + rdma_restrack_add(&id_priv->res); return 0; err2: if (id_priv->cma_dev) -- 2.30.2