Re: [PATCH v1] fs/super.c: Add NULL check for type in iterate_supers_type
From: Al Viro
Date: Wed Apr 02 2025 - 22:48:20 EST
On Thu, Apr 03, 2025 at 10:37:17AM +0800, Xiaole He wrote:
> Thank you for your feedback.
> While I acknowledge your points, I would like to clarify the rationale
> behind submitting this patch.
> During my experimentation with an external module interacting with the
> superblock, I utilized iterate_supers_type (from fs/super.c) as it is
> an exported symbol. However, I observed a potential vulnerability in
> its implementation: the type argument can be passed as NULL, leading
> to a null pointer dereference. To verify this, I deliberately triggered
> a scenario where type was set to NULL, resulting in the following dmesg
> output:
> After this observasion, I worry about if this vulnerability can cause
> the whole kernel crash if the type argument is passed by a
> unintentional NULL in the kernel code rather than in the external
> module.
> Thus I submitted the patch to address the missing null-check.
> Thank you for your review.
You do realize that passing it NULL as the second (function pointer) argument
would also oops, right? Passing (void (*)(struct super_block *))kfree
there would do even more unpleasant things, etc.
Sure, it's exported - so's strlen(). While we are at it, checking just for
NULL is not the limit - what if the caller gives it ERR_PTR(...) as argument?