* [PATCH] powerpc/mm: add sanity check to avoid null pointer dereference
@ 2020-12-28 3:10 Defang Bo
2022-09-08 6:21 ` Christophe Leroy
0 siblings, 1 reply; 2+ messages in thread
From: Defang Bo @ 2020-12-28 3:10 UTC (permalink / raw)
To: mpe, benh, paulus, christophe.leroy, akpm, geert, rppt,
linuxppc-dev, linux-kernel
Cc: Defang Bo
Similar to commit<0dc294f717d4>("powerpc/mm: bail out early when flushing TLB page"),
there should be a check for 'mm' to prevent Null pointer dereference
in case of 'mm' argument was legitimately passed.
Signed-off-by: Defang Bo <bodefang@126.com>
---
arch/powerpc/mm/nohash/tlb.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/mm/nohash/tlb.c b/arch/powerpc/mm/nohash/tlb.c
index 5872f69..1d89335 100644
--- a/arch/powerpc/mm/nohash/tlb.c
+++ b/arch/powerpc/mm/nohash/tlb.c
@@ -192,6 +192,9 @@ void local_flush_tlb_mm(struct mm_struct *mm)
{
unsigned int pid;
+ if (WARN_ON(!mm))
+ return;
+
preempt_disable();
pid = mm->context.id;
if (pid != MMU_NO_CONTEXT)
@@ -205,8 +208,11 @@ void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
{
unsigned int pid;
+ if (WARN_ON(!mm))
+ return;
+
preempt_disable();
- pid = mm ? mm->context.id : 0;
+ pid = mm->context.id;
if (pid != MMU_NO_CONTEXT)
_tlbil_va(vmaddr, pid, tsize, ind);
preempt_enable();
@@ -268,6 +274,9 @@ void flush_tlb_mm(struct mm_struct *mm)
{
unsigned int pid;
+ if (WARN_ON(!mm))
+ return;
+
preempt_disable();
pid = mm->context.id;
if (unlikely(pid == MMU_NO_CONTEXT))
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] powerpc/mm: add sanity check to avoid null pointer dereference
2020-12-28 3:10 [PATCH] powerpc/mm: add sanity check to avoid null pointer dereference Defang Bo
@ 2022-09-08 6:21 ` Christophe Leroy
0 siblings, 0 replies; 2+ messages in thread
From: Christophe Leroy @ 2022-09-08 6:21 UTC (permalink / raw)
To: Defang Bo, mpe, benh, paulus, akpm, geert, rppt, linuxppc-dev,
linux-kernel
Le 28/12/2020 à 04:10, Defang Bo a écrit :
> Similar to commit<0dc294f717d4>("powerpc/mm: bail out early when flushing TLB page"),
> there should be a check for 'mm' to prevent Null pointer dereference
> in case of 'mm' argument was legitimately passed.
I don't understand what you are trying to do here.
In commit 0dc294f717d4, a call with a NULL mm is expected. The commit
just reorganises the code in order to bail out earlier and more explicitely.
In your patch, you are adding WARN_ON, which means that being called
with a NULL mm is unexpected. Why do you think it is necessary to do it
? Have you encountered any problem ?
Thanks
Christophe
>
> Signed-off-by: Defang Bo <bodefang@126.com>
> ---
> arch/powerpc/mm/nohash/tlb.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/mm/nohash/tlb.c b/arch/powerpc/mm/nohash/tlb.c
> index 5872f69..1d89335 100644
> --- a/arch/powerpc/mm/nohash/tlb.c
> +++ b/arch/powerpc/mm/nohash/tlb.c
> @@ -192,6 +192,9 @@ void local_flush_tlb_mm(struct mm_struct *mm)
> {
> unsigned int pid;
>
> + if (WARN_ON(!mm))
> + return;
> +
> preempt_disable();
> pid = mm->context.id;
> if (pid != MMU_NO_CONTEXT)
> @@ -205,8 +208,11 @@ void __local_flush_tlb_page(struct mm_struct *mm, unsigned long vmaddr,
> {
> unsigned int pid;
>
> + if (WARN_ON(!mm))
> + return;
> +
> preempt_disable();
> - pid = mm ? mm->context.id : 0;
> + pid = mm->context.id;
> if (pid != MMU_NO_CONTEXT)
> _tlbil_va(vmaddr, pid, tsize, ind);
> preempt_enable();
> @@ -268,6 +274,9 @@ void flush_tlb_mm(struct mm_struct *mm)
> {
> unsigned int pid;
>
> + if (WARN_ON(!mm))
> + return;
> +
> preempt_disable();
> pid = mm->context.id;
> if (unlikely(pid == MMU_NO_CONTEXT))
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-08 6:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 3:10 [PATCH] powerpc/mm: add sanity check to avoid null pointer dereference Defang Bo
2022-09-08 6:21 ` Christophe Leroy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.