From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 8E9A3C2D0A3 for ; Mon, 26 Oct 2020 23:57:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 502042151B for ; Mon, 26 Oct 2020 23:57:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756630; bh=J+Oujrui4lFnwR0Rb3yS5sD9yiaM5TCm4If9PALhwOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=H7jgcKN1eIJhPtWZ92OxCG/PLayximsd08VFzo8kAZUrrx+6M/iOqhXlm/fqmtiI7 Grm4oxywSdN2ydpPs9E/+h8oOknJ6Y+YW4N6uTE0/mUD0/fJ6s5YM66cKtSGCn8f5b TXU8bcEPN/ztV8JtvMJ7yaDJPrsbH7rsMomxkVr8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436693AbgJZX5J (ORCPT ); Mon, 26 Oct 2020 19:57:09 -0400 Received: from mail.kernel.org ([198.145.29.99]:60982 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2410557AbgJZXyu (ORCPT ); Mon, 26 Oct 2020 19:54:50 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B7108221FA; Mon, 26 Oct 2020 23:54:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756490; bh=J+Oujrui4lFnwR0Rb3yS5sD9yiaM5TCm4If9PALhwOI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b5s/N/Dh0XfcBbcze+6PhXu398qTzp1Gd5YTf3/rTldK+6WF1Y2vArqgO7XT+ls13 TNmtTeedhx6YhC4E9nopC1mxsMtRR8bmLKsAuWYaDC7qYwf0QyNWjN4EVt0QmfcD6Q v1caFKr9OjZnMCT8cUsIFhixO+y7kHPTJNxZ8FqI= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Douglas Gilbert , Bart Van Assche , Jens Axboe , Sasha Levin Subject: [PATCH AUTOSEL 5.8 131/132] sgl_alloc_order: fix memory leak Date: Mon, 26 Oct 2020 19:52:03 -0400 Message-Id: <20201026235205.1023962-131-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235205.1023962-1-sashal@kernel.org> References: <20201026235205.1023962-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore 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 5d63a8857f361..c448642e0f786 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; } -- 2.25.1