bff97cf11b
We make these changes in order to prepare __register_sysctl_table and its callers for when we remove the sentinel element (empty element at the end of ctl_table arrays). We don't actually remove any sentinels in this commit, but we *do* make sure to use ARRAY_SIZE so the table_size is available when the removal occurs. We add a table_size argument to __register_sysctl_table and adjust callers, all of which pass ctl_table pointers and need an explicit call to ARRAY_SIZE. We implement a size calculation in register_net_sysctl in order to forward the size of the array pointer received from the network register calls. The new table_size argument does not yet have any effect in the init_header call which is still dependent on the sentinel's presence. table_size *does* however drive the `kzalloc` allocation in __register_sysctl_table with no adverse effects as the allocated memory is either one element greater than the calculated ctl_table array (for the calls in ipc_sysctl.c, mq_sysctl.c and ucount.c) or the exact size of the calculated ctl_table array (for the call from sysctl_net.c and register_sysctl). This approach will allows us to "just" remove the sentinel without further changes to __register_sysctl_table as table_size will represent the exact size for all the callers at that point. Signed-off-by: Joel Granados <j.granados@samsung.com> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
134 lines
3.0 KiB
C
134 lines
3.0 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>
|
|
|
|
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 struct ctl_table_root set_root = {
|
|
.lookup = set_lookup,
|
|
};
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|