mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
91b6163be4
Summary * Removed 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 PR adds to removals already in arch/, drivers/ and fs/. * Adjusted ctl_table definitions and references to allow constification Adjustments: - Removing unused ctl_table function arguments - Moving non-const elements from ctl_table to ctl_table_header - Making 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. Testing * These changes went into linux-next after v6.9-rc4; giving it a good month of testing. -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEErkcJVyXmMSXOyyeQupfNUreWQU8FAmZFvBMACgkQupfNUreW QU/eGAv9EWeiXKxr3EVSMAsb9MWbJq7C99I/pd5hMf+qH4PgJpKDH7w/sb2e8h8+ unGiW83ikgrtph7OS4/xM3Y9r3Nvzd6C/OztqgMnNKeRFdMgP7wu9HaSNs05ordb CqJdhvL93quc5HxrGTS9sdLK/wLJWOHwuWMXhX4qS44JNxTdPV2q10Rb7DZyHZ6O C9qp61L2Q2CrnOBKIx8MoeCh20ynJQAo3b0pTN63ZYF4D0vqCcnYNNTPkge4ID8/ ULJoP5hAQY0vJ4g4fC4Gmooa5GECpm8MfZUf3SdgPyauqM/sm3dVdsLXAWD4Phcp TsG2a/5KMYwnLHrUGwDW7bFfEemRU88h0Iam56+SKMl1kMlEpWaLL9ApQXoHFayG e10izS+i/nlQiqYIHtuczCoTimT4/LGnonCLcdA//C3XzBT5MnOd7xsjuaQSpFWl /CV9SZa4ABwzX7u2jty8ik90iihLCFQyKj1d9m1mDVbgb6r3iUOxVuHBgMtY7MF7 eyaEmV7l =/rQW -----END PGP SIGNATURE----- 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
169 lines
3.9 KiB
C
169 lines
3.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2007 IBM Corporation
|
|
*
|
|
* Author: Cedric Le Goater <clg@fr.ibm.com>
|
|
*/
|
|
|
|
#include <linux/nsproxy.h>
|
|
#include <linux/ipc_namespace.h>
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/stat.h>
|
|
#include <linux/capability.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/cred.h>
|
|
|
|
static int msg_max_limit_min = MIN_MSGMAX;
|
|
static int msg_max_limit_max = HARD_MSGMAX;
|
|
|
|
static int msg_maxsize_limit_min = MIN_MSGSIZEMAX;
|
|
static int msg_maxsize_limit_max = HARD_MSGSIZEMAX;
|
|
|
|
static struct ctl_table mq_sysctls[] = {
|
|
{
|
|
.procname = "queues_max",
|
|
.data = &init_ipc_ns.mq_queues_max,
|
|
.maxlen = sizeof(int),
|
|
.mode = 0644,
|
|
.proc_handler = proc_dointvec,
|
|
},
|
|
{
|
|
.procname = "msg_max",
|
|
.data = &init_ipc_ns.mq_msg_max,
|
|
.maxlen = sizeof(int),
|
|
.mode = 0644,
|
|
.proc_handler = proc_dointvec_minmax,
|
|
.extra1 = &msg_max_limit_min,
|
|
.extra2 = &msg_max_limit_max,
|
|
},
|
|
{
|
|
.procname = "msgsize_max",
|
|
.data = &init_ipc_ns.mq_msgsize_max,
|
|
.maxlen = sizeof(int),
|
|
.mode = 0644,
|
|
.proc_handler = proc_dointvec_minmax,
|
|
.extra1 = &msg_maxsize_limit_min,
|
|
.extra2 = &msg_maxsize_limit_max,
|
|
},
|
|
{
|
|
.procname = "msg_default",
|
|
.data = &init_ipc_ns.mq_msg_default,
|
|
.maxlen = sizeof(int),
|
|
.mode = 0644,
|
|
.proc_handler = proc_dointvec_minmax,
|
|
.extra1 = &msg_max_limit_min,
|
|
.extra2 = &msg_max_limit_max,
|
|
},
|
|
{
|
|
.procname = "msgsize_default",
|
|
.data = &init_ipc_ns.mq_msgsize_default,
|
|
.maxlen = sizeof(int),
|
|
.mode = 0644,
|
|
.proc_handler = proc_dointvec_minmax,
|
|
.extra1 = &msg_maxsize_limit_min,
|
|
.extra2 = &msg_maxsize_limit_max,
|
|
},
|
|
{}
|
|
};
|
|
|
|
static struct ctl_table_set *set_lookup(struct ctl_table_root *root)
|
|
{
|
|
return ¤t->nsproxy->ipc_ns->mq_set;
|
|
}
|
|
|
|
static int set_is_seen(struct ctl_table_set *set)
|
|
{
|
|
return ¤t->nsproxy->ipc_ns->mq_set == set;
|
|
}
|
|
|
|
static void mq_set_ownership(struct ctl_table_header *head,
|
|
kuid_t *uid, kgid_t *gid)
|
|
{
|
|
struct ipc_namespace *ns =
|
|
container_of(head->set, struct ipc_namespace, mq_set);
|
|
|
|
kuid_t ns_root_uid = make_kuid(ns->user_ns, 0);
|
|
kgid_t ns_root_gid = make_kgid(ns->user_ns, 0);
|
|
|
|
*uid = uid_valid(ns_root_uid) ? ns_root_uid : GLOBAL_ROOT_UID;
|
|
*gid = gid_valid(ns_root_gid) ? ns_root_gid : GLOBAL_ROOT_GID;
|
|
}
|
|
|
|
static int mq_permissions(struct ctl_table_header *head, const struct ctl_table *table)
|
|
{
|
|
int mode = table->mode;
|
|
kuid_t ns_root_uid;
|
|
kgid_t ns_root_gid;
|
|
|
|
mq_set_ownership(head, &ns_root_uid, &ns_root_gid);
|
|
|
|
if (uid_eq(current_euid(), ns_root_uid))
|
|
mode >>= 6;
|
|
|
|
else if (in_egroup_p(ns_root_gid))
|
|
mode >>= 3;
|
|
|
|
mode &= 7;
|
|
|
|
return (mode << 6) | (mode << 3) | mode;
|
|
}
|
|
|
|
static struct ctl_table_root set_root = {
|
|
.lookup = set_lookup,
|
|
.permissions = mq_permissions,
|
|
.set_ownership = mq_set_ownership,
|
|
};
|
|
|
|
bool setup_mq_sysctls(struct ipc_namespace *ns)
|
|
{
|
|
struct ctl_table *tbl;
|
|
|
|
setup_sysctl_set(&ns->mq_set, &set_root, set_is_seen);
|
|
|
|
tbl = kmemdup(mq_sysctls, sizeof(mq_sysctls), GFP_KERNEL);
|
|
if (tbl) {
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(mq_sysctls); i++) {
|
|
if (tbl[i].data == &init_ipc_ns.mq_queues_max)
|
|
tbl[i].data = &ns->mq_queues_max;
|
|
|
|
else if (tbl[i].data == &init_ipc_ns.mq_msg_max)
|
|
tbl[i].data = &ns->mq_msg_max;
|
|
|
|
else if (tbl[i].data == &init_ipc_ns.mq_msgsize_max)
|
|
tbl[i].data = &ns->mq_msgsize_max;
|
|
|
|
else if (tbl[i].data == &init_ipc_ns.mq_msg_default)
|
|
tbl[i].data = &ns->mq_msg_default;
|
|
|
|
else if (tbl[i].data == &init_ipc_ns.mq_msgsize_default)
|
|
tbl[i].data = &ns->mq_msgsize_default;
|
|
else
|
|
tbl[i].data = NULL;
|
|
}
|
|
|
|
ns->mq_sysctls = __register_sysctl_table(&ns->mq_set,
|
|
"fs/mqueue", tbl,
|
|
ARRAY_SIZE(mq_sysctls));
|
|
}
|
|
if (!ns->mq_sysctls) {
|
|
kfree(tbl);
|
|
retire_sysctl_set(&ns->mq_set);
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void retire_mq_sysctls(struct ipc_namespace *ns)
|
|
{
|
|
const struct ctl_table *tbl;
|
|
|
|
tbl = ns->mq_sysctls->ctl_table_arg;
|
|
unregister_sysctl_table(ns->mq_sysctls);
|
|
retire_sysctl_set(&ns->mq_set);
|
|
kfree(tbl);
|
|
}
|