Re: [PATCH v1] binfmt_misc: fix crash when load/unload module

From: Tong Zhang
Date: Mon Jan 24 2022 - 13:23:32 EST


On Mon, Jan 24, 2022 at 2:40 AM Christian Brauner <brauner@xxxxxxxxxx> wrote:
> The fix itself is obviously needed.
>
> However, afaict the previous patch introduced another bug and this patch
> right here doesn't fix it either.
>
> Namely, if you set CONFIG_SYSCTL=n and CONFIG_BINFMT_MISC={y,m}, then
> register_sysctl_mount_point() will return NULL causing modprobe
> binfmt_misc to fail. However, before 3ba442d5331f ("fs: move binfmt_misc
> sysctl to its own file") loading binfmt_misc would've succeeded even if
> fs/binfmt_misc wasn't created in kernel/sysctl.c. Afaict, that goes for
> both CONFIG_SYSCTL={y,n} since even in the CONFIG_SYSCTL=y case the
> kernel would've moved on if creating the sysctl header would've failed.
> And that makes sense since binfmt_misc is mountable wherever, not just
> at fs/binfmt_misc.
>
> All that indicates that the correct fix here would be to simply:
>
> binfmt_misc_header = register_sysctl_mount_point("fs/binfmt_misc");
>
> without checking for an error. That should fully restore the old
> behavior.
>

Thanks! That makes sense.
I modified the patch according to your comment, added another fix for
the return type issue and sent a v2.
Thanks again.
- Tong