[1/8] sysctl: introduce sysctl SYSCTL_U8_MAX and SYSCTL_LONG_S32_MAX

Message ID tencent_95D22FF919A42A99DA3C886B322CBD983905@qq.com
State New
Headers
Series [1/8] sysctl: introduce sysctl SYSCTL_U8_MAX and SYSCTL_LONG_S32_MAX |

Commit Message

Wen Yang Feb. 25, 2024, 4:05 a.m. UTC
  From: Wen Yang <wenyang.linux@foxmail.com>

The boundary check of multiple modules uses these static variables (such as
two_five_five, n_65535, ue_int_max, etc), and they are also not changed.
Therefore, add them to the shared sysctl_vals and sysctl_long_vals to avoid
duplication.

Also rearranged sysctl_vals and sysctl_long_vals in numerical order.

Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
Cc: Luis Chamberlain <mcgrof@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: Joel Granados <j.granados@samsung.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: David Ahern <dsahern@kernel.org>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
 include/linux/sysctl.h | 15 +++++++++------
 kernel/sysctl.c        |  4 ++--
 2 files changed, 11 insertions(+), 8 deletions(-)
  

Comments

Joel Granados Feb. 25, 2024, 8:16 p.m. UTC | #1
On Sun, Feb 25, 2024 at 12:05:31PM +0800, wenyang.linux@foxmail.com wrote:
> From: Wen Yang <wenyang.linux@foxmail.com>
> 
> The boundary check of multiple modules uses these static variables (such as
> two_five_five, n_65535, ue_int_max, etc), and they are also not changed.
> Therefore, add them to the shared sysctl_vals and sysctl_long_vals to avoid
> duplication.
> 
> Also rearranged sysctl_vals and sysctl_long_vals in numerical order.
> 
> Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
> Cc: Luis Chamberlain <mcgrof@kernel.org>
> Cc: Kees Cook <keescook@chromium.org>
> Cc: Joel Granados <j.granados@samsung.com>
> Cc: Christian Brauner <brauner@kernel.org>
> Cc: "David S. Miller" <davem@davemloft.net>
> Cc: David Ahern <dsahern@kernel.org>
> Cc: Eric Dumazet <edumazet@google.com>
> Cc: Jakub Kicinski <kuba@kernel.org>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: netdev@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  include/linux/sysctl.h | 15 +++++++++------
>  kernel/sysctl.c        |  4 ++--
>  2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
> index ee7d33b89e9e..b7a13e4c411c 100644
> --- a/include/linux/sysctl.h
> +++ b/include/linux/sysctl.h
> @@ -45,19 +45,22 @@ struct ctl_dir;
>  #define SYSCTL_FOUR			((void *)&sysctl_vals[4])
>  #define SYSCTL_ONE_HUNDRED		((void *)&sysctl_vals[5])
>  #define SYSCTL_TWO_HUNDRED		((void *)&sysctl_vals[6])
> -#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[7])
> -#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[8])
> -#define SYSCTL_INT_MAX			((void *)&sysctl_vals[9])
> +#define SYSCTL_U8_MAX			((void *)&sysctl_vals[7])
> +#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[8])
> +#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[9])
> +#define SYSCTL_U16_MAX			((void *)&sysctl_vals[10])
> +#define SYSCTL_INT_MAX			((void *)&sysctl_vals[11])
> +#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[12])
>  
>  /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
> -#define SYSCTL_MAXOLDUID		((void *)&sysctl_vals[10])
> -#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[11])
> +#define SYSCTL_MAXOLDUID		SYSCTL_U16_MAX
>  
>  extern const int sysctl_vals[];
>  
>  #define SYSCTL_LONG_ZERO	((void *)&sysctl_long_vals[0])
>  #define SYSCTL_LONG_ONE		((void *)&sysctl_long_vals[1])
> -#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[2])
> +#define SYSCTL_LONG_S32_MAX	((void *)&sysctl_long_vals[2])
> +#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[3])
>  
>  extern const unsigned long sysctl_long_vals[];
>  
> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
> index 157f7ce2942d..e1e00937cb29 100644
> --- a/kernel/sysctl.c
> +++ b/kernel/sysctl.c
> @@ -82,10 +82,10 @@
>  #endif
>  
>  /* shared constants to be used in various sysctls */
> -const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
> +const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, U8_MAX, 1000, 3000, 65535, INT_MAX, -1, };
Why do you insert the new values instead of just appending?
I figure that the patch would be much smaller if you appended.

