lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <20230118134017.c9b6e1cf0beae8e5c3bdfd8c@linux-foundation.org>
Date:   Wed, 18 Jan 2023 13:40:17 -0800
From:   Andrew Morton <akpm@...ux-foundation.org>
To:     Levi Yun <ppbuk5246@...il.com>
Cc:     linux-mm@...ck.org, linux-kernel@...r.kernel.org,
        Laurent Pinchart <laurent.pinchart@...asonboard.com>,
        Marek Szyprowski <m.szyprowski@...sung.com>,
        Joonsoo Kim <iamjoonsoo.kim@....com>,
        Minchan Kim <minchan@...nel.org>
Subject: Re: [PATCH] mm/cma: Fix potential memory loss on
 cma_declare_contiguous_nid

On Wed, 18 Jan 2023 17:05:23 +0900 Levi Yun <ppbuk5246@...il.com> wrote:

> Suppose, memblock_alloc_ranged_nid with highmem_start is success
> when cma_declare_contiguous_nid is called with !fixed
> in the system 32-bit system with PHYS_ADDR_T_64BIT enabled
> with memblock.bottom_up == false.
> 
> But, Next trial to memblock_alloc_range_nid to allocate in
> [SIZE_4G, limits) nullifies former success allocated addr and
> it retries to memblock_alloc_ragne_nid again.
> 
> In this situation, first success address area is lost.
> 
> By changing order of allocation (SIZE_4G, high_memory and base) and
> checking whether allocated prevents potential memory lost.
> 

The changelog is hard to follow.  I redid it as below - please review
and correct if needed?


From: Levi Yun <ppbuk5246@...il.com>
Subject: mm/cma: fix potential memory loss on cma_declare_contiguous_nid
Date: Wed, 18 Jan 2023 17:05:23 +0900

Suppose memblock_alloc_range_nid() with highmem_start succeeds when
cma_declare_contiguous_nid is called with !fixed on a 32-bit system with
PHYS_ADDR_T_64BIT enabled with memblock.bottom_up == false.

But the next trial to memblock_alloc_range_nid() to allocate in [SIZE_4G,
limits) nullifies former successfully allocated addr and it retries
memblock_alloc_ragne_nid().

In this situation, the first successfully allocated address area is lost.

Change the order of allocation (SIZE_4G, high_memory and base) and check
whether the allocated succeeded to prevent potential memory loss.

Link: https://lkml.kernel.org/r/20230118080523.44522-1-ppbuk5246@gmail.com
Signed-off-by: Levi Yun <ppbuk5246@...il.com>
Cc: Laurent Pinchart <laurent.pinchart@...asonboard.com>
Cc: Marek Szyprowski <m.szyprowski@...sung.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@....com>
Cc: Minchan Kim <minchan@...nel.org>
Signed-off-by: Andrew Morton <akpm@...ux-foundation.org>
---

 mm/cma.c |   24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

--- a/mm/cma.c~mm-cma-fix-potential-memory-loss-on-cma_declare_contiguous_nid
+++ a/mm/cma.c
@@ -331,18 +331,6 @@ int __init cma_declare_contiguous_nid(ph
 		phys_addr_t addr = 0;
 
 		/*
-		 * All pages in the reserved area must come from the same zone.
-		 * If the requested region crosses the low/high memory boundary,
-		 * try allocating from high memory first and fall back to low
-		 * memory in case of failure.
-		 */
-		if (base < highmem_start && limit > highmem_start) {
-			addr = memblock_alloc_range_nid(size, alignment,
-					highmem_start, limit, nid, true);
-			limit = highmem_start;
-		}
-
-		/*
 		 * If there is enough memory, try a bottom-up allocation first.
 		 * It will place the new cma area close to the start of the node
 		 * and guarantee that the compaction is moving pages out of the
@@ -359,6 +347,18 @@ int __init cma_declare_contiguous_nid(ph
 		}
 #endif
 
+		/*
+		 * All pages in the reserved area must come from the same zone.
+		 * If the requested region crosses the low/high memory boundary,
+		 * try allocating from high memory first and fall back to low
+		 * memory in case of failure.
+		 */
+		if (!addr && base < highmem_start && limit > highmem_start) {
+			addr = memblock_alloc_range_nid(size, alignment,
+					highmem_start, limit, nid, true);
+			limit = highmem_start;
+		}
+
 		if (!addr) {
 			addr = memblock_alloc_range_nid(size, alignment, base,
 					limit, nid, true);
_

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