Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp732887pxu; Thu, 15 Oct 2020 15:21:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6Hmc4ctIHA1VdsP1ua9CFpfXmcLzhE00dzExEdoj5AAEXjSHZQzpbtnnMdD4Emn3LxhMC X-Received: by 2002:aa7:de97:: with SMTP id j23mr670245edv.45.1602800462297; Thu, 15 Oct 2020 15:21:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602800462; cv=none; d=google.com; s=arc-20160816; b=fFhPaUrMIl/guwe3TS9P+5/30rQpVDrjeKCJmVXiHGIhNCDKJ0FbYHPAIwo4MtN1I8 6t3QN5o52n/J1y8svAQN2WvPnwVUTLGdxT84/NIjejHOzwDAx0reEEqyLBVfpPpTdkLn 2euQeNK0TeXzs14422OUcyZamYY2wEfrZzNqe2JPCKcr3feUBrWkOyRa35a8L6fMZSW+ uPAjeViytpYEQyPaiZopiK1J+TWGtoJmoMOu1i+rxndsFMl6J46ChZpg2tYL5LsT0fho LeLIsgTC4qUX1D0hulnyQCQN/ZjB8sfHmkSCdT0g3DtuT3Awpl2gu0c6bIn7D7hKmzCr OXzg== 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 :message-id:date:subject:cc:to:from; bh=E2BXzwhwD0A6c+2SlUHqjz8cZM4ZqLCNOzeNirX/PWk=; b=oOQvw0DfAPAfECyjOJleziUW44abjlLn4iTYBGd4Vt9dtZeaAFntZJgmlkq+TtZ6TW TyJPhSDycxbrcjdjXXZqJgTY0WDMG3K7aoPPcWREvxjmzIdreJtAooy42FU7DEWSsWgt 8pRyczsOyGZcekov0iTuBDXtSCTPGF2PuoTn5b1g85OQxi1ro6qhY3FuA04ATjfOFXTQ vwzhOLK/JX9hg4WnRU+ri1Fpo512ZX7wpTkLW2KNJiWeDRx1PCasQInJhawrO/EZ10iE J5YiwFTh7m2tq0Xp8dTh+NxcpgsNK52XS7J0BdAuW80zkzUV272nmKaASPc8YITlD3/R VhVA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s18si281034ejr.128.2020.10.15.15.20.39; Thu, 15 Oct 2020 15:21:02 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391276AbgJOS5o (ORCPT + 99 others); Thu, 15 Oct 2020 14:57:44 -0400 Received: from smtp.infotech.no ([82.134.31.41]:43262 "EHLO smtp.infotech.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391266AbgJOS5o (ORCPT ); Thu, 15 Oct 2020 14:57:44 -0400 Received: from localhost (localhost [127.0.0.1]) by smtp.infotech.no (Postfix) with ESMTP id 1F60A204238; Thu, 15 Oct 2020 20:57:41 +0200 (CEST) X-Virus-Scanned: by amavisd-new-2.6.6 (20110518) (Debian) at infotech.no Received: from smtp.infotech.no ([127.0.0.1]) by localhost (smtp.infotech.no [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j+hTVM7Rc0O6; Thu, 15 Oct 2020 20:57:39 +0200 (CEST) Received: from xtwo70.bingwo.ca (host-104-157-204-209.dyn.295.ca [104.157.204.209]) by smtp.infotech.no (Postfix) with ESMTPA id 4EC58204193; Thu, 15 Oct 2020 20:57:38 +0200 (CEST) From: Douglas Gilbert To: linux-scsi@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: martin.petersen@oracle.com, axboe@kernel.dk, bvanassche@acm.org Subject: [RESEND PATCH] sgl_alloc_order: fix memory leak Date: Thu, 15 Oct 2020 14:57:35 -0400 Message-Id: <20201015185735.5480-1-dgilbert@interlog.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- lib/scatterlist.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/scatterlist.c b/lib/scatterlist.c index 5d63a8857f36..c448642e0f78 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