From patchwork Tue Nov 3 20:35:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 317141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44323C388F9 for ; Tue, 3 Nov 2020 20:56:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EC2132080D for ; Tue, 3 Nov 2020 20:56:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436981; bh=D3/AXZBIntDiR9M4rknP2TzTGA9SxfI64sk29l4o/Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=WbEn1sVvve6kICDDN/hj5AKNemMlNDoo/Fp8Hb4Dsx9ORf8udpnhTjv8SpX34JEV8 4Mq0M4HapP9G2TKFeECFI4MU2D4RzTfFOz/dX4l1qndvBrpPpFcc3xdARmm4eIPWvJ 8pYizls6A2VXaNQGgBRLtENhHXK9La3iJASzdihA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732698AbgKCU4T (ORCPT ); Tue, 3 Nov 2020 15:56:19 -0500 Received: from mail.kernel.org ([198.145.29.99]:57924 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731901AbgKCU4T (ORCPT ); Tue, 3 Nov 2020 15:56:19 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 A5E6020732; Tue, 3 Nov 2020 20:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436979; bh=D3/AXZBIntDiR9M4rknP2TzTGA9SxfI64sk29l4o/Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gx4oQUzKJQPYqzT835r4k0Px/hKJhPc68NXMJTD4R+09TTr71BlRMRecyaaA44m40 xC79XO1oc//uzssfmjJ33Sar//prVhcHxjiH0C7zILMSRN7V+MJmlT/EZU3aqk8lGs RosjzA9qPekx3WrtUnzm6n0LNWI5PVUtburSrxEY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bart Van Assche , Douglas Gilbert , Jens Axboe , Sasha Levin Subject: [PATCH 5.4 094/214] sgl_alloc_order: fix memory leak Date: Tue, 3 Nov 2020 21:35:42 +0100 Message-Id: <20201103203259.285644721@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203249.448706377@linuxfoundation.org> References: <20201103203249.448706377@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Douglas Gilbert [ Upstream commit b2a182a40278bc5849730e66bca01a762188ed86 ] sgl_alloc_order() can fail when 'length' is large on a memory constrained system. When order > 0 it will potentially be making several multi-page allocations with the later ones more likely to fail than the earlier one. So it is important that sgl_alloc_order() frees up any pages it has obtained before returning NULL. In the case when order > 0 it calls the wrong free page function and leaks. In testing the leak was sufficient to bring down my 8 GiB laptop with OOM. Reviewed-by: Bart Van Assche Signed-off-by: Douglas Gilbert Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- lib/scatterlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 5813072bc5895..29346184fcf2e 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -514,7 +514,7 @@ struct scatterlist *sgl_alloc_order(unsigned long long length, elem_len = min_t(u64, length, PAGE_SIZE << order); page = alloc_pages(gfp, order); if (!page) { - sgl_free(sgl); + sgl_free_order(sgl, order); return NULL; }