From patchwork Fri Nov 22 22:41:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Navid Emamdoost X-Patchwork-Id: 11258587 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 64CE91390 for ; Fri, 22 Nov 2019 23:10:55 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3109D20714 for ; Fri, 22 Nov 2019 23:10:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rLy9Nkr9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3109D20714 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2A8B16B052A; Fri, 22 Nov 2019 18:10:54 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2316D6B052B; Fri, 22 Nov 2019 18:10:54 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0F9346B052C; Fri, 22 Nov 2019 18:10:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0085.hostedemail.com [216.40.44.85]) by kanga.kvack.org (Postfix) with ESMTP id E90B06B052A for ; Fri, 22 Nov 2019 18:10:53 -0500 (EST) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 5C0738249980 for ; Fri, 22 Nov 2019 23:10:53 +0000 (UTC) X-FDA: 76185460386.18.ant41_24cf4cc76fa1a X-Spam-Summary: 2,0,0,0aec19bdfdd3b44d,d41d8cd98f00b204,navid.emamdoost@gmail.com,:akpm@linux-foundation.org::linux-kernel@vger.kernel.org:emamd001@umn.edu:navid.emamdoost@gmail.com,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1437:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3870:3871:4321:4385:5007:6119:6261:6653:7514:7903:7904:9413:10004:11026:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:12986:13069:13311:13357:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:30054,0,RBL:209.85.166.196:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: ant41_24cf4cc76fa1a X-Filterd-Recvd-Size: 3709 Received: from mail-il1-f196.google.com (mail-il1-f196.google.com [209.85.166.196]) by imf20.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 Nov 2019 23:10:52 +0000 (UTC) Received: by mail-il1-f196.google.com with SMTP id z12so8571964ilp.2 for ; Fri, 22 Nov 2019 15:10:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=DEYv92j7IemrkT72odbISRuFdrsY92708cwl4dDgtHw=; b=rLy9Nkr9porBJAHLvO9SKbOVmuXwLIiyb49wh9rmNlgufky1Gr/O/KSuWV8Cm61hky uJCCChoiAgM+WF+urKe2Bo5HAbBHsutG96qZgeL1ynWsm3XrF/4qrFMIUOlOmApMvZsz qudfdPv03yF5gniw/8947gRwyeZMutHcprPCVuAKtY0f7ytTzQPf3F6sPf1TL+zjaape yKQlRnL7eDmLHnpAzGjn+fRS2DAAmIa1yYyBS+BBg+J0DE3arx/CRlbcQjXK2G5iJX1d YjwpPQ7j27/phkJmL+6BOe/9c3RRUVBOWN1XVQGGifz02IavG7oDLundKDwzrxYB52L4 o8Ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=DEYv92j7IemrkT72odbISRuFdrsY92708cwl4dDgtHw=; b=QY4mJKjhCf8DqI6yGsPcvlXw6ouJmlRYnENw06u5aBxKkmspcfJ7+EuyaKcVIVjjTq ZyR4zgRnEgYNAU7QD2z++58ax3cT4MM0Kx/GtTCBKupTg4bRTeP+6AOs6Grsln3d4vq5 IcbIDoNfZu5pA4S6z72UhwTx7iSS1u5bJ/TgPFMBvcKSrOs20tDIn7/E9kFloU9u6gDg 74ZHiEFsoUcnhPGXU3+7mIaBgs4I6XoKiBb70whuf52Otz6SKfU30QlkToixgpZRJNLi CUdHd6o2B0dq8IbqnraHdZ4kluD2biHxdTjcjnHf5g7RRcwfnTsEdH2MQXS2B1ZP0GKr 4WKg== X-Gm-Message-State: APjAAAU3bxWuVJmRrZfIyDgSC/Q2ZvRQ4gDinVoToOsJsRDgRwqiGNfv o24hncLlPUa86zLqGy58cNY= X-Google-Smtp-Source: APXvYqxy4HsiYhun3maar2NcfeaqQIbkLoH0vMv1kZl7c94h7A0UODraIdyb32xMmBT1uAnO0Du7NA== X-Received: by 2002:a92:8ccc:: with SMTP id s73mr19391625ill.86.1574464252041; Fri, 22 Nov 2019 15:10:52 -0800 (PST) Received: from cs-dulles.cs.umn.edu (cs-dulles.cs.umn.edu. [128.101.35.54]) by smtp.googlemail.com with ESMTPSA id a23sm2155846ill.83.2019.11.22.15.10.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2019 15:10:51 -0800 (PST) From: Navid Emamdoost To: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: emamd001@umn.edu, Navid Emamdoost Subject: [PATCH] mm/gup: Fix memory leaks in __gup_benchmark_ioctl Date: Fri, 22 Nov 2019 16:41:15 -0600 Message-Id: <20191122224117.2372-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In the implementation of __gup_benchmark_ioctl() memory is leaked if the passed cmd is invalid. Release pages before returning -1. Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") Signed-off-by: Navid Emamdoost Reviewed-by: David Hildenbrand --- mm/gup_benchmark.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index 7dd602d7f8db..33ede5727523 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -23,7 +23,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, struct gup_benchmark *gup) { ktime_t start_time, end_time; - unsigned long i, nr_pages, addr, next; + unsigned long i, j, nr_pages, addr, next; int nr; struct page **pages; @@ -63,6 +63,12 @@ static int __gup_benchmark_ioctl(unsigned int cmd, NULL); break; default: + for (j = 0; j < i; j++) { + if (!pages[j]) + break; + put_page(pages[j]); + } + kvfree(pages); return -1; }