Skip to contentSkip to conversation

powerpc/mm: add sanity check to avoid null pointer dereference

PATCH In review Defang Bo 2 participants 2 messages Dec 28, 2020 – Sep 8, 2022 PowerPC

lore
Share & tools
lore

Defang Bo

author
#0 lore raw

PATCH 1/1 powerpc/mm: add sanity check to avoid null pointer dereference

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.

---
 arch/powerpc/mm/nohash/tlb.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/mm/nohash/tlb.c +10 -1
index 5872f69..1d89335 100644
@@ -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))
Signature · 1 line
2.7.4
#1 lore raw

Le 28/12/2020 à 04:10, Defang Bo a écrit :

Quoted 3 lines

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

Quoted 43 lines
---
  arch/powerpc/mm/nohash/tlb.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
arch/powerpc/mm/nohash/tlb.c +10 -1
index 5872f69..1d89335 100644
@@ -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))