Skip to content

Commit 91b6163

Browse files
committed
Merge tag 'sysctl-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl
Pull sysctl updates from Joel Granados: - Remove sentinel elements from ctl_table structs in kernel/* Removing sentinels in ctl_table arrays reduces the build time size and runtime memory consumed by ~64 bytes per array. Removals for net/, io_uring/, mm/, ipc/ and security/ are set to go into mainline through their respective subsystems making the next release the most likely place where the final series that removes the check for proc_name == NULL will land. This adds to removals already in arch/, drivers/ and fs/. - Adjust ctl_table definitions and references to allow constification - Remove unused ctl_table function arguments - Move non-const elements from ctl_table to ctl_table_header - Make ctl_table pointers const in ctl_table_root structure Making the static ctl_table structs const will increase safety by keeping the pointers to proc_handler functions in .rodata. Though no ctl_tables where made const in this PR, the ground work for making that possible has started with these changes sent by Thomas Weißschuh. * tag 'sysctl-6.10-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/sysctl/sysctl: sysctl: drop now unnecessary out-of-bounds check sysctl: move sysctl type to ctl_table_header sysctl: drop sysctl_is_perm_empty_ctl_table sysctl: treewide: constify argument ctl_table_root::permissions(table) sysctl: treewide: drop unused argument ctl_table_root::set_ownership(table) bpf: Remove the now superfluous sentinel elements from ctl_table array delayacct: Remove the now superfluous sentinel elements from ctl_table array kprobes: Remove the now superfluous sentinel elements from ctl_table array printk: Remove the now superfluous sentinel elements from ctl_table array scheduler: Remove the now superfluous sentinel elements from ctl_table array seccomp: Remove the now superfluous sentinel elements from ctl_table array timekeeping: Remove the now superfluous sentinel elements from ctl_table array ftrace: Remove the now superfluous sentinel elements from ctl_table array umh: Remove the now superfluous sentinel elements from ctl_table array kernel misc: Remove the now superfluous sentinel elements from ctl_table array
2 parents 06f054b + a35dd3a commit 91b6163

35 files changed

+28
-67
lines changed

fs/proc/proc_sysctl.c

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ static const struct file_operations proc_sys_dir_file_operations;
3030
static const struct inode_operations proc_sys_dir_operations;
3131

3232
/* Support for permanently empty directories */
33-
static struct ctl_table sysctl_mount_point[] = {
34-
{.type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY }
35-
};
33+
static struct ctl_table sysctl_mount_point[] = { };
3634

