Re: [PATCH] sysfs:Addresses null pointer dereference in sysfs_merge_group and sysfs_unmerge_group.

From: Greg KH
Date: Sun Feb 11 2024 - 06:09:19 EST


On Sat, Feb 10, 2024 at 08:43:14PM +1000, Rohan wrote:
> Hey,

Please don't top-post, or send html email, as they get dropped from the
mailing lists.

> I found this bug when writing my own kernel driver. I believed the function
> wasn't explicit in stating its the requirement for the name field and made
> it easy for developers to mistake it with sysfs_create_group and cause a
> crash. I wanted to change the code for robustness purposes. Other functions
> in the same file already do this check such as sysfs_group_change_owner.

Adding documentation is great, but don't add checks that are not needed,
we require callers to set up things properly, otherwise the kernel would
be nothing but a constant set of checks for things that can never
happen.

> As for why I chose -ENOENT, I did this because it was the same error code
> returned if the group cannot be found by kernfs_find_and_get but I
> understand if this should be changed.

Yes, that is a different type of error entirely. Just do the
documentation update, I'll gladly take that.

thanks,

greg k-h