>  EXPORT_SYMBOL(sysctl_vals);
>  
> -const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
> +const unsigned long sysctl_long_vals[] = { 0, 1, S32_MAX, LONG_MAX, };
Same here. Why insert instead of append?
>  EXPORT_SYMBOL_GPL(sysctl_long_vals);
>  
>  #if defined(CONFIG_SYSCTL)
> -- 
> 2.25.1
>
  
Wen Yang Feb. 26, 2024, 2:59 p.m. UTC | #2
On 2024/2/26 04:16, Joel Granados wrote:
> On Sun, Feb 25, 2024 at 12:05:31PM +0800, wenyang.linux@foxmail.com wrote:
>> From: Wen Yang <wenyang.linux@foxmail.com>
>>
>> The boundary check of multiple modules uses these static variables (such as
>> two_five_five, n_65535, ue_int_max, etc), and they are also not changed.
>> Therefore, add them to the shared sysctl_vals and sysctl_long_vals to avoid
>> duplication.
>>
>> Also rearranged sysctl_vals and sysctl_long_vals in numerical order.
>>
>> Signed-off-by: Wen Yang <wenyang.linux@foxmail.com>
>> Cc: Luis Chamberlain <mcgrof@kernel.org>
>> Cc: Kees Cook <keescook@chromium.org>
>> Cc: Joel Granados <j.granados@samsung.com>
>> Cc: Christian Brauner <brauner@kernel.org>
>> Cc: "David S. Miller" <davem@davemloft.net>
>> Cc: David Ahern <dsahern@kernel.org>
>> Cc: Eric Dumazet <edumazet@google.com>
>> Cc: Jakub Kicinski <kuba@kernel.org>
>> Cc: Paolo Abeni <pabeni@redhat.com>
>> Cc: netdev@vger.kernel.org
>> Cc: linux-kernel@vger.kernel.org
>> ---
>>   include/linux/sysctl.h | 15 +++++++++------
>>   kernel/sysctl.c        |  4 ++--
>>   2 files changed, 11 insertions(+), 8 deletions(-)
>>
>> diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
>> index ee7d33b89e9e..b7a13e4c411c 100644
>> --- a/include/linux/sysctl.h
>> +++ b/include/linux/sysctl.h
>> @@ -45,19 +45,22 @@ struct ctl_dir;
>>   #define SYSCTL_FOUR			((void *)&sysctl_vals[4])
>>   #define SYSCTL_ONE_HUNDRED		((void *)&sysctl_vals[5])
>>   #define SYSCTL_TWO_HUNDRED		((void *)&sysctl_vals[6])
>> -#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[7])
>> -#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[8])
>> -#define SYSCTL_INT_MAX			((void *)&sysctl_vals[9])
>> +#define SYSCTL_U8_MAX			((void *)&sysctl_vals[7])
>> +#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[8])
>> +#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[9])
>> +#define SYSCTL_U16_MAX			((void *)&sysctl_vals[10])
>> +#define SYSCTL_INT_MAX			((void *)&sysctl_vals[11])
>> +#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[12])
>>   
>>   /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
>> -#define SYSCTL_MAXOLDUID		((void *)&sysctl_vals[10])
>> -#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[11])
>> +#define SYSCTL_MAXOLDUID		SYSCTL_U16_MAX
>>   
>>   extern const int sysctl_vals[];
>>   
>>   #define SYSCTL_LONG_ZERO	((void *)&sysctl_long_vals[0])
>>   #define SYSCTL_LONG_ONE		((void *)&sysctl_long_vals[1])
>> -#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[2])
>> +#define SYSCTL_LONG_S32_MAX	((void *)&sysctl_long_vals[2])
>> +#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[3])
>>   
>>   extern const unsigned long sysctl_long_vals[];
>>   
>> diff --git a/kernel/sysctl.c b/kernel/sysctl.c
>> index 157f7ce2942d..e1e00937cb29 100644
>> --- a/kernel/sysctl.c
>> +++ b/kernel/sysctl.c
>> @@ -82,10 +82,10 @@
>>   #endif
>>   
>>   /* shared constants to be used in various sysctls */
>> -const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
>> +const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, U8_MAX, 1000, 3000, 65535, INT_MAX, -1, };
> Why do you insert the new values instead of just appending?
> I figure that the patch would be much smaller if you appended.
> 


