From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E86CF1EA72 for ; Tue, 25 Jul 2023 10:49:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AB99C433C7; Tue, 25 Jul 2023 10:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1690282151; bh=rr+AIe3BWfMFqUL0HbmluR22ksFyRK6wqOtlacIzNgo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YMUqrjQE1r8dSEAwIwTGwAiBR0Bpes/2VgAXDBB8q6itDOnH82J/3RfWPPL/cuqfp CXcGmlRJ+KW9q2HRfmcAs1U/gHuPVZpKaak/EaayBh9WchrkHRsi2XOvu6N8VGA5R5 F7x+ILdTs24aZp7nYnu2NJhfjFQFM0SBL/CcFukI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Dan Carpenter , Pranjal Ramajor Asha Kanojiya , Jeffrey Hugo , Dafna Hirschfeld Subject: [PATCH 6.4 026/227] accel/qaic: Fix a leak in map_user_pages() Date: Tue, 25 Jul 2023 12:43:13 +0200 Message-ID: <20230725104515.891736546@linuxfoundation.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230725104514.821564989@linuxfoundation.org> References: <20230725104514.821564989@linuxfoundation.org> User-Agent: quilt/0.67 Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Dan Carpenter commit 73274c33d961f4aa0f968f763e2c9f4210b4f4a3 upstream. If get_user_pages_fast() allocates some pages but not as many as we wanted, then the current code leaks those pages. Call put_page() on the pages before returning. Fixes: 129776ac2e38 ("accel/qaic: Add control path") Signed-off-by: Dan Carpenter Reviewed-by: Pranjal Ramajor Asha Kanojiya Reviewed-by: Jeffrey Hugo Reviewed-by: Dafna Hirschfeld Cc: stable@vger.kernel.org # 6.4.x Signed-off-by: Jeffrey Hugo Link: https://patchwork.freedesktop.org/patch/msgid/ZK0Q+ZuONTsBG+1T@moroto Signed-off-by: Greg Kroah-Hartman --- drivers/accel/qaic/qaic_control.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/drivers/accel/qaic/qaic_control.c +++ b/drivers/accel/qaic/qaic_control.c @@ -418,9 +418,12 @@ static int find_and_map_user_pages(struc } ret = get_user_pages_fast(xfer_start_addr, nr_pages, 0, page_list); - if (ret < 0 || ret != nr_pages) { - ret = -EFAULT; + if (ret < 0) goto free_page_list; + if (ret != nr_pages) { + nr_pages = ret; + ret = -EFAULT; + goto put_pages; } sgt = kmalloc(sizeof(*sgt), GFP_KERNEL);