Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2989636yba; Mon, 22 Apr 2019 17:17:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqyk4Lg03gRgFczWefbYN1YDL9LomDCJnAbMCLS78tgqNf4iWldVSBaEpkGRbrKJ70YkrUF7 X-Received: by 2002:aa7:8494:: with SMTP id u20mr16793215pfn.76.1555978657018; Mon, 22 Apr 2019 17:17:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555978657; cv=none; d=google.com; s=arc-20160816; b=X4a/JVWYvq8nDv0SyYFCaSRXUVGi66GBNFZAXVdqkLsKA7LH0UHMuC+9lbEtwhD3zQ sBQ0rUnD+WFshEaQJcZN+EjwMVBl3c/FFpO7QfJCErIbRm+Oi7AUnmn1I8fFSq6jLPkk AXRJxn15C146IIYQ0esIeWQFCI+9ZJR39487bn/lnyb/9fYrsxP8r13/UoA4uzskSOSy Wre2W2q/XwweEWC+5WZEJQ2qo/4D/a0kPL1dqAsM7GchDeYC3AglDRHgnGFZeG+fAcVH whRhNnGTmcU9lmBfp8eUSepe7NbWvC1l0F4QUezcNQPcP4olHF40xruDCzz/lCLdYPvl hoKw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=yCm+EfFiCIkstc1HN+L2RZZ1zD8NuIk9yd6S9HiYiOY=; b=TU+rtFCwR7ceR+ws/BT0gwh3ckIOsvbgA+yioroDE/tMXZFavvzbZR+QUgNIPT4kKm 9SDD+Dw/Xi8zfJLIWuNe4OBgsCcCnpAK/mxCXRKnCE3Me4KO8Y5qOYmBTRLW0MN+mEwX TdsaU8bKFHPaqpS1kcCxatjvYaa+dQgYcP1Tas9e6u5I4dFlWjKeIjwjQBQ7Wa413c8u BSBG9oBascz14bYNLU+mRe61ChQiz5nCsxaq7ZMCIiGf59ubkfDK+7kAGJxMl2bRnA6V OZxZo5992S06meGi8EUDyIy5O/cJWw8Owxv/Xk2y7aAbDw28n0IDfDCcpT1fIr+0qPvv AblA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=MMceJbhd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p61si14857448plb.428.2019.04.22.17.17.21; Mon, 22 Apr 2019 17:17:37 -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=MMceJbhd; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732208AbfDVUEf (ORCPT + 99 others); Mon, 22 Apr 2019 16:04:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:47236 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729755AbfDVTpa (ORCPT ); Mon, 22 Apr 2019 15:45:30 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E363A218D9; Mon, 22 Apr 2019 19:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962328; bh=rF6XTEBf5a0m4ame5jPAzGC8IEM8zF6ECoNu3KnOFm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMceJbhdYZSVZnIbmzy/4y2A6aGIol2955FUa/CtRXIzxgcVSDUYiPHu0GP/fRnHt gO2NyUP0EWNAEK82TIF8yb7C3yxO+0zFA0oQpCXAO3ignmqlEwadV/wn9cynqPGiff hpaCS+ohSNe5lvBPV09dn3tId00G0d7PBu5wB2Ts= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: =?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?= , Daniel Borkmann , Sasha Levin , netdev@vger.kernel.org, xdp-newbies@vger.kernel.org, bpf@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 07/68] xsk: fix umem memory leak on cleanup Date: Mon, 22 Apr 2019 15:44:15 -0400 Message-Id: <20190422194516.11634-7-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194516.11634-1-sashal@kernel.org> References: <20190422194516.11634-1-sashal@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Björn Töpel [ 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