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>] [day] [month] [year] [list]
Message-ID: <20210701141137epcms1p8e36d33056f5ad5351f5fe1fb35238e58@epcms1p8>
Date:   Thu, 01 Jul 2021 23:11:37 +0900
From:   권오훈 <ohoono.kwon@...sung.com>
To:     "robh+dt@...nel.org" <robh+dt@...nel.org>,
        "frowand.list@...il.com" <frowand.list@...il.com>
CC:     "lee.jones@...aro.org" <lee.jones@...aro.org>,
        권오훈 <ohoono.kwon@...sung.com>,
        "ohkwon1043@...il.com" <ohkwon1043@...il.com>,
        "devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] of: of_reserved_mem: match memblock_free with
 memblock_reserve

When __reserved_mem_init_node called from fdt_init_reserved_mem fails,
we try to undo __reserved_mem_alloc_size to prevent memory leak.
'commit d0b8ed47e83a ("of: reserved_mem: fix reserve memory leak")'

Meanwhile, __reserved_mem_alloc_size calls
early_init_dt_alloc_reserved_memory_arch to allocate memory,
which calls
1) memblock_remove when rmem is declared nomap,
2) memblock_reserve, otherwise.

static int __init early_init_dt_alloc_reserved_memory_arch(
...
	if (nomap)
		return memblock_remove(base, size);

	return memblock_reserve(base, size);
}

Therefore the proper undo-logic should be as follows:
1) memblock_add when rmem is declared nomap,
2) memblock_free, otherwise.

Match the undo functions for readability.

Signed-off-by: Ohhoon Kwon <ohoono.kwon@...sung.com>
---
 drivers/of/of_reserved_mem.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c
index 15e2417974d6..2279e1b55d1d 100644
--- a/drivers/of/of_reserved_mem.c
+++ b/drivers/of/of_reserved_mem.c
@@ -273,9 +273,10 @@ void __init fdt_init_reserved_mem(void)
 			if (err != 0 && err != -ENOENT) {
 				pr_info("node %s compatible matching fail\n",
 					rmem->name);
-				memblock_free(rmem->base, rmem->size);
 				if (nomap)
 					memblock_add(rmem->base, rmem->size);
+				else
+					memblock_free(rmem->base, rmem->size);
 			}
 		}
 	}
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