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

Lizhi Xu
2024-01-05T01:33:07Z

#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);