* [PATCH v2 0/1] mm: kfence: fix unexpected leak scan on kfence pool
@ 2022-06-28 11:37 yee.lee
2022-06-28 11:37 ` [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool yee.lee
0 siblings, 1 reply; 12+ messages in thread
From: yee.lee @ 2022-06-28 11:37 UTC (permalink / raw)
To: linux-kernel
Cc: catalin.marinas, Yee Lee, Matthias Brugger,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
From: Yee Lee <yee.lee@mediatek.com>
Since the latest patches of kmemleak separated its address management
to two rb-trees, phys and virt, the kmemleak_free failed to free kfence_pool
from the virt tree. It caused unexpected scan the blocks and triggered
kfence faults.
Reference:
https://lore.kernel.org/linux-mm/20220611035551.1823303-1-patrick.wang.shcn@gmail.com/
==================================================================
BUG: KFENCE: invalid read in scan_block+0x13c/0x838
Invalid read at 0x000000003dc26873:
scan_block+0x13c/0x838
scan_gray_list+0x1f0/0x478
kmemleak_scan+0x63c/0xd64
kmemleak_write+0x618/0x8cc
full_proxy_write+0x70/0x138
vfs_write+0x108/0x314
ksys_write+0x7c/0x14c
__arm64_sys_write+0x20/0x30
el0_svc_common+0xa8/0x144
do_el0_svc+0x30/0xd4
el0_svc+0x38/0x15c
el0t_64_sync_handler+0x88/0xf8
el0t_64_sync+0x1a0/0x1a4
CPU: 0 PID: 128 Comm: sh Not tainted 5.18.0-mainline-40996-g7d83a175ff4a-dirty #1
Hardware name: linux,dummy-virt (DT)
==================================================================
This patch applies kmemleak_ignore_phys() to replace the original kmemleak_free and
adapts it to the late enabling case.
v1->v2:
- use kmemleak_ignore_phys() to bypass the scanning.
- move out the freeing opeartion from late enabling as it's trivial.
Yee Lee (1):
mm: kfence: apply kmemleak_ignore_phys on early allocated pool
mm/kfence/core.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-06-28 11:37 [PATCH v2 0/1] mm: kfence: fix unexpected leak scan on kfence pool yee.lee
@ 2022-06-28 11:37 ` yee.lee
2022-06-28 12:10 ` Marco Elver
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: yee.lee @ 2022-06-28 11:37 UTC (permalink / raw)
To: linux-kernel
Cc: catalin.marinas, Yee Lee, Alexander Potapenko, Marco Elver,
Dmitry Vyukov, Andrew Morton, Matthias Brugger, open list:KFENCE,
open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
From: Yee Lee <yee.lee@mediatek.com>
This patch solves two issues.
(1) The pool allocated by memblock needs to unregister from
kmemleak scanning. Apply kmemleak_ignore_phys to replace the
original kmemleak_free as its address now is stored in the phys tree.
(2) The pool late allocated by page-alloc doesn't need to unregister.
Move out the freeing operation from its call path.
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Suggested-by: Marco Elver <elver@google.com>
Signed-off-by: Yee Lee <yee.lee@mediatek.com>
---
mm/kfence/core.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)
diff --git a/mm/kfence/core.c b/mm/kfence/core.c
index 4e7cd4c8e687..32a4a75e820c 100644
--- a/mm/kfence/core.c
+++ b/mm/kfence/core.c
@@ -600,14 +600,6 @@ static unsigned long kfence_init_pool(void)
addr += 2 * PAGE_SIZE;
}
- /*
- * The pool is live and will never be deallocated from this point on.
- * Remove the pool object from the kmemleak object tree, as it would
- * otherwise overlap with allocations returned by kfence_alloc(), which
- * are registered with kmemleak through the slab post-alloc hook.
- */
- kmemleak_free(__kfence_pool);
-
return 0;
}
@@ -620,8 +612,16 @@ static bool __init kfence_init_pool_early(void)
addr = kfence_init_pool();
- if (!addr)
+ if (!addr) {
+ /*
+ * The pool is live and will never be deallocated from this point on.
+ * Ignore the pool object from the kmemleak phys object tree, as it would
+ * otherwise overlap with allocations returned by kfence_alloc(), which
+ * are registered with kmemleak through the slab post-alloc hook.
+ */
+ kmemleak_ignore_phys(__pa(__kfence_pool));
return true;
+ }
/*
* Only release unprotected pages, and do not try to go back and change
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-06-28 11:37 ` [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool yee.lee
@ 2022-06-28 12:10 ` Marco Elver
2022-06-29 21:39 ` Catalin Marinas
2022-07-15 8:17 ` Geert Uytterhoeven
2 siblings, 0 replies; 12+ messages in thread
From: Marco Elver @ 2022-06-28 12:10 UTC (permalink / raw)
To: yee.lee
Cc: linux-kernel, catalin.marinas, Alexander Potapenko,
Dmitry Vyukov, Andrew Morton, Matthias Brugger, open list:KFENCE,
open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
On Tue, 28 Jun 2022 at 13:37, yee.lee via kasan-dev
<kasan-dev@googlegroups.com> wrote:
>
> From: Yee Lee <yee.lee@mediatek.com>
>
> This patch solves two issues.
>
> (1) The pool allocated by memblock needs to unregister from
> kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> original kmemleak_free as its address now is stored in the phys tree.
>
> (2) The pool late allocated by page-alloc doesn't need to unregister.
> Move out the freeing operation from its call path.
>
> Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Yee Lee <yee.lee@mediatek.com>
Reviewed-by: Marco Elver <elver@google.com>
Does this want a Fixes tag?
> ---
> mm/kfence/core.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/mm/kfence/core.c b/mm/kfence/core.c
> index 4e7cd4c8e687..32a4a75e820c 100644
> --- a/mm/kfence/core.c
> +++ b/mm/kfence/core.c
> @@ -600,14 +600,6 @@ static unsigned long kfence_init_pool(void)
> addr += 2 * PAGE_SIZE;
> }
>
> - /*
> - * The pool is live and will never be deallocated from this point on.
> - * Remove the pool object from the kmemleak object tree, as it would
> - * otherwise overlap with allocations returned by kfence_alloc(), which
> - * are registered with kmemleak through the slab post-alloc hook.
> - */
> - kmemleak_free(__kfence_pool);
> -
> return 0;
> }
>
> @@ -620,8 +612,16 @@ static bool __init kfence_init_pool_early(void)
>
> addr = kfence_init_pool();
>
> - if (!addr)
> + if (!addr) {
> + /*
> + * The pool is live and will never be deallocated from this point on.
> + * Ignore the pool object from the kmemleak phys object tree, as it would
> + * otherwise overlap with allocations returned by kfence_alloc(), which
> + * are registered with kmemleak through the slab post-alloc hook.
> + */
> + kmemleak_ignore_phys(__pa(__kfence_pool));
> return true;
> + }
>
> /*
> * Only release unprotected pages, and do not try to go back and change
> --
> 2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-06-28 11:37 ` [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool yee.lee
2022-06-28 12:10 ` Marco Elver
@ 2022-06-29 21:39 ` Catalin Marinas
2022-07-15 8:17 ` Geert Uytterhoeven
2 siblings, 0 replies; 12+ messages in thread
From: Catalin Marinas @ 2022-06-29 21:39 UTC (permalink / raw)
To: yee.lee
Cc: linux-kernel, Alexander Potapenko, Marco Elver, Dmitry Vyukov,
Andrew Morton, Matthias Brugger, open list:KFENCE,
open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
On Tue, Jun 28, 2022 at 07:37:11PM +0800, yee.lee@mediatek.com wrote:
> From: Yee Lee <yee.lee@mediatek.com>
>
> This patch solves two issues.
>
> (1) The pool allocated by memblock needs to unregister from
> kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> original kmemleak_free as its address now is stored in the phys tree.
>
> (2) The pool late allocated by page-alloc doesn't need to unregister.
> Move out the freeing operation from its call path.
>
> Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Yee Lee <yee.lee@mediatek.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-06-28 11:37 ` [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool yee.lee
2022-06-28 12:10 ` Marco Elver
2022-06-29 21:39 ` Catalin Marinas
@ 2022-07-15 8:17 ` Geert Uytterhoeven
2022-07-15 23:33 ` Andrew Morton
2 siblings, 1 reply; 12+ messages in thread
From: Geert Uytterhoeven @ 2022-07-15 8:17 UTC (permalink / raw)
To: yee.lee
Cc: Linux Kernel Mailing List, Catalin Marinas, Alexander Potapenko,
Marco Elver, Dmitry Vyukov, Andrew Morton, Matthias Brugger,
open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
Hi Yee,
On Tue, Jun 28, 2022 at 1:42 PM <yee.lee@mediatek.com> wrote:
> From: Yee Lee <yee.lee@mediatek.com>
>
> This patch solves two issues.
>
> (1) The pool allocated by memblock needs to unregister from
> kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> original kmemleak_free as its address now is stored in the phys tree.
>
> (2) The pool late allocated by page-alloc doesn't need to unregister.
> Move out the freeing operation from its call path.
>
> Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> Suggested-by: Marco Elver <elver@google.com>
> Signed-off-by: Yee Lee <yee.lee@mediatek.com>
Thank you, this fixes the storm of
BUG: KFENCE: invalid read in scan_block+0x78/0x130
BUG: KFENCE: use-after-free read in scan_block+0x78/0x130
BUG: KFENCE: out-of-bounds read in scan_block+0x78/0x130
messages I was seeing on arm64.
Tested-by: Geert Uytterhoeven <geert+renesas@glider.be>
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-15 8:17 ` Geert Uytterhoeven
@ 2022-07-15 23:33 ` Andrew Morton
2022-07-16 18:43 ` Geert Uytterhoeven
0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2022-07-15 23:33 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: yee.lee, Linux Kernel Mailing List, Catalin Marinas,
Alexander Potapenko, Marco Elver, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Marco Elver,
Catalin Marinas
On Fri, 15 Jul 2022 10:17:43 +0200 Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Tue, Jun 28, 2022 at 1:42 PM <yee.lee@mediatek.com> wrote:
> > From: Yee Lee <yee.lee@mediatek.com>
> >
> > This patch solves two issues.
> >
> > (1) The pool allocated by memblock needs to unregister from
> > kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> > original kmemleak_free as its address now is stored in the phys tree.
> >
> > (2) The pool late allocated by page-alloc doesn't need to unregister.
> > Move out the freeing operation from its call path.
> >
> > Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> > Suggested-by: Marco Elver <elver@google.com>
> > Signed-off-by: Yee Lee <yee.lee@mediatek.com>
>
> Thank you, this fixes the storm of
>
> BUG: KFENCE: invalid read in scan_block+0x78/0x130
> BUG: KFENCE: use-after-free read in scan_block+0x78/0x130
> BUG: KFENCE: out-of-bounds read in scan_block+0x78/0x130
>
> messages I was seeing on arm64.
Thanks, but...
- It would be great if we could identify a Fixes: for this.
- This patch has been accused of crashing the kernel:
https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
Do we think that report is bogus?
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-15 23:33 ` Andrew Morton
@ 2022-07-16 18:43 ` Geert Uytterhoeven
2022-07-18 14:26 ` Marco Elver
2022-07-19 11:50 ` Catalin Marinas
0 siblings, 2 replies; 12+ messages in thread
From: Geert Uytterhoeven @ 2022-07-16 18:43 UTC (permalink / raw)
To: Andrew Morton
Cc: yee.lee, Linux Kernel Mailing List, Catalin Marinas,
Alexander Potapenko, Marco Elver, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
Hi Andrew,
On Sat, Jul 16, 2022 at 1:33 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> On Fri, 15 Jul 2022 10:17:43 +0200 Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > On Tue, Jun 28, 2022 at 1:42 PM <yee.lee@mediatek.com> wrote:
> > > From: Yee Lee <yee.lee@mediatek.com>
> > >
> > > This patch solves two issues.
> > >
> > > (1) The pool allocated by memblock needs to unregister from
> > > kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> > > original kmemleak_free as its address now is stored in the phys tree.
> > >
> > > (2) The pool late allocated by page-alloc doesn't need to unregister.
> > > Move out the freeing operation from its call path.
> > >
> > > Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> > > Suggested-by: Marco Elver <elver@google.com>
> > > Signed-off-by: Yee Lee <yee.lee@mediatek.com>
> >
> > Thank you, this fixes the storm of
> >
> > BUG: KFENCE: invalid read in scan_block+0x78/0x130
> > BUG: KFENCE: use-after-free read in scan_block+0x78/0x130
> > BUG: KFENCE: out-of-bounds read in scan_block+0x78/0x130
> >
> > messages I was seeing on arm64.
>
> Thanks, but...
>
> - It would be great if we could identify a Fixes: for this.
IIRC, I started seeing the issue with "[PATCH v4 3/4] mm:
kmemleak: add rbtree and store physical address for objects
allocated with PA" (i.e. commit 0c24e061196c21d5 ("mm: kmemleak:
add rbtree and store physical address for objects allocated
with PA")) of series "[PATCH v4 0/4] mm: kmemleak: store objects
allocated with physical address separately and check when scan"
(https://lore.kernel.org/all/20220611035551.1823303-1-patrick.wang.shcn@gmail.com),
in an arm64 config that had enabled kfence.
So I think this patch is sort of a dependency for that series.
I had cherry-picked that series after bisecting a regression to
commit 23c2d497de21f258 ("mm: kmemleak: take a full lowmem check in
kmemleak_*_phys()") in v5.18-rc3, and having a look around.
> - This patch has been accused of crashing the kernel:
>
> https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
>
> Do we think that report is bogus?
I think all of this is highly architecture-specific...
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-16 18:43 ` Geert Uytterhoeven
@ 2022-07-18 14:26 ` Marco Elver
2022-07-19 23:13 ` Andrew Morton
2022-07-19 11:50 ` Catalin Marinas
1 sibling, 1 reply; 12+ messages in thread
From: Marco Elver @ 2022-07-18 14:26 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Andrew Morton, yee.lee, Linux Kernel Mailing List,
Catalin Marinas, Alexander Potapenko, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
On Sat, 16 Jul 2022 at 20:43, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
[...]
> > - This patch has been accused of crashing the kernel:
> >
> > https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
> >
> > Do we think that report is bogus?
>
> I think all of this is highly architecture-specific...
The report can be reproduced on i386 with CONFIG_X86_PAE=y. But e.g.
mm/memblock.c:memblock_free() is also guilty of using __pa() on
previously memblock_alloc()'d addresses. Looking at the phys addr
before memblock_alloc() does virt_to_phys(), the result of __pa()
looks correct even on PAE, at least for the purpose of passing it on
to kmemleak(). So I don't know what that BUG_ON(slow_virt_to_phys() !=
phys_addr) is supposed to tell us here.
Ideas?
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-16 18:43 ` Geert Uytterhoeven
2022-07-18 14:26 ` Marco Elver
@ 2022-07-19 11:50 ` Catalin Marinas
1 sibling, 0 replies; 12+ messages in thread
From: Catalin Marinas @ 2022-07-19 11:50 UTC (permalink / raw)
To: Geert Uytterhoeven
Cc: Andrew Morton, yee.lee, Linux Kernel Mailing List,
Alexander Potapenko, Marco Elver, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support
On Sat, Jul 16, 2022 at 08:43:06PM +0200, Geert Uytterhoeven wrote:
> On Sat, Jul 16, 2022 at 1:33 AM Andrew Morton <akpm@linux-foundation.org> wrote:
> > On Fri, 15 Jul 2022 10:17:43 +0200 Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> > > On Tue, Jun 28, 2022 at 1:42 PM <yee.lee@mediatek.com> wrote:
> > > > From: Yee Lee <yee.lee@mediatek.com>
> > > >
> > > > This patch solves two issues.
> > > >
> > > > (1) The pool allocated by memblock needs to unregister from
> > > > kmemleak scanning. Apply kmemleak_ignore_phys to replace the
> > > > original kmemleak_free as its address now is stored in the phys tree.
> > > >
> > > > (2) The pool late allocated by page-alloc doesn't need to unregister.
> > > > Move out the freeing operation from its call path.
> > > >
> > > > Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
> > > > Suggested-by: Marco Elver <elver@google.com>
> > > > Signed-off-by: Yee Lee <yee.lee@mediatek.com>
> > >
> > > Thank you, this fixes the storm of
> > >
> > > BUG: KFENCE: invalid read in scan_block+0x78/0x130
> > > BUG: KFENCE: use-after-free read in scan_block+0x78/0x130
> > > BUG: KFENCE: out-of-bounds read in scan_block+0x78/0x130
> > >
> > > messages I was seeing on arm64.
> >
> > Thanks, but...
> >
> > - It would be great if we could identify a Fixes: for this.
>
> IIRC, I started seeing the issue with "[PATCH v4 3/4] mm:
> kmemleak: add rbtree and store physical address for objects
> allocated with PA" (i.e. commit 0c24e061196c21d5 ("mm: kmemleak:
> add rbtree and store physical address for objects allocated
> with PA")) of series "[PATCH v4 0/4] mm: kmemleak: store objects
> allocated with physical address separately and check when scan"
> (https://lore.kernel.org/all/20220611035551.1823303-1-patrick.wang.shcn@gmail.com),
> in an arm64 config that had enabled kfence.
Yes, I think it fixes 0c24e061196c21d5 since after that commit, the
kmemleak_free() no longer worked as expected on physically allocated
objects.
--
Catalin
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-18 14:26 ` Marco Elver
@ 2022-07-19 23:13 ` Andrew Morton
2022-07-19 23:22 ` Dave Hansen
0 siblings, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2022-07-19 23:13 UTC (permalink / raw)
To: Marco Elver
Cc: Geert Uytterhoeven, yee.lee, Linux Kernel Mailing List,
Catalin Marinas, Alexander Potapenko, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Dave Hansen
On Mon, 18 Jul 2022 16:26:25 +0200 Marco Elver <elver@google.com> wrote:
> On Sat, 16 Jul 2022 at 20:43, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> [...]
> > > - This patch has been accused of crashing the kernel:
> > >
> > > https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
> > >
> > > Do we think that report is bogus?
> >
> > I think all of this is highly architecture-specific...
>
> The report can be reproduced on i386 with CONFIG_X86_PAE=y. But e.g.
> mm/memblock.c:memblock_free() is also guilty of using __pa() on
> previously memblock_alloc()'d addresses. Looking at the phys addr
> before memblock_alloc() does virt_to_phys(), the result of __pa()
> looks correct even on PAE, at least for the purpose of passing it on
> to kmemleak(). So I don't know what that BUG_ON(slow_virt_to_phys() !=
> phys_addr) is supposed to tell us here.
>
It's only been nine years, so I'm sure Dave can remember why he added
it ;)
BUG_ON(slow_virt_to_phys((void *)x) != phys_addr);
in arch/x86/mm/physaddr.c:__phys_addr().
This kfence patch does seem to be desirable, but we can't proceed if
it's resulting in kernel crashes.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-19 23:13 ` Andrew Morton
@ 2022-07-19 23:22 ` Dave Hansen
2022-08-01 14:05 ` Marco Elver
0 siblings, 1 reply; 12+ messages in thread
From: Dave Hansen @ 2022-07-19 23:22 UTC (permalink / raw)
To: Andrew Morton, Marco Elver
Cc: Geert Uytterhoeven, yee.lee, Linux Kernel Mailing List,
Catalin Marinas, Alexander Potapenko, Dmitry Vyukov,
Matthias Brugger, open list:KFENCE, open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Dave Hansen
On 7/19/22 16:13, Andrew Morton wrote:
> On Mon, 18 Jul 2022 16:26:25 +0200 Marco Elver <elver@google.com> wrote:
>
>> On Sat, 16 Jul 2022 at 20:43, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>> [...]
>>>> - This patch has been accused of crashing the kernel:
>>>>
>>>> https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
>>>>
>>>> Do we think that report is bogus?
>>> I think all of this is highly architecture-specific...
>> The report can be reproduced on i386 with CONFIG_X86_PAE=y. But e.g.
>> mm/memblock.c:memblock_free() is also guilty of using __pa() on
>> previously memblock_alloc()'d addresses. Looking at the phys addr
>> before memblock_alloc() does virt_to_phys(), the result of __pa()
>> looks correct even on PAE, at least for the purpose of passing it on
>> to kmemleak(). So I don't know what that BUG_ON(slow_virt_to_phys() !=
>> phys_addr) is supposed to tell us here.
>>
> It's only been nine years, so I'm sure Dave can remember why he added
> it ;)
>
> BUG_ON(slow_virt_to_phys((void *)x) != phys_addr);
>
> in arch/x86/mm/physaddr.c:__phys_addr().
I think I intended it to double check that the linear map is *actually*
a linear map for 'x'. Sure, we can use the "x - PAGE_OFFSET" shortcut,
but did it turn out to be actually accurate for the address it was handed?
I'd be curious what the page tables actually say for the address that's
causing problems.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool
2022-07-19 23:22 ` Dave Hansen
@ 2022-08-01 14:05 ` Marco Elver
0 siblings, 0 replies; 12+ messages in thread
From: Marco Elver @ 2022-08-01 14:05 UTC (permalink / raw)
To: Dave Hansen
Cc: Andrew Morton, Geert Uytterhoeven, yee.lee,
Linux Kernel Mailing List, Catalin Marinas, Alexander Potapenko,
Dmitry Vyukov, Matthias Brugger, open list:KFENCE,
open list:MEMORY MANAGEMENT,
moderated list:ARM/Mediatek SoC support,
moderated list:ARM/Mediatek SoC support, Dave Hansen,
the arch/x86 maintainers
[+x86 maintainers ...]
On Wed, 20 Jul 2022 at 01:22, Dave Hansen <dave.hansen@intel.com> wrote:
> On 7/19/22 16:13, Andrew Morton wrote:
> > On Mon, 18 Jul 2022 16:26:25 +0200 Marco Elver <elver@google.com> wrote:
> >
> >> On Sat, 16 Jul 2022 at 20:43, Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> >> [...]
> >>>> - This patch has been accused of crashing the kernel:
> >>>>
> >>>> https://lkml.kernel.org/r/YsFeUHkrFTQ7T51Q@xsang-OptiPlex-9020
> >>>>
> >>>> Do we think that report is bogus?
> >>> I think all of this is highly architecture-specific...
> >> The report can be reproduced on i386 with CONFIG_X86_PAE=y. But e.g.
> >> mm/memblock.c:memblock_free() is also guilty of using __pa() on
> >> previously memblock_alloc()'d addresses. Looking at the phys addr
> >> before memblock_alloc() does virt_to_phys(), the result of __pa()
> >> looks correct even on PAE, at least for the purpose of passing it on
> >> to kmemleak(). So I don't know what that BUG_ON(slow_virt_to_phys() !=
> >> phys_addr) is supposed to tell us here.
> >>
> > It's only been nine years, so I'm sure Dave can remember why he added
> > it ;)
> >
> > BUG_ON(slow_virt_to_phys((void *)x) != phys_addr);
> >
> > in arch/x86/mm/physaddr.c:__phys_addr().
>
> I think I intended it to double check that the linear map is *actually*
> a linear map for 'x'. Sure, we can use the "x - PAGE_OFFSET" shortcut,
> but did it turn out to be actually accurate for the address it was handed?
>
> I'd be curious what the page tables actually say for the address that's
> causing problems.
test robot just reminded us again:
https://lore.kernel.org/all/YufXncrWhJZH0ifB@xsang-OptiPlex-9020/T/#u
Few things I noticed:
* mm/memblock.c's memblock_free() also uses __pa() to convert back to
physical address. Presumably that's also wrong. What should be used
instead?
* kmemleak happily converts phys_addr_t to unsigned long everywhere,
but with i386 PAE, this will narrow a 64-bit address to a 32-bit
address. Is that correct? Does kmemleak need a "depends on 64BIT ||
!PHYS_ADDR_T_64BIT"?
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2022-08-01 14:07 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-28 11:37 [PATCH v2 0/1] mm: kfence: fix unexpected leak scan on kfence pool yee.lee
2022-06-28 11:37 ` [PATCH v2 1/1] mm: kfence: apply kmemleak_ignore_phys on early allocated pool yee.lee
2022-06-28 12:10 ` Marco Elver
2022-06-29 21:39 ` Catalin Marinas
2022-07-15 8:17 ` Geert Uytterhoeven
2022-07-15 23:33 ` Andrew Morton
2022-07-16 18:43 ` Geert Uytterhoeven
2022-07-18 14:26 ` Marco Elver
2022-07-19 23:13 ` Andrew Morton
2022-07-19 23:22 ` Dave Hansen
2022-08-01 14:05 ` Marco Elver
2022-07-19 11:50 ` Catalin Marinas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).