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 042FA3F54B6; Thu, 16 Jul 2026 14:08:51 +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=1784210932; cv=none; b=nsWJZbI7UXUjHq4bTCGtHZKA0a7xk9ZjM0CM90pVWGgdTV94W2vFlTTugcfFrak4c4RyTV8EpXvD+efa6GKWhX8yQXjk22R3IkeIu+xj4cSW+Lbn9XWDfJOHVaJi4uQoxWXWZd6JY7SWO17oeOP7MeVGxUIXQkD0tn8XkdZTosM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784210932; c=relaxed/simple; bh=X+lS8XK7TGPG5sRlnl0qkOfLQhz9edKqUBI2uAmPRgk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AtlDiHit885NbG49AFA9e19rVkje6UPAgHMlesiiutodm6lGx0PfAHTCLcZ4VjYYXHeG0pN9SrGOyiKc3xwGKWzv0nt7eAkUq7IvlE2TAZGaJEVabUDoJvKs/5w/nONfBvQTe7iCQ5zUXq54IcK/XkTMnZxAg1vUWPDvt80nE+k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=lA9zG5+J; 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="lA9zG5+J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 632001F000E9; Thu, 16 Jul 2026 14:08:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784210930; bh=dkHyFA90d7ar7kDXHQpH50fh+EXqlJtQ2NIbg01wAvE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=lA9zG5+JkPitG6wUxZxNdR1w+Z1F5nKVHAoFoIJprLtKCxo0NTt/e2jmMvCSPbkb/ kKkubO2tjydHZgWtcVbwokK5YJwwG/Hr0xkH/AmXiroERRgZWdlYphEI88f8KQa7H0 LufZaZSPWInrFCxbVIV3V7ACMd/2d/DnpNud832U= 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 Subject: [PATCH 6.18 191/480] mm: shrinker: fix NULL pointer dereference in debugfs Date: Thu, 16 Jul 2026 15:28:58 +0200 Message-ID: <20260716133048.859575894@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260716133044.672218725@linuxfoundation.org> References: <20260716133044.672218725@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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Qi Zheng commit e30453c61e185e914fde83c650e268067b140218 upstream. 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: 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 @@ -182,10 +182,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; }