Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1086959ybg; Wed, 29 Jul 2020 05:36:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgh7tdQFZnNrHMdMnOZ3WUu6Akr/hKEdcTPFISUjiyZObxslyxjh/XGYuQzkg9YgY8IV0j X-Received: by 2002:a17:906:6a5b:: with SMTP id n27mr11372697ejs.154.1596026213037; Wed, 29 Jul 2020 05:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596026213; cv=none; d=google.com; s=arc-20160816; b=aJiwul96tehgWR2YgOeFTHGS0TgEVZG3xKpKXqRV6Rysa2yY7b6IUMfL8tYpsXD/TV OfxPY5lH1XRjGHGklorsBIqn6wPO0AyzRurtqhzUBh9nnQd/BTVslG5vNKE1hl9bpDOk ZJeCjn0Paxn6YmTdAjVoEPbyxeUQXPKr7Txe+zjW56a9z9CgEdCbbgCv35WJl7Kh/ueV 2/Q+l5bXMXPcRT5o3XVONbGPXOQfKBQ0oDAmrOARTd5e6guob3d4s9uyKZWzZG1GNoP+ EQA1xiIfwdQ/gEF1XC+ylAIcte7rQY50cFXfrnfNkdrGo6zrYLgurlZonPgaZOfCVJz8 iS+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=ckLfjXtDlNzfBaiEh1n2WcNgMFoH6IBrBoFHbV5jBXk=; b=j86z7wzuA3Lv8LzFs1ftIykFiLFonKDsXn01DilZ6tJDUgjTW/L18q9hIBPDeypHWQ KpQEl0z27DkdshUOdkHY78FFoXEP9euYldNckWZQJt5+xcpFlSPtHLQEKf3aekP3CEvf Stp3B9i0BviZf1ubBCFNXmAGigDc9hxWBO2x1YD5YCGAYWMbU/p+dbpI8oG+lsbIDBHt UjR2lSzjrpmttCgIRtYxJKAAsxYzSSfC+yTAjMenpfoqBlEcRaZXVpDMOWnfGYisEGmt yRnIH1eA8I9KMua0MIwhyYiTm6h/DWdvUPRBB4f2CVd28U6FM8weYwAo20tt97fNkSHB P47A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fudan.edu.cn header.s=dkim header.b=fnf7yXZz; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 91si1439485edy.18.2020.07.29.05.36.29; Wed, 29 Jul 2020 05:36:53 -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=@fudan.edu.cn header.s=dkim header.b=fnf7yXZz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgG2Mdz (ORCPT + 99 others); Wed, 29 Jul 2020 08:33:55 -0400 Received: from mail.fudan.edu.cn ([202.120.224.73]:48464 "EHLO fudan.edu.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726054AbgG2Mdz (ORCPT ); Wed, 29 Jul 2020 08:33:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fudan.edu.cn; s=dkim; h=Received:Date:From:To:Cc:Subject: Message-ID:MIME-Version:Content-Type:Content-Disposition; bh=ckL fjXtDlNzfBaiEh1n2WcNgMFoH6IBrBoFHbV5jBXk=; b=fnf7yXZz1XG1VNx8A0G P4HxGvbRGReDWbincy2f3kynybLSC3IMgsbUHPjD/qfWHFxTL31NniB634/rzCCi oEJjjyakdrtR8A+77LWS4LFdp2MkciXGICA9ZFGcnRgzXTrEQ4fTEc52rD+0BW3L HPTtyfYhnRNJbCvS7krRiVQc= Received: from xin-virtual-machine (unknown [111.192.143.50]) by app2 (Coremail) with SMTP id XQUFCgDHzbmebCFfDJqTAg--.8049S3; Wed, 29 Jul 2020 20:33:35 +0800 (CST) Date: Wed, 29 Jul 2020 20:33:34 +0800 From: Xin Xiong To: Saeed Mahameed , Leon Romanovsky , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Martin KaFai Lau , Song Liu , Yonghong Song , Andrii Nakryiko , KP Singh , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Cc: Xin Xiong , Xiyu Yang , Xin Tan , yuanxzhang@fudan.edu.cn Subject: [PATCH] net/mlx5e: fix bpf_prog refcnt leaks in mlx5e_alloc_rq Message-ID: <20200729123334.GA6766@xin-virtual-machine> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-CM-TRANSID: XQUFCgDHzbmebCFfDJqTAg--.8049S3 X-Coremail-Antispam: 1UD129KBjvJXoW7AF1DCFy8JF1rJw1rGr45KFg_yoW8WF4Upr 47X3sFyrZ5ta4UJw4DAaykXa4rKan0vF1kWr1avayfZr4DAan5Ar9Ygry7uF1UGFy8Gw12 qws2kws8AFn5C3JanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUU9K14x267AKxVW5JVWrJwAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK02 1l84ACjcxK6xIIjxv20xvE14v26F1j6w1UM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r4U JVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gc CE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xv F2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r 4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwACjI8F5VA0II8E6IAqYI8I648v 4I1lFIxGxcIEc7CjxVA2Y2ka0xkIwI1lc2xSY4AK67AK6ryUMxAIw28IcxkI7VAKI48JMx C20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAF wI0_JrI_JrWlx4CE17CEb7AF67AKxVW8ZVWrXwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20x vE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4v2 0xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14 v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjfUewIDDUUUU X-CM-SenderInfo: arytiiqsuqiimz6i3vldqovvfxof0/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function invokes bpf_prog_inc(), which increases the refcount of a bpf_prog object "rq->xdp_prog" if the object isn't NULL. The refcount leak issues take place in two error handling paths. When mlx5_wq_ll_create() or mlx5_wq_cyc_create() fails, the function simply returns the error code and forgets to drop the refcount increased earlier, causing a refcount leak of "rq->xdp_prog". Fix this issue by jumping to the error handling path err_rq_wq_destroy when either function fails. Signed-off-by: Xin Xiong Signed-off-by: Xiyu Yang Signed-off-by: Xin Tan --- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index a836a02a2116..8e1b1ab416d8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -419,7 +419,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, err = mlx5_wq_ll_create(mdev, &rqp->wq, rqc_wq, &rq->mpwqe.wq, &rq->wq_ctrl); if (err) - return err; + goto err_rq_wq_destroy; rq->mpwqe.wq.db = &rq->mpwqe.wq.db[MLX5_RCV_DBR]; @@ -470,7 +470,7 @@ static int mlx5e_alloc_rq(struct mlx5e_channel *c, err = mlx5_wq_cyc_create(mdev, &rqp->wq, rqc_wq, &rq->wqe.wq, &rq->wq_ctrl); if (err) - return err; + goto err_rq_wq_destroy; rq->wqe.wq.db = &rq->wqe.wq.db[MLX5_RCV_DBR]; -- 2.25.1