public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] fs/super.c: Add NULL check for type in iterate_supers_type
@ 2025-04-02  3:45 Xiaole He
  2025-04-02 11:38 ` James Bottomley
  2025-04-03  8:01 ` Christian Brauner
  0 siblings, 2 replies; 5+ messages in thread
From: Xiaole He @ 2025-04-02  3:45 UTC (permalink / raw)
  To: viro, brauner; +Cc: jack, linux-fsdevel, linux-kernel, Xiaole He

The first several lines of iterate_supers_type are below:

1 void iterate_supers_type(struct file_system_type *type,
2 	void (*f)(struct super_block *, void *), void *arg)
3 {
4 	struct super_block *sb, *p = NULL;
5
6 	spin_lock(&sb_lock);
7 	hlist_for_each_entry(sb, &type->fs_supers, s_instances) {
8 	...
9 }

The iterate_super_type is a exported symbol, and if iterate_supers_type
is called with type of NULL, then there will be a NULL pointer
dereference of argument type in line 7.

This patch fix above problem by adding NULL pointer check for argument
type.

Signed-off-by: Xiaole He <hexiaole1994@126.com>
---
 fs/super.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/super.c b/fs/super.c
index 5a7db4a556e3..105a275b8360 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -959,6 +959,8 @@ void iterate_supers_type(struct file_system_type *type,
 {
 	struct super_block *sb, *p = NULL;
 
+	if (unlikely(ZERO_OR_NULL_PTR(type)))
+		return;
 	spin_lock(&sb_lock);
 	hlist_for_each_entry(sb, &type->fs_supers, s_instances) {
 		bool locked;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-04-03  8:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-02  3:45 [PATCH v1] fs/super.c: Add NULL check for type in iterate_supers_type Xiaole He
2025-04-02 11:38 ` James Bottomley
     [not found]   ` <4ee2fdcb.1854a.195f9828c86.Coremail.hexiaole1994@126.com>
2025-04-03  2:47     ` Al Viro
     [not found]       ` <75a45193.18746.195f9a088c4.Coremail.hexiaole1994@126.com>
2025-04-03  3:50         ` Al Viro
2025-04-03  8:01 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox