Commit Graph
855 Commits
Author SHA1 Message Date
Mark Brown 647a365c9a Merge branch 'sysctl-next' of https://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl.git 2026-07-31 16:35:34 +01:00
Oleg NesterovandAndrew Morton 67dc06b843 sysctl: remove CONFIG_PROC_SYSCTL, it just mirrors CONFIG_SYSCTL
CONFIG_SYSCTL used to make sense as a separate hidden bool before commit
61a47c1ad3 ("sysctl: Remove the sysctl system call"); it was selected by
both CONFIG_SYSCTL_SYSCALL and CONFIG_PROC_SYSCTL.

Today CONFIG_PROC_SYSCTL is the only selector, so the two are always
equal.  Kill the hidden bool, rename the PROC_SYSCTL prompt to SYSCTL, and
s/CONFIG_PROC_SYSCTL/CONFIG_SYSCTL/ tree-wide.

Link: https://lore.kernel.org/amdveg1m4E4uQlGv@redhat.com
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Alexey Gladkov (Intel) <legion@kernel.org>
Cc: Balbir Singh <bsingharora@gmail.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Eric Biederman <ebiederm@xmission.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jakub Kacinski <kuba@kernel.org>
Cc: Jason A. Donenfeld <jason@zx2c4.com>
Cc: Joel Granados <joel.granados@kernel.org>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Nathan Chancellor <nathan@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Yang Yang <yang.yang29@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2026-07-30 19:50:15 -07:00
Randy DunlapandJoel Granados dccde188b7 sysctl: add Returns: kernel-doc for all functions
Fix kernel-doc warnings in kernel/sysctl.c by adding Returns.

Signed-off-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados 48eacddbd3 sysctl: Replace do_proc_typevec macro with do_proc_vec function
Replace macro with a single runtime static function, do_proc_vec(),
parameterised by proc_vec_type enum which defines the type being
processed and selects which converter is "live". Signedness and size are
calculated based on proc_vec_type and table->data is now walked as raw
bytes and advanced by the element size; the converter still performs the
actual typed load/store.

Pass converter as a union to avoid a cast from void*. The public
proc_do{int,uint,ulong}vec_conv() prototypes and all converter
signatures in kernel/, fs/ and the header are therefore unchanged.

Moving away from a macro makes debugging easier. No functional change
intended.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados ca1771eef6 sysctl: Update API function documentation
Add colon ":" after argument name where it is missing
Add doc for proc_int_conv and proc_dointvec_conv

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados 38f8bf3859 sysctl: Rename proc_doulongvec_minmax_conv to proc_doulongvec_conv
Remove "_minmax" from proc_doulongvec_minmax_conv as it does not enforce
min/max limits but serves as a generic converter for unsigned long
vectors. Update function declaration in sysctl.h, definition in
sysctl.c, and caller in jiffies.c accordingly.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados 3d41d334de sysctl: Rename do_proc_dotypevec macro to do_proc_typevec
Remove the do..do from the proc vector functions. The redundant "do"
only adds confusion to the already large amount of functions in sysctl.c

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados 8ff8fbfc6a sysctl: Generate do_proc_douintvec with a type-generic macro
Generate the behavior in do_proc_douintvec{,_w,_r} functions with
do_proc_dotypevec(uint). The originals (do_proc_douintvec{,_w,_r})
where created in the same way as do_proc_dotypevec but for individual
values (no vectors). In this commit we use the existing macro
implementation to extend do_proc_douintvec to include vectors of values.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados c27eb1e1c3 sysctl: Add negp parameter to douintvec converter functions
Updates all douintvec converter function signatures to include a bool
*negp parameter. This is a preparation commit required to eventually
generate do_proc_douintvec with a macro. The negp argument will be
ignored as it is not relevant for the uint type. Note that
do_proc_uint_conv_pipe_maxsz in pipe.c is also modified.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:30 +02:00
Joel Granados a3c70a5a9f sysctl: Generate do_proc_doulongvec_minmax with do_proc_dotypevec macro
The existing do_proc_doulongvec_minmax conversions (based on conv{mul,div})
are replaced with a call to a converter callback that is passed by the
caller.