3735
/**
3836
* register_sysctl_mount_point() - registers a sysctl mount point
@@ -48,14 +46,12 @@ struct ctl_table_header *register_sysctl_mount_point(const char *path)
4846
}
4947
EXPORT_SYMBOL(register_sysctl_mount_point);
5048

51-
#define sysctl_is_perm_empty_ctl_table(tptr) \
52-
(tptr[0].type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
5349
#define sysctl_is_perm_empty_ctl_header(hptr) \
54-
(sysctl_is_perm_empty_ctl_table(hptr->ctl_table))
50+
(hptr->type == SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
5551
#define sysctl_set_perm_empty_ctl_header(hptr) \
56-
(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
52+
(hptr->type = SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY)
5753
#define sysctl_clear_perm_empty_ctl_header(hptr) \
58-
(hptr->ctl_table[0].type = SYSCTL_TABLE_TYPE_DEFAULT)
54+
(hptr->type = SYSCTL_TABLE_TYPE_DEFAULT)
5955

6056
void proc_sys_poll_notify(struct ctl_table_poll *poll)
6157
{
@@ -210,6 +206,8 @@ static void init_header(struct ctl_table_header *head,
210206
node++;
211207
}
212208
}
209+
if (table == sysctl_mount_point)
210+
sysctl_set_perm_empty_ctl_header(head);
213211
}
214212

215213
static void erase_header(struct ctl_table_header *head)
@@ -232,8 +230,7 @@ static int insert_header(struct ctl_dir *dir, struct ctl_table_header *header)
232230
return -EROFS;
233231

234232
/* Am I creating a permanently empty directory? */
235-
if (header->ctl_table_size > 0 &&
236-
sysctl_is_perm_empty_ctl_table(header->ctl_table)) {
233+
if (sysctl_is_perm_empty_ctl_header(header)) {
237234
if (!RB_EMPTY_ROOT(&dir->root))
238235
return -EINVAL;
239236
sysctl_set_perm_empty_ctl_header(dir_h);
@@ -480,7 +477,7 @@ static struct inode *proc_sys_make_inode(struct super_block *sb,
480477
}
481478

482479
if (root->set_ownership)
483-
root->set_ownership(head, table, &inode->i_uid, &inode->i_gid);
480+
root->set_ownership(head, &inode->i_uid, &inode->i_gid);
484481
else {
485482
inode->i_uid = GLOBAL_ROOT_UID;
486483
inode->i_gid = GLOBAL_ROOT_GID;
@@ -1204,7 +1201,7 @@ static bool get_links(struct ctl_dir *dir,
12041201
struct ctl_table *entry, *link;
12051202

12061203
if (header->ctl_table_size == 0 ||
1207-
sysctl_is_perm_empty_ctl_table(header->ctl_table))
1204+
sysctl_is_perm_empty_ctl_header(header))
12081205
return true;
12091206

12101207
/* Are there links available for every entry in table? */

include/linux/sysctl.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,6 @@ struct ctl_table {
137137
void *data;
138138
int maxlen;
139139
umode_t mode;
140-
/**
141-
* enum type - Enumeration to differentiate between ctl target types
142-
* @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
143-
* @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
144-
* empty directory target to serve
145-
* as mount point.
146-
*/
147-
enum {
148-
SYSCTL_TABLE_TYPE_DEFAULT,
149-
SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY
150-
} type;
151140
proc_handler *proc_handler; /* Callback for text formatting */
152141
struct ctl_table_poll *poll;
153142
void *extra1;
@@ -188,6 +177,17 @@ struct ctl_table_header {
188177
struct ctl_dir *parent;
189178
struct ctl_node *node;
190179
struct hlist_head inodes; /* head for proc_inode->sysctl_inodes */
180+
/**
181+
* enum type - Enumeration to differentiate between ctl target types
182+
* @SYSCTL_TABLE_TYPE_DEFAULT: ctl target with no special considerations
183+
* @SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY: Used to identify a permanently
184+
* empty directory target to serve
185+
* as mount point.
186+
*/
187+
enum {
188+
SYSCTL_TABLE_TYPE_DEFAULT,
189+
SYSCTL_TABLE_TYPE_PERMANENTLY_EMPTY,
190+
} type;
191191
};
192192

193193
struct ctl_dir {
@@ -205,9 +205,8 @@ struct ctl_table_root {
205205
struct ctl_table_set default_set;
206206
struct ctl_table_set *(*lookup)(struct ctl_table_root *root);
207207
void (*set_ownership)(struct ctl_table_header *head,
208-
struct ctl_table *table,
209208
kuid_t *uid, kgid_t *gid);
210-
int (*permissions)(struct ctl_table_header *head, struct ctl_table *table);
209+
int (*permissions)(struct ctl_table_header *head, const struct ctl_table *table);
211210
};
212211

213212
#define register_sysctl(path, table) \

ipc/ipc_sysctl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ static int set_is_seen(struct ctl_table_set *set)
192192
}
193193

194194
static void ipc_set_ownership(struct ctl_table_header *head,
195-
struct ctl_table *table,
196195
kuid_t *uid, kgid_t *gid)
197196
{
198197
struct ipc_namespace *ns =
@@ -205,7 +204,7 @@ static void ipc_set_ownership(struct ctl_table_header *head,
205204
*gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID;
206205
}
207206

208-
static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *table)
207+
static int ipc_permissions(struct ctl_table_header *head, const struct ctl_table *table)
209208
{
210209
int mode = table->mode;
211210

@@ -224,7 +223,7 @@ static int ipc_permissions(struct ctl_table_header *head, struct ctl_table *tabl
224223
kuid_t ns_root_uid;
225224
kgid_t ns_root_gid;
226225

227-
ipc_set_ownership(head, table, &ns_root_uid, &ns_root_gid);
226+
ipc_set_ownership(head, &ns_root_uid, &ns_root_gid);
228227

229228
if (uid_eq(current_euid(), ns_root_uid))
230229
mode >>= 6;

ipc/mq_sysctl.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ static int set_is_seen(struct ctl_table_set *set)
7878
}
7979

8080
static void mq_set_ownership(struct ctl_table_header *head,
81-
struct ctl_table *table,
8281
kuid_t *uid, kgid_t *gid)
8382
{
8483
struct ipc_namespace *ns =
@@ -91,13 +90,13 @@ static void mq_set_ownership(struct ctl_table_header *head,
9190
*gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID;
9291
}
9392

94-
static int mq_permissions(struct ctl_table_header *head, struct ctl_table *table)
93+
static int mq_permissions(struct ctl_table_header *head, const struct ctl_table *table)
9594
{
9695
int mode = table->mode;
9796
kuid_t ns_root_uid;
9897
kgid_t ns_root_gid;
9998

100-
mq_set_ownership(head, table, &ns_root_uid, &ns_root_gid);
99+
mq_set_ownership(head, &ns_root_uid, &ns_root_gid);
101100

102101
if (uid_eq(current_euid(), ns_root_uid))
103102
mode >>= 6;

kernel/acct.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ static struct ctl_table kern_acct_table[] = {
8484
.mode = 0644,
8585
.proc_handler = proc_dointvec,
8686
},
87-
{ }
8887
};
8988

9089
static __init int kernel_acct_sysctls_init(void)

kernel/bpf/syscall.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6035,7 +6035,6 @@ static struct ctl_table bpf_syscall_table[] = {
60356035
.mode = 0644,
60366036
.proc_handler = bpf_stats_handler,
60376037
},
6038-
{ }
60396038
};
60406039

60416040
static int __init bpf_syscall_sysctl_init(void)

kernel/delayacct.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ static struct ctl_table kern_delayacct_table[] = {
7474
.extra1 = SYSCTL_ZERO,
7575
.extra2 = SYSCTL_ONE,
7676
},
77-
{ }
7877
};
7978

8079
static __init int kernel_delayacct_sysctls_init(void)

kernel/exit.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ static struct ctl_table kern_exit_table[] = {
9494
.mode = 0644,
9595
.proc_handler = proc_douintvec,
9696
},
97-
{ }
9897
};
9998

10099
static __init int kernel_exit_sysctls_init(void)

kernel/hung_task.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ static struct ctl_table hung_task_sysctls[] = {
314314
.proc_handler = proc_dointvec_minmax,
315315
.extra1 = SYSCTL_NEG_ONE,
316316
},
317-
{}
318317
};
319318

320319
static void __init hung_task_sysctl_init(void)

kernel/kexec_core.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,6 @@ static struct ctl_table kexec_core_sysctls[] = {
948948
.mode = 0644,
949949
.proc_handler = kexec_limit_handler,
950950
},
951-
{ }
952951
};
953952

954953
static int __init kexec_core_sysctl_init(void)

0 commit comments

Comments
 (0)