Thanks.
We originally intended to rearrange this array in numerical order, but 
now it seems unnecessary.
We will follow your suggestions and send v2 later.

--
Best wishes,
Wen


>>   EXPORT_SYMBOL(sysctl_vals);
>>   
>> -const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
>> +const unsigned long sysctl_long_vals[] = { 0, 1, S32_MAX, LONG_MAX, };
> Same here. Why insert instead of append?
>>   EXPORT_SYMBOL_GPL(sysctl_long_vals);
>>   
>>   #if defined(CONFIG_SYSCTL)
>> -- 
>> 2.25.1
>>
>
  

Patch

diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index ee7d33b89e9e..b7a13e4c411c 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -45,19 +45,22 @@  struct ctl_dir;
 #define SYSCTL_FOUR			((void *)&sysctl_vals[4])
 #define SYSCTL_ONE_HUNDRED		((void *)&sysctl_vals[5])
 #define SYSCTL_TWO_HUNDRED		((void *)&sysctl_vals[6])
-#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[7])
-#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[8])
-#define SYSCTL_INT_MAX			((void *)&sysctl_vals[9])
+#define SYSCTL_U8_MAX			((void *)&sysctl_vals[7])
+#define SYSCTL_ONE_THOUSAND		((void *)&sysctl_vals[8])
+#define SYSCTL_THREE_THOUSAND		((void *)&sysctl_vals[9])
+#define SYSCTL_U16_MAX			((void *)&sysctl_vals[10])
+#define SYSCTL_INT_MAX			((void *)&sysctl_vals[11])
+#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[12])
 
 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
-#define SYSCTL_MAXOLDUID		((void *)&sysctl_vals[10])
-#define SYSCTL_NEG_ONE			((void *)&sysctl_vals[11])
+#define SYSCTL_MAXOLDUID		SYSCTL_U16_MAX
 
 extern const int sysctl_vals[];
 
 #define SYSCTL_LONG_ZERO	((void *)&sysctl_long_vals[0])
 #define SYSCTL_LONG_ONE		((void *)&sysctl_long_vals[1])
-#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[2])
+#define SYSCTL_LONG_S32_MAX	((void *)&sysctl_long_vals[2])
+#define SYSCTL_LONG_MAX		((void *)&sysctl_long_vals[3])
 
 extern const unsigned long sysctl_long_vals[];
 
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 157f7ce2942d..e1e00937cb29 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -82,10 +82,10 @@ 
 #endif
 
 /* shared constants to be used in various sysctls */
-const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 };
+const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, U8_MAX, 1000, 3000, 65535, INT_MAX, -1, };
 EXPORT_SYMBOL(sysctl_vals);
 
-const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX };
+const unsigned long sysctl_long_vals[] = { 0, 1, S32_MAX, LONG_MAX, };
 EXPORT_SYMBOL_GPL(sysctl_long_vals);
 
 #if defined(CONFIG_SYSCTL)