diff mbox series

[v4,-next,13/15] x86: vdso: move the sysctl to arch/x86/entry/vdso/vdso32-setup.c

Message ID 20241228145746.2783627-14-yukaixiong@huawei.com (mailing list archive)
State New
Headers show
Series sysctl: move sysctls from vm_table into its own files | expand

Commit Message

yukaixiong Dec. 28, 2024, 2:57 p.m. UTC
When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
So, move it into its own file.

Before this patch, vdso_enabled was allowed to be set to
a value exceeding 1 on x86_32 architecture. After this patch is
applied, vdso_enabled is not permitted to set the value more than 1.
It does not matter, because according to the function load_vdso32(),
only vdso_enabled is set to 1, VDSO would be enabled. Other values
all mean "disabled". The same limitation could be seen in the
function vdso32_setup().

Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
Reviewed-by: Kees Cook <kees@kernel.org>
---
v4:
 - const qualify struct ctl_table vdso_table
---
---
 arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
 kernel/sysctl.c                    |  8 +-------
 2 files changed, 12 insertions(+), 12 deletions(-)

Comments

Brian Gerst Dec. 29, 2024, 11:05 p.m. UTC | #1
On Sat, Dec 28, 2024 at 10:17 AM Kaixiong Yu <yukaixiong@huawei.com> wrote:
>
> When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
> vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
> So, move it into its own file.
>
> Before this patch, vdso_enabled was allowed to be set to
> a value exceeding 1 on x86_32 architecture. After this patch is
> applied, vdso_enabled is not permitted to set the value more than 1.
> It does not matter, because according to the function load_vdso32(),
> only vdso_enabled is set to 1, VDSO would be enabled. Other values
> all mean "disabled". The same limitation could be seen in the
> function vdso32_setup().
>
> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
> Reviewed-by: Kees Cook <kees@kernel.org>
> ---
> v4:
>  - const qualify struct ctl_table vdso_table
> ---
> ---
>  arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
>  kernel/sysctl.c                    |  8 +-------
>  2 files changed, 12 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
> index 76e4e74f35b5..f71625f99bf9 100644
> --- a/arch/x86/entry/vdso/vdso32-setup.c
> +++ b/arch/x86/entry/vdso/vdso32-setup.c
> @@ -51,15 +51,17 @@ __setup("vdso32=", vdso32_setup);
>  __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
>  #endif
>
> -#ifdef CONFIG_X86_64
>
>  #ifdef CONFIG_SYSCTL
> -/* Register vsyscall32 into the ABI table */
>  #include <linux/sysctl.h>
>
> -static struct ctl_table abi_table2[] = {
> +static const struct ctl_table vdso_table[] = {
>         {
> +#ifdef CONFIG_X86_64
>                 .procname       = "vsyscall32",
> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))

vdso32-setup,.c is not used when building UML, so this can be reduced
to "#else".

> +               .procname       = "vdso_enabled",
> +#endif
>                 .data           = &vdso32_enabled,
>                 .maxlen         = sizeof(int),
>                 .mode           = 0644,
> @@ -71,10 +73,14 @@ static struct ctl_table abi_table2[] = {
>
>  static __init int ia32_binfmt_init(void)
>  {
> -       register_sysctl("abi", abi_table2);
> +#ifdef CONFIG_X86_64
> +       /* Register vsyscall32 into the ABI table */
> +       register_sysctl("abi", vdso_table);
> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))

Same as above.



> +       register_sysctl_init("vm", vdso_table);
> +#endif
>         return 0;
>  }
>  __initcall(ia32_binfmt_init);
>  #endif /* CONFIG_SYSCTL */
>
> -#endif /* CONFIG_X86_64 */


