From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2046944AB62; Tue, 21 Jul 2026 21:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784670681; cv=none; b=SUaMdYy8qIX+5NFDLIYhtLmkK68pi/wgj1y0W1KrlAM1mICBstjjzZazzkjFVuMuCThhb0l3ZDBItl2YA20KhOtvkDeE/Xiv9gt0or6pxPVrAvM2PXkIBLiiWOVLaiegBzkxf6AtIwD/KSkYcl39oPXMA534bK60aPFy7Xj+jG4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784670681; c=relaxed/simple; bh=7Fl62BfBpI0HtfsPKvswjzfSyGM3MruklLGNUpdXFB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMMo16vne18Qm91/9WmUeRQ2rH4sviHoCOR7H19kHd6cW6j6KNDTbakBqNyBDXd053bgJ1uWEXRdzxbEJSLxXYCebAppO1WYCck1H60kpuFndmBUMHzknfLyuwa4cqguF/+OBxfCmz7NnkgchYrwDJQ3fgMb2Mm/Qs4lMRwFVGU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=F2m359VV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="F2m359VV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6072C1F000E9; Tue, 21 Jul 2026 21:51:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784670679; bh=MdfXrK7NK2a3fc2mro7hsZSMP+RSFcXuNLT8X2qHddU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=F2m359VVuELFtG8KMIIamjGFuFOvC7pNxYRCr2zg4c4828hWvQdJ+eASbDVudZI+r SsEKRTMqPkV0Zwlr+kei5NWKT2RxyE5BwclAqLJy+cL2ppVKycRsp/NtqDVnwLchEH 6kqolc+qEOPf2xwaxM+4UE2PNjK9P01bDT1qnHww= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Qi Zheng , Muchun Song , Dave Chinner , Roman Gushchin , Andrew Morton , Sasha Levin Subject: [PATCH 6.1 0981/1067] mm: shrinker: fix NULL pointer dereference in debugfs Date: Tue, 21 Jul 2026 17:26:22 +0200 Message-ID: <20260721152446.497900184@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260721152424.521567757@linuxfoundation.org> References: <20260721152424.521567757@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qi Zheng [ Upstream commit e30453c61e185e914fde83c650e268067b140218 ] shrinker_debugfs_add() creates both "count" and "scan" debugfs files unconditionally. That assumes every shrinker implements both count_objects() and scan_objects(), which is not guaranteed. For example, the xen-backend shrinker sets count_objects() but leaves scan_objects() NULL, so writing to its scan file calls through a NULL function pointer and panics the kernel: BUG: kernel NULL pointer dereference, address: 0000000000000000 RIP: 0010:0x0 Code: Unable to access opcode bytes at 0xffffffffffffffd6. Call Trace: shrinker_debugfs_scan_write+0x12e/0x270 full_proxy_write+0x5f/0x90 vfs_write+0xde/0x420 ? filp_flush+0x75/0x90 ? filp_close+0x1d/0x30 ? do_dup2+0xb8/0x120 ksys_write+0x68/0xf0 ? filp_flush+0x75/0x90 do_syscall_64+0xb3/0x5b0 entry_SYSCALL_64_after_hwframe+0x76/0x7e The count path has the same issue in principle if a shrinker omits count_objects(). To fix it, only create "count" and "scan" debugfs files when the corresponding callbacks are present. Link: https://lore.kernel.org/20260617090052.27325-1-qi.zheng@linux.dev Fixes: bbf535fd6f06 ("mm: shrinkers: add scan interface for shrinker debugfs") Signed-off-by: Qi Zheng Reviewed-by: Muchun Song Cc: Dave Chinner Cc: Qi Zheng Cc: Roman Gushchin Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- mm/shrinker_debug.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/mm/shrinker_debug.c +++ b/mm/shrinker_debug.c @@ -180,10 +180,12 @@ int shrinker_debugfs_add(struct shrinker } shrinker->debugfs_entry = entry; - debugfs_create_file("count", 0440, entry, shrinker, - &shrinker_debugfs_count_fops); - debugfs_create_file("scan", 0220, entry, shrinker, - &shrinker_debugfs_scan_fops); + if (shrinker->count_objects) + debugfs_create_file("count", 0440, entry, shrinker, + &shrinker_debugfs_count_fops); + if (shrinker->scan_objects) + debugfs_create_file("scan", 0220, entry, shrinker, + &shrinker_debugfs_scan_fops); return 0; }