Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp905645pxx; Tue, 27 Oct 2020 03:37:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7qg8n+SRiQ4g8AX6KVnlxmWVqYzw3mu+tDdUcRmNlp22ghWT3ZSakR+UwBZzs/4OM9T12 X-Received: by 2002:a50:d65c:: with SMTP id c28mr1431926edj.279.1603795020436; Tue, 27 Oct 2020 03:37:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603795020; cv=none; d=google.com; s=arc-20160816; b=MElMgZtCR2VlOqz9tN7EjJBKGi4xuOm5aktscUHDLLC70bNFYLPGKzR8/Kw6eZsyGW hl3V0TphclkStRLIvmmXMsTDQoOhyCPvLzcaxqbYfMH+Q1G3aNPByn4J1i3jxGDabnfo 9T0+bvOm3zwyO0tpgZyXXG0MUakRxioDmoik+xoUq1yUIDYuvS9kCx5Gf1QstcjsZjxW 8BiGYKP53Z0wF0SfN8sVL8IUTmSQzWTz/6YoDeGqwwTAjyN/zncEnaOc+c0KNaQrVYvG wnr4kZkoqagnv8RP1DoVpr2rbcmldezJzpN2mTXXMalI2N8qcKxwLMF3v1abBQSe7sjq GslA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pt44iurnFpfeIpN3QZmh1aURrv86pWq9K5vRyHN54Iw=; b=QDF4iVKkw6M6WbpifDMQ5AFVAxUwzvVnlzwpJM3I0pz37+br9FOXDkExc0lWuqQtnA qcIb/qONienIDJ+qMmDz/3UOE1xhBVkW3wTMV0SHLoVhOuLVySNy2eaPwZMqZSg2vbth /o7Gcn81nsbth3ZOaz6bMwtVVD5TNW+UlZaA6Zge8iQKBMcCRAjFyN7tgos3HVRcYnzg N4UnLjfwBSabTnjENaWWk3WL4FofyBq2apH4rSeAyjET7jysJ61TH1j+iQnlE6CcqSx0 0EAmW6nQv0QSrzvtOrZfduY9rGzioR2DCUtoo4Qc82auoxNXZECE9r22RxvmqY4XEF15 5wzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LPL1wYxd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z24si568426edl.8.2020.10.27.03.36.38; Tue, 27 Oct 2020 03:37:00 -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; dkim=pass header.i=@kernel.org header.s=default header.b=LPL1wYxd; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2410909AbgJZX7n (ORCPT + 99 others); Mon, 26 Oct 2020 19:59:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:37302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436626AbgJZX4w (ORCPT ); Mon, 26 Oct 2020 19:56:52 -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 B28BE21655; Mon, 26 Oct 2020 23:56:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603756612; bh=xJWRU/YQ82m7XTFpktBM9kIwsuIL8D4ULBwNA69rWUo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LPL1wYxda7PMMsTzuC4BXykQ98/NBw0VaW6rErYkY5HDb4GlU3xOJt3JJrIQPIWyM 4Bc8xcjoyU1+LiFjNeD+RgjXeW8f/szT8E0Q7RqjtYdl0TNLGUOC2RFrvVTfiXeikO TXx6lwQHFAAO+zhrixMPLqeejtNl7dZffSbgJgys= 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.4 79/80] sgl_alloc_order: fix memory leak Date: Mon, 26 Oct 2020 19:55:15 -0400 Message-Id: <20201026235516.1025100-79-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201026235516.1025100-1-sashal@kernel.org> References: <20201026235516.1025100-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 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; } -- 2.25.1