Skip to content

Commit 7abc9b5

Browse files
t-8chJoelgranados
authored andcommitted
sysctl: allow registration of const struct ctl_table
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 <[email protected]> Acked-by: Kees Cook <[email protected]> Reviewed-by: Kees Cook <[email protected]> # security/* Signed-off-by: Joel Granados <[email protected]>
1 parent 29e1095 commit 7abc9b5

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

fs/proc/proc_sysctl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ static struct ctl_dir *sysctl_mkdir_p(struct ctl_dir *dir, const char *path)
13591359
*/
13601360
struct ctl_table_header *__register_sysctl_table(
13611361
struct ctl_table_set *set,
1362-
const char *path, struct ctl_table *table, size_t table_size)
1362+
const char *path, const struct ctl_table *table, size_t table_size)
13631363
{
13641364
struct ctl_table_root *root = set->dir.header.root;
13651365
struct ctl_table_header *header;
@@ -1420,7 +1420,7 @@ struct ctl_table_header *__register_sysctl_table(
14201420
*
14211421
* See __register_sysctl_table for more details.
14221422
*/
1423-
struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
1423+
struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table,
14241424
size_t table_size)
14251425
{
14261426
return __register_sysctl_table(&sysctl_table_root.default_set,
@@ -1449,7 +1449,7 @@ EXPORT_SYMBOL(register_sysctl_sz);
14491449
*
14501450
* Context: if your base directory does not exist it will be created for you.
14511451
*/
1452-
void __init __register_sysctl_init(const char *path, struct ctl_table *table,
1452+
void __init __register_sysctl_init(const char *path, const struct ctl_table *table,
14531453
const char *table_name, size_t table_size)
14541454
{
14551455
struct ctl_table_header *hdr = register_sysctl_sz(path, table, table_size);

include/linux/sysctl.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,13 +223,13 @@ extern void retire_sysctl_set(struct ctl_table_set *set);
223223

224224
struct ctl_table_header *__register_sysctl_table(
225225
struct ctl_table_set *set,
226-
const char *path, struct ctl_table *table, size_t table_size);
227-
struct ctl_table_header *register_sysctl_sz(const char *path, struct ctl_table *table,
226+
const char *path, const struct ctl_table *table, size_t table_size);
227+
struct ctl_table_header *register_sysctl_sz(const char *path, const struct ctl_table *table,
228228
size_t table_size);
229229
void unregister_sysctl_table(struct ctl_table_header * table);
230230

231231
extern int sysctl_init_bases(void);
232-
extern void __register_sysctl_init(const char *path, struct ctl_table *table,
232+
extern void __register_sysctl_init(const char *path, const struct ctl_table *table,
233233
const char *table_name, size_t table_size);
234234
#define register_sysctl_init(path, table) \
235235
__register_sysctl_init(path, table, #table, ARRAY_SIZE(table))
@@ -251,7 +251,7 @@ extern int no_unaligned_warning;
251251

252252
#else /* CONFIG_SYSCTL */
253253

254-
static inline void register_sysctl_init(const char *path, struct ctl_table *table)
254+
static inline void register_sysctl_init(const char *path, const struct ctl_table *table)
255255
{
256256
}
257257

@@ -261,7 +261,7 @@ static inline struct ctl_table_header *register_sysctl_mount_point(const char *p
261261
}
262262

263263
static inline struct ctl_table_header *register_sysctl_sz(const char *path,
264-
struct ctl_table *table,
264+
const struct ctl_table *table,
265265
size_t table_size)
266266
{
267267
return NULL;

0 commit comments

Comments
 (0)