Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp7371829yba; Thu, 2 May 2019 08:45:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqzdElgCdj6rj3YDwdcUXltG44mXNMIdRhyTBHX4LBvXNq81fITkHfmg4bsB5nRjYwf8Irlh X-Received: by 2002:a63:4c26:: with SMTP id z38mr4771832pga.425.1556811938419; Thu, 02 May 2019 08:45:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556811938; cv=none; d=google.com; s=arc-20160816; b=OtPXvq1t3WjIS81suQ92H9I0YfnyLqoxoLGzCOS1OXjX/8i1rAxh8SAMMsKsrfTy7l 1q1ZUjHZqGt2J30vFdGYulUWAryHrW2rj9qjzcjcpfOKqMTEz67SQsPgXv3zQ3txgA2m /RBXn1k4MiQR6/t1kLOBjeGlLpFAFOAS6kOcW0wnCxKJP9+KeBptdaSU85zd2J4nTLTf aCJ4KKn0IpvDEJoVfQpWejWSb2HzFC+tjiwhJsCdY6tiDRoAug5dLMlSKxXVvaA4nLbC NFAFCHxhsTtCYBbrHh+WzSU4HkC9oX/K8tP5hMxXiwAoPyqg/QueFUC9fDULDM4WsNLx xtWw== 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=Kg5oviVP3hP2vFW+mMq8jUv1+qScyBooPeh6b0hOSks=; b=Y/tQ5AznYe4rjny5SN7HHW8sB7gtmn2+CpyW1v6L8/C9uZF520BNV+DsTP+Sz0sZY4 8K4NLugaD7pT8hImJU/0YB9g0CuRCvPzydm/BMCuG9PKV7cI0PnHMECOVC3sI7FuchMi AsV9+aoLqxIxX9Qybo3SgQ7+e4rNlc5pgIMkWHy831KrdalscuN0/MhJ/fIE1FiFETBM Vt/a/WaL3Oz1M0XfycOGe+98FvaSA8OhBnqEgv05L1/lsdR8Reu7o86KI5zuu0gIRNV4 8GqCPYuQ26PSWF3cvENUAff+fQEiSP9CHRmZB92KOc0StD0RxhJE4svC637eVGzVZMeu 7/7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=o97akdYx; 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 a67si46685082pla.350.2019.05.02.08.45.23; Thu, 02 May 2019 08:45:38 -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; dkim=pass header.i=@kernel.org header.s=default header.b=o97akdYx; 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 S1727877AbfEBP1B (ORCPT + 99 others); Thu, 2 May 2019 11:27:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:43694 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727105AbfEBP07 (ORCPT ); Thu, 2 May 2019 11:26:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B005C20449; Thu, 2 May 2019 15:26:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556810818; bh=FAOdV6X0lvrtwWMnvZw0fTD6ooo1Cg8DxlUZNEtRbho=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o97akdYxDtzmVR014Hi/MKd6CuqNfzPez01IlbifxkqE096/izN1RCuODzsI9KQfR wsxglsVDW3IsIm7CFY3iRvVmZwlzURzmi68bQpelvbyDKshRxUeyUl+7mnR+ctA1DU hIWGzVQC9rS//izWFDuqCi/5wivm+WtxMAtF89Io= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jiri Slaby , =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Daniel Borkmann , "Sasha Levin (Microsoft)" Subject: [PATCH 4.19 13/72] xsk: fix umem memory leak on cleanup Date: Thu, 2 May 2019 17:20:35 +0200 Message-Id: <20190502143334.454298740@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190502143333.437607839@linuxfoundation.org> References: <20190502143333.437607839@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 [ Upstream commit 044175a06706d516aa42874bb44dbbfc3c4d20eb ] When the umem is cleaned up, the task that created it might already be gone. If the task was gone, the xdp_umem_release function did not free the pages member of struct xdp_umem. It turned out that the task lookup was not needed at all; The code was a left-over when we moved from task accounting to user accounting [1]. This patch fixes the memory leak by removing the task lookup logic completely. [1] https://lore.kernel.org/netdev/20180131135356.19134-3-bjorn.topel@gmail.com/ Link: https://lore.kernel.org/netdev/c1cb2ca8-6a14-3980-8672-f3de0bb38dfd@suse.cz/ Fixes: c0c77d8fb787 ("xsk: add user memory registration support sockopt") Reported-by: Jiri Slaby Signed-off-by: Björn Töpel Signed-off-by: Daniel Borkmann Signed-off-by: Sasha Levin (Microsoft) --- include/net/xdp_sock.h | 1 - net/xdp/xdp_umem.c | 19 +------------------ 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/include/net/xdp_sock.h b/include/net/xdp_sock.h index 7161856bcf9c..c2c10cc9ffa0 100644 --- a/include/net/xdp_sock.h +++ b/include/net/xdp_sock.h @@ -34,7 +34,6 @@ struct xdp_umem { u32 headroom; u32 chunk_size_nohr; struct user_struct *user; - struct pid *pid; unsigned long address; refcount_t users; struct work_struct work; diff --git a/net/xdp/xdp_umem.c b/net/xdp/xdp_umem.c index bfe2dbea480b..a3b037fbfecd 100644 --- a/net/xdp/xdp_umem.c +++ b/net/xdp/xdp_umem.c @@ -152,9 +152,6 @@ static void xdp_umem_unaccount_pages(struct xdp_umem *umem) static void xdp_umem_release(struct xdp_umem *umem) { - struct task_struct *task; - struct mm_struct *mm; - xdp_umem_clear_dev(umem); if (umem->fq) { @@ -169,21 +166,10 @@ static void xdp_umem_release(struct xdp_umem *umem) xdp_umem_unpin_pages(umem); - task = get_pid_task(umem->pid, PIDTYPE_PID); - put_pid(umem->pid); - if (!task) - goto out; - mm = get_task_mm(task); - put_task_struct(task); - if (!mm) - goto out; - - mmput(mm); kfree(umem->pages); umem->pages = NULL; xdp_umem_unaccount_pages(umem); -out: kfree(umem); } @@ -312,7 +298,6 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) if (size_chk < 0) return -EINVAL; - umem->pid = get_task_pid(current, PIDTYPE_PID); umem->address = (unsigned long)addr; umem->props.chunk_mask = ~((u64)chunk_size - 1); umem->props.size = size; @@ -328,7 +313,7 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) err = xdp_umem_account_pages(umem); if (err) - goto out; + return err; err = xdp_umem_pin_pages(umem); if (err) @@ -347,8 +332,6 @@ static int xdp_umem_reg(struct xdp_umem *umem, struct xdp_umem_reg *mr) out_account: xdp_umem_unaccount_pages(umem); -out: - put_pid(umem->pid); return err; } -- 2.19.1