Re: [PATCH] kernfs: fix potential NULL dereference in mmap handler

From: Tejun Heo
Date: Tue Apr 01 2025 - 11:51:43 EST


On Tue, Apr 01, 2025 at 11:18:59PM +0800, Wentao Liang wrote:
> The kernfs_fop_mmap() invokes the '->mmap' callback without verifying its
> existence. This leads to a NULL pointer dereference when the kernfs node
> does not define the operation, resulting in an invalid memory access.
>
> Add a check to ensure the '->mmap' callback is present before invocation.
> Return -EINVAL when uninitialized to prevent the invalid access.

I think that's already checked through KERNFS_HAS_MMAP.

Thanks.

--
tejun