Re: [syzbot] [fs?] BUG: unable to handle kernel NULL pointer dereference in do_pagemap_scan

From: Lizhi Xu
Date: Thu Jan 04 2024 - 20:33:17 EST


#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 861deac3b092

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 435b61054b5b..f547057f096b 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -2433,6 +2433,9 @@ static long do_pagemap_scan(struct mm_struct *mm, unsigned long uarg)

/* Protection change for the range is going to happen. */
if (p.arg.flags & PM_SCAN_WP_MATCHING) {
+ if (IS_ERR_OR_NULL(mm))
+ return -EINVAL;
+
mmu_notifier_range_init(&range, MMU_NOTIFY_PROTECTION_VMA, 0,
mm, p.arg.start, p.arg.end);
mmu_notifier_invalidate_range_start(&range);