Received: by 2002:a05:6622:f08:0:0:0:0 with SMTP id l8csp4490156ivc; Tue, 3 Nov 2020 13:25:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPRqkg0yqXSAgdyiNbJgTL+eBAGm7XRAf4zZAglvTmEBrBysap08j+g/w3eX1YIInv54Ge X-Received: by 2002:a50:d805:: with SMTP id o5mr23823861edj.142.1604438726215; Tue, 03 Nov 2020 13:25:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604438726; cv=none; d=google.com; s=arc-20160816; b=gdZoWrGoSkUXOYDTVvmrZxc3Uklk9rtHAcku7RdbpkYXqn9y+U8fSzzntevuTZR0VW Br4DsLsWTouJCxnIZcEkyFa4VmuMMVb4ChQpSyJCQXPNgrKoQeOMoipbD7o4nX6+st87 yX6wrdXN/Z3GoKaNVPS4EPod3Xyd9cKN7BOOKkNbvW0cLpTD2BXGeLY2RuelY9NfoVWa ccdzUL1KF0726R71nBG2nHD1S7s+DTLcOgt6P8NgKWVmwaJK5Gr2Z9RqKI21LSZNvl76 z6LuCc4Rm+cYm3/BhLMTD9rdnU+gC16ot2H87hi+CzO/vfabGI4cfJhKGHEAFcG4CRQu lLtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Kb7Mgg3nlBJKdoDEGvadzM4H21wphOI/K7HRcv3M83U=; b=PkqpA71vlj/HXWj5rFQPqyz3x1zOOo+erjL/iV1yakSYUUA0+gcu2xmEAx0vETYiMt +1wu3gppIGYS/3v7wq254dcrhnDSiYSQuImi4vGAjuwkIMHyvOtSJnt8CIHLUMb7KROB uqA4cyQXCMTyXvluwQRb9cpKy++z+UjDmAaBukgtiAPTGIitcggeT2T95BRxTtGmQCgV WMr9xT02fayyham316r2nYmahaxG6bwCwozVBJbH34AOq5lqzSmrlnxPzIiAVcIsf+t/ 4yXmRP0qbyKkVPJk7AyZRha3uR4p//OnwcDRuHg6pfcIcwhsa5yLMyYqewy3j0zIwgQG Ak9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tp7j302U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bg3si251ejb.616.2020.11.03.13.25.03; Tue, 03 Nov 2020 13:25:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tp7j302U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388572AbgKCVWf (ORCPT + 99 others); Tue, 3 Nov 2020 16:22:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:43732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733172AbgKCVFR (ORCPT ); Tue, 3 Nov 2020 16:05:17 -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 5842B20658; Tue, 3 Nov 2020 21:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604437516; bh=XWKBGVT0fLlUqbteaHTUAI/g2Q91q7n4qRD6yK2GNdI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tp7j302UnQj3vjnjAWxdv/Xy8xOckMJ46WwwGHLUNtwftNuyH+otCZFu7KgGR8GuY 1O+3RigkxsrQftWIObVEFiw9MbQEXcEmeuH4OlL7HXJ5sI+JXpjCjyU8mDWMAY8J2b daQOdwmGHavm2iApKt8SE6KCrthztVVymTrtWxjg= 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 4.19 110/191] sgl_alloc_order: fix memory leak Date: Tue, 3 Nov 2020 21:36:42 +0100 Message-Id: <20201103203243.802362900@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203232.656475008@linuxfoundation.org> References: <20201103203232.656475008@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 60e7eca2f4bed..3b859201f84c6 100644 --- a/lib/scatterlist.c +++ b/lib/scatterlist.c @@ -506,7 +506,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; } -- 2.27.0