From: Thomas Weißschuh <[email protected]>
In a future commit the proc_handlers themselves will change to
"const struct ctl_table". As a preparation for that adapt the internal
helper.
Signed-off-by: Thomas Weißschuh <[email protected]>
---
What:
Modify the arguments of utility functions within the sysctl subsystem in
preparation for the system wide commit (should look like this [5]). This
patch is picked out from Thomas's series in [6]. Note that this commit
does *not* constify any ctl_table structures.
Why:
This is part of a greater constification effort that involves several
patchsets and subsystems ([3,4,5,6]). This patchset is in preparation
to:
1. Increase safety by putting ctl_table struct objects in .rodata and
making the pointers to the proc_handler functions read only.
2. Clarify and transmit intent to API users so that it is obvious that
ctl_table object are not meant to change.
[1] [PATCH v2 00/14] ASoC: Constify local snd_sof_dsp_ops
https://lore.kernel.org/all/[email protected]
[2] [PATCH v2 00/19] backlight: Constify lcd_ops
https://lore.kernel.org/all/[email protected]
[3] [PATCH 1/4] iommu: constify pointer to bus_type
https://lore.kernel.org/all/[email protected]
[4] [PATCH 00/29] const xattr tables
https://lore.kernel.org/all/[email protected]
[5] https://lore.kernel.org/linux-mm/[email protected]/
[6] https://lore.kernel.org/all/[email protected]
Signed-off-by: Joel Granados <[email protected]>
---
include/linux/sysctl.h | 2 +-
kernel/sysctl.c | 21 +++++++++++----------
2 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
index ee7d33b89e9e..99ea26b16c0d 100644
--- a/include/linux/sysctl.h
+++ b/include/linux/sysctl.h
@@ -238,7 +238,7 @@ extern struct ctl_table_header *register_sysctl_mount_point(const char *path);
void do_sysctl_args(void);
bool sysctl_is_alias(char *param);
-int do_proc_douintvec(struct ctl_table *table, int write,
+int do_proc_douintvec(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos,
int (*conv)(unsigned long *lvalp,
unsigned int *valp,
diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index 81cc974913bb..233380f967f8 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -205,7 +205,7 @@ static int _proc_do_string(char *data, int maxlen, int write,
return 0;
}
-static void warn_sysctl_write(struct ctl_table *table)
+static void warn_sysctl_write(const struct ctl_table *table)
{
pr_warn_once("%s wrote to %s when file position was not 0!\n"
"This will not be supported in the future. To silence this\n"
@@ -223,7 +223,7 @@ static void warn_sysctl_write(struct ctl_table *table)
* handlers can ignore the return value.
*/
static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
- struct ctl_table *table)
+ const struct ctl_table *table)
{
if (!*ppos)
return false;
@@ -468,7 +468,7 @@ static int do_proc_douintvec_conv(unsigned long *lvalp,
static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
-static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
+static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table,
int write, void *buffer,
size_t *lenp, loff_t *ppos,
int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
@@ -541,7 +541,7 @@ static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
return err;
}
-static int do_proc_dointvec(struct ctl_table *table, int write,
+static int do_proc_dointvec(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos,
int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
int write, void *data),
@@ -552,7 +552,7 @@ static int do_proc_dointvec(struct ctl_table *table, int write,
}
static int do_proc_douintvec_w(unsigned int *tbl_data,
- struct ctl_table *table,
+ const struct ctl_table *table,
void *buffer,
size_t *lenp, loff_t *ppos,
int (*conv)(unsigned long *lvalp,
@@ -639,7 +639,7 @@ static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer,
return err;
}
-static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
+static int __do_proc_douintvec(void *tbl_data, const struct ctl_table *table,
int write, void *buffer,
size_t *lenp, loff_t *ppos,
int (*conv)(unsigned long *lvalp,
@@ -675,7 +675,7 @@ static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
}
-int do_proc_douintvec(struct ctl_table *table, int write,
+int do_proc_douintvec(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos,
int (*conv)(unsigned long *lvalp,
unsigned int *valp,
@@ -1023,8 +1023,9 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
}
#endif
-static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
- int write, void *buffer, size_t *lenp, loff_t *ppos,
+static int __do_proc_doulongvec_minmax(void *data,
+ const struct ctl_table *table, int write,
+ void *buffer, size_t *lenp, loff_t *ppos,
unsigned long convmul, unsigned long convdiv)
{
unsigned long *i, *min, *max;
@@ -1096,7 +1097,7 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table,
return err;
}
-static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
+static int do_proc_doulongvec_minmax(const struct ctl_table *table, int write,
void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul,
unsigned long convdiv)
{
---
base-commit: a38297e3fb012ddfa7ce0321a7e5a8daeb1872b6
change-id: 20240513-jag-constfy_sysctl_proc_args-41e0aa357303
Best regards,
--
Joel Granados <[email protected]>
On Mon, May 13, 2024 at 11:25:18AM +0200, Joel Granados via B4 Relay wrote:
> From: Thomas Wei?schuh <[email protected]>
>
> In a future commit the proc_handlers themselves will change to
> "const struct ctl_table". As a preparation for that adapt the internal
> helper.
>
> Signed-off-by: Thomas Wei?schuh <[email protected]>
Yup, looks good. At what point is this safe to apply to Linus's tree?
i.e. what prerequisite patches need to land before this?
Reviewed-by: Kees Cook <[email protected]>
--
Kees Cook
On Mon, May 13, 2024 at 12:47:07PM -0700, Kees Cook wrote:
> On Mon, May 13, 2024 at 11:25:18AM +0200, Joel Granados via B4 Relay wrote:
> > From: Thomas Wei?schuh <[email protected]>
> >
> > In a future commit the proc_handlers themselves will change to
> > "const struct ctl_table". As a preparation for that adapt the internal
> > helper.
> >
> > Signed-off-by: Thomas Wei?schuh <[email protected]>
>
> Yup, looks good. At what point is this safe to apply to Linus's tree?
> i.e. what prerequisite patches need to land before this?
I was planning to queue this for v6.11. I expect the other patches (1/11 - 9/11)
will make it to mainline at that point.
This patchset has no dependencies and can easily go into v6.11 as it is trivial,
the generated assember (in x86_64 at least) is unchanged and it has been tested
it in 0-day.
>
> Reviewed-by: Kees Cook <[email protected]>
>
> --
> Kees Cook
--
Joel Granados