Commit 6963c508 authored by Gregory Detal's avatar Gregory Detal Committed by Jakub Kicinski

mptcp: only allow set existing scheduler for net.mptcp.scheduler

The current behavior is to accept any strings as inputs, this results in
an inconsistent result where an unexisting scheduler can be set:

  # sysctl -w net.mptcp.scheduler=notdefault
  net.mptcp.scheduler = notdefault

This patch changes this behavior by checking for existing scheduler
before accepting the input.

Fixes: e3b2870b ("mptcp: add a new sysctl scheduler")
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGregory Detal <gregory.detal@gmail.com>
Reviewed-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Tested-by: default avatarGeliang Tang <geliang@kernel.org>
Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Link: https://lore.kernel.org/r/20240506-upstream-net-20240506-mptcp-sched-exist-v1-1-2ed1529e521e@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 19e35f24
...@@ -96,6 +96,43 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet) ...@@ -96,6 +96,43 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
} }
#ifdef CONFIG_SYSCTL #ifdef CONFIG_SYSCTL
static int mptcp_set_scheduler(const struct net *net, const char *name)
{
struct mptcp_pernet *pernet = mptcp_get_pernet(net);
struct mptcp_sched_ops *sched;
int ret = 0;
rcu_read_lock();
sched = mptcp_sched_find(name);
if (sched)
strscpy(pernet->scheduler, name, MPTCP_SCHED_NAME_MAX);
else
ret = -ENOENT;
rcu_read_unlock();
return ret;
}
static int proc_scheduler(struct ctl_table *ctl, int write,
void *buffer, size_t *lenp, loff_t *ppos)
{
const struct net *net = current->nsproxy->net_ns;
char val[MPTCP_SCHED_NAME_MAX];
struct ctl_table tbl = {
.data = val,
.maxlen = MPTCP_SCHED_NAME_MAX,
};
int ret;
strscpy(val, mptcp_get_scheduler(net), MPTCP_SCHED_NAME_MAX);
ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
if (write && ret == 0)
ret = mptcp_set_scheduler(net, val);
return ret;
}
static struct ctl_table mptcp_sysctl_table[] = { static struct ctl_table mptcp_sysctl_table[] = {
{ {
.procname = "enabled", .procname = "enabled",
...@@ -148,7 +185,7 @@ static struct ctl_table mptcp_sysctl_table[] = { ...@@ -148,7 +185,7 @@ static struct ctl_table mptcp_sysctl_table[] = {
.procname = "scheduler", .procname = "scheduler",
.maxlen = MPTCP_SCHED_NAME_MAX, .maxlen = MPTCP_SCHED_NAME_MAX,
.mode = 0644, .mode = 0644,
.proc_handler = proc_dostring, .proc_handler = proc_scheduler,
}, },
{ {
.procname = "close_timeout", .procname = "close_timeout",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment