Skip to content

Commit

Permalink
mptcp: only allow set existing scheduler for net.mptcp.scheduler
Browse files Browse the repository at this point in the history
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: e3b2870 ("mptcp: add a new sysctl scheduler")
Signed-off-by: Gregory Detal <gregory.detal@gmail.com>
  • Loading branch information
gdetal authored and Geliang Tang committed May 2, 2024
1 parent 9491b4a commit 8dbfad6
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion net/mptcp/ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,44 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
}

#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[] = {
{
.procname = "enabled",
Expand Down Expand Up @@ -148,7 +186,7 @@ static struct ctl_table mptcp_sysctl_table[] = {
.procname = "scheduler",
.maxlen = MPTCP_SCHED_NAME_MAX,
.mode = 0644,
.proc_handler = proc_dostring,
.proc_handler = proc_scheduler,
},
{
.procname = "close_timeout",
Expand Down

0 comments on commit 8dbfad6

Please sign in to comment.