Replace the values (HZ, 1000l) passed to proc_doulongvec_minmax_conv in
jiffies.c with a new callback containing millisecond to jiffie
conversion (do_proc_ulong_conv_ms_jiffies). This effectively changes the
simple calculation based on HZ and 1000l to a more robust conversion
based on  {_,}_msecs_to_jiffies.

Change specifics
================
* sysctl.h API
 - Implement new ulong uni & bi-directional converters (proc_ulong_*);
   export them so they can be used in proc_doulongvec_ms_jiffies_minmax
   (jiffies.c).
 - Replace two arguments (conv{mul,div}) in proc_doulongvec_minmax_conv
   with a general converter callback function that will be forwarded to
   do_proc_doulongvec.

* do_proc_doulongvec
 - Replace the hardcoded uni-directional converters with a call to the
   call back converter function
 - Generate do_proc_doulongvec with do_proc_dotypevec macro
 - Rename do_proc_doulongvec_minmax to do_proc_doulongvec

* jiffies
 - Create uni and bi-directional converters for milliseconds to jiffies
   (sysctl_{u2k,k2u}_ulong_conv_ms, do_proc_ulong_conv_ms_jiffies)
 - Pass the new bi-directional converter to proc_doulongvec_minmax_conv.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:29 +02:00
Joel Granados 566863476f sysctl: Replace do_proc_dointvec with a type-generic macro
Replaces do_proc_dointvec with do_proc_dotypevec macro. For now, it only
generates the integer function, but it will bring together the logic for
int, uint and ulong proc vector functions. It is parametrized on the
kernel pointer type being processed and generates a "do_proc_do##T##vec"
(where T is the type) function. The parametrization is needed for
advancing the for loop with "++" and affects the type of the k_ptr
argument in the converter call back function.

Initialize the neg variable to false to ensure that unsigned types do
not inadvertently assign negative values to user space. Return an
-EINVAL when user space tries to assign a negative value to an unsigned
variable. Add a comment to clarify that the macro is **not** designed to
be exported outside of sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:29 +02:00
Joel Granados d0eedf17d0 sysctl: Move default converter assignment out of do_proc_dointvec
Move the converter assignment out of do_proc_dointvec into the caller.
Both the test for NULL and the assignment are meant to stay within the
sysctl.c context. This is in preparation of using a typed macro to for
the integer proc vector function.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-07-08 13:12:29 +02:00
Marc BuergandJoel Granados f63a9df7e3 sysctl: fix uninitialized variable in proc_do_large_bitmap
proc_do_large_bitmap() does not initialize variable c, which is expected
to be set to a trailing character by proc_get_long().

However, proc_get_long() only sets c when the input buffer contains a
trailing character after the parsed value.

If c is not initialized it may happen to contain a '-'. If this is the
case proc_do_large_bitmap() expects to be able to parse a second part of
the input buffer. If there is no second part an unjustified -EINVAL will
be returned.

Initialize c to 0 to prevent returning -EINVAL on valid input.

