From patchwork Fri Dec 13 22:37:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Navid Emamdoost X-Patchwork-Id: 11291903 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 E280A14B7 for ; Fri, 13 Dec 2019 22:38:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A74C522527 for ; Fri, 13 Dec 2019 22:38:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AMkbyHim" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A74C522527 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 DCE008E0005; Fri, 13 Dec 2019 17:38:17 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D7D038E0001; Fri, 13 Dec 2019 17:38:17 -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 C93578E0005; Fri, 13 Dec 2019 17:38:17 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0182.hostedemail.com [216.40.44.182]) by kanga.kvack.org (Postfix) with ESMTP id B0C098E0001 for ; Fri, 13 Dec 2019 17:38:17 -0500 (EST) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with SMTP id 423FF4FF4 for ; Fri, 13 Dec 2019 22:38:17 +0000 (UTC) X-FDA: 76261583034.07.cork45_65677c1e4c21a X-Spam-Summary: 30,2,0,afd39666a25741f3,d41d8cd98f00b204,navid.emamdoost@gmail.com,:akpm@linux-foundation.org:kirill.shutemov@linux.intel.com:keith.busch@intel.com::linux-kernel@vger.kernel.org:emamd001@umn.edu:jhubbard@nvidia.com:navid.emamdoost@gmail.com,RULES_HIT:41:355:379:541:800:960:966:973:988:989:1260:1345:1359:1437:1534:1541:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:3138:3139:3140:3141:3142:3352:3865:3866:3868:3870:4321:4385:5007:6261:6653:7514:7875:7903:8603:9413:10010:11026:11232:11658:11914:12043:12048:12297:12438:12517:12519:12555:12679:12895:12986:13069:13311:13357:14096:14181:14384:14394:14687:14721:21080:21444:21451:21627:21666:21987:21990:30054,0,RBL:209.85.166.195:@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:1:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: cork45_65677c1e4c21a X-Filterd-Recvd-Size: 4352 Received: from mail-il1-f195.google.com (mail-il1-f195.google.com [209.85.166.195]) by imf15.hostedemail.com (Postfix) with ESMTP for ; Fri, 13 Dec 2019 22:38:16 +0000 (UTC) Received: by mail-il1-f195.google.com with SMTP id g12so769993ild.2 for ; Fri, 13 Dec 2019 14:38:16 -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:in-reply-to:references; bh=05pwc1cDq1D/DICCYWl1LBEP7b2TGkJ4T9jlAojcSw4=; b=AMkbyHim27QPrfH+SFbUq5K6UtLpL5hRLHJ2gT/tiB/okhD6H760a3eNBadZXZ3USZ 9IqwEe874ONRzJUPePaY7+ZFBY/7Jw4a8qNUz2Lwb2Cwe0AYa3Dr2ScyeuHIoT9QOopz 4WEjiIH+qRYgL3U4gHwl41xMXGF3CsjNG0ICD0D4HRgm3c9LHj2d9e0a9Oh5NzglgwDA mKC2Zxb13JloprCzr+lr9Lgtg7CSK+ywVxFJ0L0bjf9FrOr3cu6Z1k7Eg1QTc17SVaM6 CoQrQ7YCAZAomYu7mxI0jRh+fZOtxyUbc5NVxGYImZTDO09mOhcam4wxIml9YPeUX8eI ouZA== 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:in-reply-to :references; bh=05pwc1cDq1D/DICCYWl1LBEP7b2TGkJ4T9jlAojcSw4=; b=JeTN/5Lk9CzqArzDy3h2S7eFe/Gat2NUXIUlcMvfTTVpCQdl3vIuCJjIKBbTZNbqF3 VrXwZKNPVXoYSguUGuHiak0uztdgbpnpk3GXBRtx/xCCXhsg7PDXe1tagiz7UyjmuaQP T1SD+T7PVk5W0+Yqk75hyQFQNbo4LesqSr2bbJD8j6i4ii/z1DCTB3zK40tHic2RCrbQ RU/xGy1Qo97AQUX+1Sg/k4t3L5KBIFAn93NhKLGUC3xP371wLsdaAlGS1ENw/5CMHxqK +za3Nfr9OfLz/wFh2iWeCIXI8nfTGtSsASmxJOmh+vjHESUrMkxT4H6r3LpEAuVBnTUv Xq0A== X-Gm-Message-State: APjAAAXmt/rhKtlYwjx1zBln8jWEliElbRObhqedPjCG/E72QVqAPKAt mkP6mooft7Y0f9ZmOXvMI5Y= X-Google-Smtp-Source: APXvYqx0uEsIvwLyNJN7RXSIIglVZGUqy7rs3mqi+4ZkWl+6KLFw6vmUQBxc/SD9Aaiscam/6CaC1g== X-Received: by 2002:a92:9107:: with SMTP id t7mr1701040ild.51.1576276695976; Fri, 13 Dec 2019 14:38:15 -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 f7sm2396743ioo.27.2019.12.13.14.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Dec 2019 14:38:15 -0800 (PST) From: Navid Emamdoost To: Andrew Morton , "Kirill A. Shutemov" , Keith Busch , linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: emamd001@umn.edu, jhubbard@nvidia.com, Navid Emamdoost Subject: [PATCH v2] mm/gup: Fix memory leak in __gup_benchmark_ioctl Date: Fri, 13 Dec 2019 16:37:41 -0600 Message-Id: <20191213223751.4089-1-navid.emamdoost@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <9a692d27-4654-f1fc-d4c5-c6efba02c8a9@nvidia.com> References: <9a692d27-4654-f1fc-d4c5-c6efba02c8a9@nvidia.com> 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() the allocated pages should be released before returning in case of an invalid cmd. Release pages via kvfree() by goto done. Fixes: 714a3a1ebafe ("mm/gup_benchmark.c: add additional pinning methods") Signed-off-by: Navid Emamdoost Reviewed-by: Ira Weiny Reviewed-by: John Hubbard Reviewed-by: David Hildenbrand --- Changes in v2: -- added goto and ret value instead of return -1. --- mm/gup_benchmark.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/gup_benchmark.c b/mm/gup_benchmark.c index b160638f647e..b773b2568544 100644 --- a/mm/gup_benchmark.c +++ b/mm/gup_benchmark.c @@ -24,7 +24,7 @@ static int __gup_benchmark_ioctl(unsigned int cmd, { ktime_t start_time, end_time; unsigned long i, nr_pages, addr, next; - int nr; + int nr, ret = 0; struct page **pages; if (gup->size > ULONG_MAX) @@ -63,8 +63,8 @@ static int __gup_benchmark_ioctl(unsigned int cmd, NULL); break; default: - kvfree(pages); - return -1; + ret = -EINVAL; + goto done; } if (nr <= 0) @@ -85,8 +85,9 @@ static int __gup_benchmark_ioctl(unsigned int cmd, end_time = ktime_get(); gup->put_delta_usec = ktime_us_delta(end_time, start_time); +done: kvfree(pages); - return 0; + return ret; } static long gup_benchmark_ioctl(struct file *filep, unsigned int cmd,