Skip to contentSkip to conversation

fs: f2fs: fix kernel discard_thread NULL dereference

PATCH In review Hoi Pok Wu 2 participants 2 messages Oct 17, 2022 F2FS file system

lore
Share & tools
lore

Hoi Pok Wu

author
#0 lore raw

PATCH 1/1 fs: f2fs: fix kernel discard_thread NULL dereference

Pointer discard_thread is pointing to nowhere, using IS_ERR prevents the situation. IS_ERR also seen being used throughout the file.

---
 fs/f2fs/segment.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +2 -1
index acf3d3fa4363..79978b7206b5 100644
@@ -1634,7 +1634,8 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi)
 		struct task_struct *discard_thread = dcc->f2fs_issue_discard;
 
 		dcc->f2fs_issue_discard = NULL;
-		kthread_stop(discard_thread);
+		if (!IS_ERR(discard_thread))
+			kthread_stop(discard_thread);
 	}
 }
 
Signature · 8 lines
2.38.0



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
maintainer
#1 lore raw
Quoted 2 lines · Hoi Pok Wu

Pointer discard_thread is pointing to nowhere, using IS_ERR prevents the situation. IS_ERR also seen being used throughout the file.

I guess below patch can fix this issue from root cause?

https://lore.kernel.org/linux-f2fs-devel/[email protected]/T/#u

Thanks,

Quoted 22 lines
---
  fs/f2fs/segment.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
fs/f2fs/segment.c +2 -1
index acf3d3fa4363..79978b7206b5 100644
@@ -1634,7 +1634,8 @@ void f2fs_stop_discard_thread(struct f2fs_sb_info *sbi)
  		struct task_struct *discard_thread = dcc->f2fs_issue_discard;
 
  		dcc->f2fs_issue_discard = NULL;
-		kthread_stop(discard_thread);
+		if (!IS_ERR(discard_thread))
+			kthread_stop(discard_thread);
  	}
  }