Fixes: 9f977fb7ae ("sysctl: add proc_do_large_bitmap")
Signed-off-by: Marc Buerg <buermarc@googlemail.com>
Reviewed-by: Joel Granados <joel.granados@kernel.org>
Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-03-26 09:32:19 +01:00
Joel Granados d174174c67 sysctl: replace SYSCTL_INT_CONV_CUSTOM macro with functions
Remove SYSCTL_INT_CONV_CUSTOM and replace it with proc_int_conv. This
converter function expects a negp argument as it can take on negative
values. Update all jiffies converters to use explicit function calls.
Remove SYSCTL_CONV_IDENTITY as it is no longer used.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-06 11:27:10 +01:00
Joel Granados ef153851af sysctl: Replace unidirectional INT converter macros with functions
Replace SYSCTL_USER_TO_KERN_INT_CONV and SYSCTL_KERN_TO_USER_INT_CONV
macros with function implementing the same logic.This makes debugging
easier and aligns with the functions preference described in
coding-style.rst. Update all jiffies converters to use explicit function
implementations instead of macro-generated versions.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-06 11:26:42 +01:00
Joel Granados b3af263b8a sysctl: Add kernel doc to proc_douintvec_conv
This commit is making sure that all the functions that are part of the
API are documented.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-05 14:10:32 +01:00
Joel Granados 8fc344a5af sysctl: Replace UINT converter macros with functions
Replace the SYSCTL_USER_TO_KERN_UINT_CONV and SYSCTL_UINT_CONV_CUSTOM
macros with functions with the same logic. This makes debugging easier
and aligns with the functions preference described in coding-style.rst.
Update the only user of this API: pipe.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-05 14:10:32 +01:00
Joel Granados ac3d6a4b60 sysctl: clarify proc_douintvec_minmax doc
Specify that the range check is only when assigning kernel variable

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-05 14:10:32 +01:00
Joel Granados 11400f86c2 sysctl: Return -ENOSYS from proc_douintvec_conv when CONFIG_PROC_SYSCTL=n
Ensure an error if prco_douintvec_conv is erroneously called in a system
with CONFIG_PROC_SYSCTL=n

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-05 14:10:32 +01:00
Joel Granados 4864010524 sysctl: Add missing kernel-doc for proc_dointvec_conv
Add kernel-doc documentation for the proc_dointvec_conv function to
describe its parameters and return value.

Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Joel Granados <joel.granados@kernel.org>
2026-01-05 13:36:45 +01:00
Joel Granados 564195c1a3 sysctl: Wrap do_proc_douintvec with the public function proc_douintvec_conv
Make do_proc_douintvec static and export proc_douintvec_conv wrapper
function for external use. This is to keep with the design in sysctl.c.
Update fs/pipe.c to use the new public API.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2025-11-27 15:45:38 +01:00
Joel Granados 30baaeb685 sysctl: Create pipe-max-size converter using sysctl UINT macros
Create a converter for the pipe-max-size proc_handler using the
SYSCTL_UINT_CONV_CUSTOM. Move SYSCTL_CONV_IDENTITY macro to the sysctl
header to make it available for pipe size validation. Keep returning
-EINVAL when (val == 0) by using a range checking converter and setting
the minimal valid value (extern1) to SYSCTL_ONE. Keep round_pipe_size by
passing it as the operation for SYSCTL_USER_TO_KERN_INT_CONV.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2025-11-27 15:45:37 +01:00
Joel Granados 4639faaa60 sysctl: Move proc_doulongvec_ms_jiffies_minmax to kernel/time/jiffies.c
Move proc_doulongvec_ms_jiffies_minmax to kernel/time/jiffies.c. Create
a non static wrapper function proc_doulongvec_minmax_conv that
forwards the custom convmul and convdiv argument values to the internal
do_proc_doulongvec_minmax. Remove unused linux/times.h include from
kernel/sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2025-11-27 15:45:37 +01:00
Joel Granados 54932988c4 sysctl: Move jiffies converters to kernel/time/jiffies.c
Move integer jiffies converters (proc_dointvec{_,_ms_,_userhz_}jiffies
and proc_dointvec_ms_jiffies_minmax) to kernel/time/jiffies.c. Error
stubs for when CONFIG_PRCO_SYSCTL is not defined are not reproduced
because all the jiffies converters go through proc_dointvec_conv which
is already stubbed. This is part of the greater effort to move sysctl
logic out of kernel/sysctl.c thereby reducing merge conflicts in
kernel/sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2025-11-27 15:45:37 +01:00
Joel Granados 24a08eefdd sysctl: Move UINT converter macros to sysctl header
Move SYSCTL_USER_TO_KERN_UINT_CONV and SYSCTL_UINT_CONV_CUSTOM macros to
include/linux/sysctl.h. No need to embed sysctl_kern_to_user_uint_conv
in a macro as it will not need a custom kernel pointer operation. This
is a preparation commit to enable jiffies converter creation outside
kernel/sysctl.c.

Signed-off-by: Joel Granados <joel.granados@kernel.org>
2025-11-27 15:45:37 +01:00