Brian Gerst
yukaixiong Dec. 30, 2024, 3:02 a.m. UTC | #2
On 2024/12/30 7:05, Brian Gerst wrote:
> On Sat, Dec 28, 2024 at 10:17 AM Kaixiong Yu <yukaixiong@huawei.com> wrote:
>> When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
>> vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
>> So, move it into its own file.
>>
>> Before this patch, vdso_enabled was allowed to be set to
>> a value exceeding 1 on x86_32 architecture. After this patch is
>> applied, vdso_enabled is not permitted to set the value more than 1.
>> It does not matter, because according to the function load_vdso32(),
>> only vdso_enabled is set to 1, VDSO would be enabled. Other values
>> all mean "disabled". The same limitation could be seen in the
>> function vdso32_setup().
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
>> Reviewed-by: Kees Cook <kees@kernel.org>
>> ---
>> v4:
>>   - const qualify struct ctl_table vdso_table
>> ---
>> ---
>>   arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
>>   kernel/sysctl.c                    |  8 +-------
>>   2 files changed, 12 insertions(+), 12 deletions(-)
>>
>> diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
>> index 76e4e74f35b5..f71625f99bf9 100644
>> --- a/arch/x86/entry/vdso/vdso32-setup.c
>> +++ b/arch/x86/entry/vdso/vdso32-setup.c
>> @@ -51,15 +51,17 @@ __setup("vdso32=", vdso32_setup);
>>   __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
>>   #endif
>>
>> -#ifdef CONFIG_X86_64
>>
>>   #ifdef CONFIG_SYSCTL
>> -/* Register vsyscall32 into the ABI table */
>>   #include <linux/sysctl.h>
>>
>> -static struct ctl_table abi_table2[] = {
>> +static const struct ctl_table vdso_table[] = {
>>          {
>> +#ifdef CONFIG_X86_64
>>                  .procname       = "vsyscall32",
>> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
> vdso32-setup,.c is not used when building UML, so this can be reduced
> to "#else".
I will take your advice.

Thanks.
>> +               .procname       = "vdso_enabled",
>> +#endif
>>                  .data           = &vdso32_enabled,
>>                  .maxlen         = sizeof(int),
>>                  .mode           = 0644,
>> @@ -71,10 +73,14 @@ static struct ctl_table abi_table2[] = {
>>
>>   static __init int ia32_binfmt_init(void)
>>   {
>> -       register_sysctl("abi", abi_table2);
>> +#ifdef CONFIG_X86_64
>> +       /* Register vsyscall32 into the ABI table */
>> +       register_sysctl("abi", vdso_table);
>> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
> Same as above.
>
>
I will take your advice.

Thanks.
>> +       register_sysctl_init("vm", vdso_table);
>> +#endif
>>          return 0;
>>   }
>>   __initcall(ia32_binfmt_init);
>>   #endif /* CONFIG_SYSCTL */
>>
>> -#endif /* CONFIG_X86_64 */
>
> Brian Gerst
> .
>
yukaixiong Dec. 30, 2024, 6:43 a.m. UTC | #3
On 2024/12/30 7:05, Brian Gerst wrote:
> On Sat, Dec 28, 2024 at 10:17 AM Kaixiong Yu <yukaixiong@huawei.com> wrote:
>> When CONFIG_X86_32 is defined and CONFIG_UML is not defined,
>> vdso_enabled belongs to arch/x86/entry/vdso/vdso32-setup.c.
>> So, move it into its own file.
>>
>> Before this patch, vdso_enabled was allowed to be set to
>> a value exceeding 1 on x86_32 architecture. After this patch is
>> applied, vdso_enabled is not permitted to set the value more than 1.
>> It does not matter, because according to the function load_vdso32(),
>> only vdso_enabled is set to 1, VDSO would be enabled. Other values
>> all mean "disabled". The same limitation could be seen in the
>> function vdso32_setup().
>>
>> Signed-off-by: Kaixiong Yu <yukaixiong@huawei.com>
>> Reviewed-by: Kees Cook <kees@kernel.org>
>> ---
>> v4:
>>   - const qualify struct ctl_table vdso_table
>> ---
>> ---
>>   arch/x86/entry/vdso/vdso32-setup.c | 16 +++++++++++-----
>>   kernel/sysctl.c                    |  8 +-------
>>   2 files changed, 12 insertions(+), 12 deletions(-)
>>
>> diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
>> index 76e4e74f35b5..f71625f99bf9 100644
>> --- a/arch/x86/entry/vdso/vdso32-setup.c
>> +++ b/arch/x86/entry/vdso/vdso32-setup.c
>> @@ -51,15 +51,17 @@ __setup("vdso32=", vdso32_setup);
>>   __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
>>   #endif
>>
>> -#ifdef CONFIG_X86_64
>>
>>   #ifdef CONFIG_SYSCTL
>> -/* Register vsyscall32 into the ABI table */
>>   #include <linux/sysctl.h>
>>
>> -static struct ctl_table abi_table2[] = {
>> +static const struct ctl_table vdso_table[] = {
>>          {
>> +#ifdef CONFIG_X86_64
>>                  .procname       = "vsyscall32",
>> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
> vdso32-setup,.c is not used when building UML, so this can be reduced
> to "#else".
>
>> +               .procname       = "vdso_enabled",
>> +#endif
>>                  .data           = &vdso32_enabled,
>>                  .maxlen         = sizeof(int),
>>                  .mode           = 0644,
>> @@ -71,10 +73,14 @@ static struct ctl_table abi_table2[] = {
>>
>>   static __init int ia32_binfmt_init(void)
>>   {
>> -       register_sysctl("abi", abi_table2);
>> +#ifdef CONFIG_X86_64
>> +       /* Register vsyscall32 into the ABI table */
>> +       register_sysctl("abi", vdso_table);
>> +#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
> Same as above.
>
>
>
>> +       register_sysctl_init("vm", vdso_table);
>> +#endif
>>          return 0;
>>   }
>>   __initcall(ia32_binfmt_init);
>>   #endif /* CONFIG_SYSCTL */
>>
>> -#endif /* CONFIG_X86_64 */
>
> Brian Gerst
> .
Hello all;

I want to confirm that I should send a new patch series, such as "PATCH 
v5 -next", or just modify this patch by
"git send-email -in-reply-to xxxxx",or the maintainer will fix this issue ?
diff mbox series

Patch

diff --git a/arch/x86/entry/vdso/vdso32-setup.c b/arch/x86/entry/vdso/vdso32-setup.c
index 76e4e74f35b5..f71625f99bf9 100644
--- a/arch/x86/entry/vdso/vdso32-setup.c
+++ b/arch/x86/entry/vdso/vdso32-setup.c
@@ -51,15 +51,17 @@  __setup("vdso32=", vdso32_setup);
 __setup_param("vdso=", vdso_setup, vdso32_setup, 0);
 #endif
 
-#ifdef CONFIG_X86_64
 
 #ifdef CONFIG_SYSCTL
-/* Register vsyscall32 into the ABI table */
 #include <linux/sysctl.h>
 
-static struct ctl_table abi_table2[] = {
+static const struct ctl_table vdso_table[] = {
 	{
+#ifdef CONFIG_X86_64
 		.procname	= "vsyscall32",
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+		.procname	= "vdso_enabled",
+#endif
 		.data		= &vdso32_enabled,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
@@ -71,10 +73,14 @@  static struct ctl_table abi_table2[] = {
 
 static __init int ia32_binfmt_init(void)
 {
-	register_sysctl("abi", abi_table2);
+#ifdef CONFIG_X86_64
+	/* Register vsyscall32 into the ABI table */
+	register_sysctl("abi", vdso_table);
+#elif (defined(CONFIG_X86_32) && !defined(CONFIG_UML))
+	register_sysctl_init("vm", vdso_table);
+#endif
 	return 0;
 }
 __initcall(ia32_binfmt_init);
 #endif /* CONFIG_SYSCTL */
 
-#endif	/* CONFIG_X86_64 */
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 860dea8f1587..7ff07b7560b4 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -2013,17 +2013,11 @@  static struct ctl_table kern_table[] = {
 };
 
 static struct ctl_table vm_table[] = {
-#if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
-   (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
+#if defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)
 	{
 		.procname	= "vdso_enabled",
-#ifdef CONFIG_X86_32
-		.data		= &vdso32_enabled,
-		.maxlen		= sizeof(vdso32_enabled),
-#else
 		.data		= &vdso_enabled,
 		.maxlen		= sizeof(vdso_enabled),
-#endif
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 		.extra1		= SYSCTL_ZERO,