]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
sysctl: Create pipe-max-size converter using sysctl UINT macros
authorJoel Granados <joel.granados@kernel.org>
Tue, 14 Oct 2025 12:21:03 +0000 (14:21 +0200)
committerJoel Granados <joel.granados@kernel.org>
Thu, 27 Nov 2025 14:45:37 +0000 (15:45 +0100)
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>
fs/pipe.c
include/linux/sysctl.h
kernel/sysctl.c

index 9411d4fc2f4399eb30f1e8bf814a115b6d853721..f1b3d1154ad22d81fc7c2ec85fa0df35a7b7c9dd 100644 (file)
--- a/fs/pipe.c
+++ b/fs/pipe.c
@@ -1481,31 +1481,16 @@ static struct file_system_type pipe_fs_type = {
 };
 
 #ifdef CONFIG_SYSCTL
-static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
-                                       unsigned int *valp, int write,
-                                       const struct ctl_table *table)
-{
-       if (write) {
-               unsigned int val;
-
-               val = round_pipe_size(*lvalp);
-               if (val == 0)
-                       return -EINVAL;
-
-               *valp = val;
-       } else {
-               unsigned int val = *valp;
-               *lvalp = (unsigned long) val;
-       }
-
-       return 0;
-}
+static SYSCTL_USER_TO_KERN_UINT_CONV(_pipe_maxsz, round_pipe_size)
+static SYSCTL_UINT_CONV_CUSTOM(_pipe_maxsz,
+                              sysctl_user_to_kern_uint_conv_pipe_maxsz,
+                              sysctl_kern_to_user_uint_conv, true)
 
 static int proc_dopipe_max_size(const struct ctl_table *table, int write,
                                void *buffer, size_t *lenp, loff_t *ppos)
 {
        return do_proc_douintvec(table, write, buffer, lenp, ppos,
-                                do_proc_dopipe_max_size_conv);
+                                do_proc_uint_conv_pipe_maxsz);
 }
 
 static const struct ctl_table fs_pipe_sysctls[] = {
@@ -1515,6 +1500,7 @@ static const struct ctl_table fs_pipe_sysctls[] = {
                .maxlen         = sizeof(pipe_max_size),
                .mode           = 0644,
                .proc_handler   = proc_dopipe_max_size,
+               .extra1         = SYSCTL_ONE,
        },
        {
                .procname       = "pipe-user-pages-hard",
index 30f6a184d3f46ffe8ca74fd0e2d73887dc7bce75..4c88514a7d1a5a37b319e13842b004b5462d8bb1 100644 (file)
@@ -59,6 +59,7 @@ extern const int sysctl_vals[];
 #define SYSCTL_LONG_ONE                ((void *)&sysctl_long_vals[1])
 #define SYSCTL_LONG_MAX                ((void *)&sysctl_long_vals[2])
 
+#define SYSCTL_CONV_IDENTITY(val) (val)
 /**
  *
  * "dir" originates from read_iter (dir = 0) or write_iter (dir = 1)
index 998400323ae96469783c086d1f1f552eddb58df1..d09c6602a1150240a1ce9049c8da96bfc87d5105 100644 (file)
@@ -354,8 +354,6 @@ static void proc_put_char(void **buf, size_t *size, char c)
        }
 }
 
-#define SYSCTL_CONV_IDENTITY(val) val
-
 static SYSCTL_USER_TO_KERN_INT_CONV(, SYSCTL_CONV_IDENTITY)
 static SYSCTL_KERN_TO_USER_INT_CONV(, SYSCTL_CONV_IDENTITY)