diff mbox series

[mptcp-next,1/2] mptcp: only allow set existing scheduler for net.mptcp.scheduler

Message ID 20240430-sysctl_scheduler-v1-1-8187148850df@gmail.com (mailing list archive)
State Accepted, archived
Commit bc3eac499491ea69ac92c6f078977c5c7f0a36bb
Delegated to: Matthieu Baerts
Headers show
Series mptcp: fix net.mptcp.scheduler behavior | expand

Checks

Context Check Description
matttbe/build success Build and static analysis OK
matttbe/checkpatch success total: 0 errors, 0 warnings, 0 checks, 52 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug warning Unstable: 1 failed test(s): selftest_mptcp_join
matttbe/KVM_Validation__btf__only_bpftest_all_ success Success! ✅

Commit Message

Gregory Detal April 30, 2024, 12:06 p.m. UTC
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: e3b2870b6d22 ("mptcp: add a new sysctl scheduler")
Signed-off-by: Gregory Detal <gregory.detal@gmail.com>
---
 net/mptcp/ctrl.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

Comments

Matthieu Baerts (NGI0) April 30, 2024, 2 p.m. UTC | #1
On 30/04/2024 14:06, Gregory Detal wrote:
> 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: e3b2870b6d22 ("mptcp: add a new sysctl scheduler")
> Signed-off-by: Gregory Detal <gregory.detal@gmail.com>
> ---
>  net/mptcp/ctrl.c | 40 +++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
> index 8d661156ab8c..0e69bd0ea302 100644
> --- a/net/mptcp/ctrl.c
> +++ b/net/mptcp/ctrl.c
> @@ -96,6 +96,44 @@ static void mptcp_pernet_set_defaults(struct mptcp_pernet *pernet)
>  }
>  
>  #ifdef CONFIG_SYSCTL
> +

We can remove this extra new line here: I can do that when applying the
patches if I don't forget.

> +static int mptcp_set_scheduler(const struct net *net, const char *name)
(...)

Cheers,
Matt
diff mbox series

Patch

diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
index 8d661156ab8c..0e69bd0ea302 100644
--- a/net/mptcp/ctrl.c
+++ b/net/mptcp/ctrl.c
@@ -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",
@@ -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",