]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
sysctl: allow registration of const struct ctl_table
authorThomas Weißschuh <linux@weissschuh.net>
Mon, 5 Aug 2024 09:39:38 +0000 (11:39 +0200)
committerJoel Granados <joel.granados@kernel.org>
Wed, 9 Oct 2024 11:39:11 +0000 (13:39 +0200)
Putting structure, especially those containing function pointers,
into read-only memory makes the safer and easier to reason about.
Change the sysctl registration APIs to allow registration of
"const struct ctl_table".

Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Acked-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Kees Cook <keescook@chromium.org> # security/*
Signed-off-by: Joel Granados <joel.granados@kernel.org>
fs/proc/proc_sysctl.c
include/linux/sysctl.h

index 713abccbfcf9c20cc9304d878ecd1dfafcff3f35..968f8dcffd8f193bb573706c36d83626b4e9d183 100644 (file)
@@ -1359,7 +1359,7 @@ static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path)
  */
 struct ctl_table_header *__register_sysctl_table(
        struct ctl_table_set *set,
-       const char *path, struct ctl_table *table, size_t table_size)
+       const char *path, const struct ctl_table *table, size_t table_size)
 {
        struct ctl_table_root *root = set->dir.header.root;
        struct ctl_table_header *header;
@@ -1420,7 +1420,7 @@ fail:
  *
  * See __register_sysctl_table for more details.
  */
-struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
+struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table,
                                            size_t table_size)
 {
        return __register_sysctl_table(&sysctl_table_root.default_set,
@@ -1449,7 +1449,7 @@ EXPORT_SYMBOL(register_sysctl_sz);
  *
  * Context: if your base directory does not exist it will be created for you.
  */
-void __init __register_sysctl_init(const char *path, struct ctl_table *table,
+void __init __register_sysctl_init(const char *path, const struct ctl_table *table,
                                 const char *table_name, size_t table_size)
 {
        struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size);
index a473deaf5a911418df01fe32a64781854f3007c6..202855befa8bb4d789360444724da58882e4b650 100644 (file)
@@ -223,13 +223,13 @@ extern void retire_sysctl_set(struct ctl_table_set *set);
 
 struct ctl_table_header *__register_sysctl_table(
        struct ctl_table_set *set,
-       const char *path, struct ctl_table *table, size_t table_size);
-struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
+       const char *path, const struct ctl_table *table, size_t table_size);
+struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table,
                                            size_t table_size);
 void unregister_sysctl_table(struct ctl_table_header * table);
 
 extern int sysctl_init_bases(void);
-extern void __register_sysctl_init(const char *path, struct ctl_table *table,
+extern void __register_sysctl_init(const char *path, const struct ctl_table *table,
                                 const char *table_name, size_t table_size);
 #define register_sysctl_init(path, table)      \
        __register_sysctl_init(path, table, #table, ARRAY_SIZE(table))
@@ -251,7 +251,7 @@ extern int no_unaligned_warning;
 
 #else /* CONFIG_SYSCTL */
 
-static inline void register_sysctl_init(const char *path, struct ctl_table *table)
+static inline void register_sysctl_init(const char *path, const struct ctl_table *table)
 {
 }
 
@@ -261,7 +261,7 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p
 }
 
 static inline struct ctl_table_header *register_sysctl_sz(const char *path,
-                                                         struct ctl_table *table,
+                                                         const struct ctl_table *table,
                                                          size_t table_size)
 {
        return NULL;