Skip to content

Commit 30e0b28

Browse files
author
Herton R. Krzesinski
committed
Merge: mm/kmemleak: Fix a UAF problem in kmemleak
MR: https://gitlab.com/redhat/centos-stream/src/kernel/centos-stream-9/-/merge_requests/2026 Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2151065 The BZ documents a use-after-free problem in the kmemleak code. The last patch in this MR fixes it. A number of other kmemleaks patches are pulled in as well to reduce merge conflicts and context differences. The last 2 patches are from mm-stable and so will be merged into the 6.3 kernel. Note that the kmemleak code is enabled only in the debug kernel. So it doesn't affect the quality of the production kernel. Signed-off-by: Waiman Long <longman@redhat.com> Approved-by: Chris von Recklinghausen <crecklin@redhat.com> Approved-by: Donald Dutile <ddutile@redhat.com> Approved-by: Rafael Aquini <aquini@redhat.com> Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2 parents 55cd084 + 80938dd commit 30e0b28

File tree

23 files changed

+473
-132
lines changed

23 files changed

+473
-132
lines changed

Documentation/dev-tools/kmemleak.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ mapping:
174174

175175
- ``kmemleak_alloc_phys``
176176
- ``kmemleak_free_part_phys``
177-
- ``kmemleak_not_leak_phys``
178177
- ``kmemleak_ignore_phys``
179178

180179
Dealing with false positives/negatives

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12179,6 +12179,7 @@ S: Maintained
1217912179
F: Documentation/core-api/boot-time-mm.rst
1218012180
F: include/linux/memblock.h
1218112181
F: mm/memblock.c
12182+
F: tools/testing/memblock/
1218212183

1218312184
MEMORY CONTROLLER DRIVERS
1218412185
M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>

drivers/of/fdt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ static int __init __reserved_mem_reserve_reg(unsigned long node,
529529
pr_debug("Reserved memory: reserved region for node '%s': base %pa, size %lu MiB\n",
530530
uname, &base, (unsigned long)(size / SZ_1M));
531531
if (!nomap)
532-
kmemleak_alloc_phys(base, size, 0, 0);
532+
kmemleak_alloc_phys(base, size, 0);
533533
}
534534
else
535535
pr_info("Reserved memory: failed to reserve memory for node '%s': base %pa, size %lu MiB\n",

include/linux/kmemleak.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ extern void kmemleak_not_leak(const void *ptr) __ref;
2929
extern void kmemleak_ignore(const void *ptr) __ref;
3030
extern void kmemleak_scan_area(const void *ptr, size_t size, gfp_t gfp) __ref;
3131
extern void kmemleak_no_scan(const void *ptr) __ref;
32-
extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size, int min_count,
32+
extern void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
3333
gfp_t gfp) __ref;
3434
extern void kmemleak_free_part_phys(phys_addr_t phys, size_t size) __ref;
35-
extern void kmemleak_not_leak_phys(phys_addr_t phys) __ref;
3635
extern void kmemleak_ignore_phys(phys_addr_t phys) __ref;
3736

3837
static inline void kmemleak_alloc_recursive(const void *ptr, size_t size,
@@ -107,15 +106,12 @@ static inline void kmemleak_no_scan(const void *ptr)
107106
{
108107
}
109108
static inline void kmemleak_alloc_phys(phys_addr_t phys, size_t size,
110-
int min_count, gfp_t gfp)
109+
gfp_t gfp)
111110
{
112111
}
113112
static inline void kmemleak_free_part_phys(phys_addr_t phys, size_t size)
114113
{
115114
}
116-
static inline void kmemleak_not_leak_phys(phys_addr_t phys)
117-
{
118-
}
119115
static inline void kmemleak_ignore_phys(phys_addr_t phys)
120116
{
121117
}

mm/kfence/core.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,6 @@ static unsigned long kfence_init_pool(void)
591591
addr += 2 * PAGE_SIZE;
592592
}
593593

594-
/*
595-
* The pool is live and will never be deallocated from this point on.
596-
* Remove the pool object from the kmemleak object tree, as it would
597-
* otherwise overlap with allocations returned by kfence_alloc(), which
598-
* are registered with kmemleak through the slab post-alloc hook.
599-
*/
600-
kmemleak_free(__kfence_pool);
601-
602594
return 0;
603595
}
604596

@@ -611,8 +603,16 @@ static bool __init kfence_init_pool_early(void)
611603

612604
addr = kfence_init_pool();
613605

614-
if (!addr)
606+
if (!addr) {
607+
/*
608+
* The pool is live and will never be deallocated from this point on.
609+
* Ignore the pool object from the kmemleak phys object tree, as it would
610+
* otherwise overlap with allocations returned by kfence_alloc(), which
611+
* are registered with kmemleak through the slab post-alloc hook.
612+
*/
613+
kmemleak_ignore_phys(__pa(__kfence_pool));
615614
return true;
615+
}
616616

617617
/*
618618
* Only release unprotected pages, and do not try to go back and change

0 commit comments

Comments
 (0)