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

From: Andrew Morton
Date: Mon Jan 24 2022 - 23:48:28 EST


On Mon, 24 Jan 2022 19:40:53 +0800 kernel test robot <lkp@xxxxxxxxx> wrote:

> Hi Tong,
>
>
> >> fs/binfmt_misc.c:828:21: error: incompatible pointer types assigning to 'struct ctl_table_header *' from 'struct sysctl_header *' [-Werror,-Wincompatible-pointer-types]
> binfmt_misc_header = register_sysctl_mount_point("fs/binfmt_misc");
> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 1 error generated.
>
>
> vim +828 fs/binfmt_misc.c
>
> 821
> 822 static int __init init_misc_binfmt(void)
> 823 {
> 824 int err = register_filesystem(&bm_fs_type);
> 825 if (!err)
> 826 insert_binfmt(&misc_format);
> 827
> > 828 binfmt_misc_header = register_sysctl_mount_point("fs/binfmt_misc");
> 829 if (!binfmt_misc_header) {
> 830 pr_warn("Failed to create fs/binfmt_misc sysctl mount point");
> 831 return -ENOMEM;
> 832 }
> 833 return 0;
> 834 }
> 835

This is actually a blooper in Luis's "sysctl: add helper to register a
sysctl mount point".

Please test, review, ridicule, etc:

From: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Subject: include/linux/sysctl.h: fix register_sysctl_mount_point() return type

The CONFIG_SYSCTL=n stub returns the wrong type.

Fixes: ee9efac48a082 ("sysctl: add helper to register a sysctl mount point")
Cc: Luis Chamberlain <mcgrof@xxxxxxxxxx>
Cc: Tong Zhang <ztong0001@xxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

include/linux/sysctl.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

--- a/include/linux/sysctl.h~a
+++ a/include/linux/sysctl.h
@@ -265,7 +265,7 @@ static inline struct ctl_table_header *r
return NULL;
}

-static inline struct sysctl_header *register_sysctl_mount_point(const char *path)
+static inline struct ctl_table_header *register_sysctl_mount_point(const char *path)
{
return NULL;
}
_