Commit f5ed0867 authored by Catalin Marinas's avatar Catalin Marinas Committed by Euler
Browse files

mm: kmemleak: fix upper boundary check for physical address objects

mainline inclusion
from mainline-v6.14-rc1
commit 488b5b9eca68497b533ced059be5eff19578bbca
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/IBK4CC

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=488b5b9eca68497b533ced059be5eff19578bbca

--------------------------------

Memblock allocations are registered by kmemleak separately, based on their
physical address.  During the scanning stage, it checks whether an object
is within the min_low_pfn and max_low_pfn boundaries and ignores it
otherwise.

With the recent addition of __percpu pointer leak detection (commit
6c99d4eb7c5e ("kmemleak: enable tracking for percpu pointers")), kmemleak
started reporting leaks in setup_zone_pageset() and
setup_per_cpu_pageset().  These were caused by the node_data[0] object
(initialised in alloc_node_data()) ending on the PFN_PHYS(max_low_pfn)
boundary.  The non-strict upper boundary check introduced by commit
84c32629 ("mm: kmemleak: check physical address when scan") causes the
pg_data_t object to be ignored (not scanned) and the __percpu pointers it
contains to be reported as leaks.

Make the max_low_pfn upper boundary check strict when deciding whether to
ignore a physical address object and not scan it.

Link: https://lkml.kernel.org/r/20250127184233.2974311-1-catalin.marinas@arm.com


Fixes: 84c32629 ("mm: kmemleak: check physical address when scan")
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Reported-by: default avatarJakub Kicinski <kuba@kernel.org>
Tested-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Cc: Patrick Wang <patrick.wang.shcn@gmail.com>
Cc: <stable@vger.kernel.org>	[6.0.x]
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarWang Lian <dev01404@linx-info.com>
parent 0984334e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -1603,7 +1603,7 @@ static void kmemleak_scan(void)
			unsigned long phys = object->pointer;

			if (PHYS_PFN(phys) < min_low_pfn ||
			    PHYS_PFN(phys + object->size) >= max_low_pfn)
			    PHYS_PFN(phys + object->size) > max_low_pfn)
				__paint_it(object, KMEMLEAK_BLACK);
		}