linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware
@ 2022-11-25 12:11 Firo Yang
  2022-11-25 12:22 ` Marcelo Ricardo Leitner
  2022-11-30  4:48 ` Jakub Kicinski
  0 siblings, 2 replies; 4+ messages in thread
From: Firo Yang @ 2022-11-25 12:11 UTC (permalink / raw)
  To: marcelo.leitner, vyasevich, nhorman
  Cc: mkubecek, davem, edumazet, kuba, pabeni, linux-sctp, netdev,
	linux-kernel, firogm, Firo Yang

Recently, a customer reported that from their container whose
net namespace is different to the host's init_net, they can't set
the container's net.sctp.rto_max to any value smaller than
init_net.sctp.rto_min.

For instance,
Host:
sudo sysctl net.sctp.rto_min
net.sctp.rto_min = 1000

Container:
echo 100 > /mnt/proc-net/sctp/rto_min
echo 400 > /mnt/proc-net/sctp/rto_max
echo: write error: Invalid argument

This is caused by the check made from this'commit 4f3fdf3bc59c
("sctp: add check rto_min and rto_max in sysctl")'
When validating the input value, it's always referring the boundary
value set for the init_net namespace.

Having container's rto_max smaller than host's init_net.sctp.rto_min
does make sense. Consider that the rto between two containers on the
same host is very likely smaller than it for two hosts.

So to fix this problem, as suggested by Marcelo, this patch makes the
extra pointers of rto_min, rto_max, pf_retrans, and ps_retrans point
to the corresponding variables from the newly created net namespace while
the new net namespace is being registered in sctp_sysctl_net_register.

Fixes: 4f3fdf3bc59c ("sctp: add check rto_min and rto_max in sysctl")
Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Signed-off-by: Firo Yang <firo.yang@suse.com>
---
 net/sctp/sysctl.c | 51 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 33 insertions(+), 18 deletions(-)

diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
index b46a416787ec..516ab67475e1 100644
--- a/net/sctp/sysctl.c
+++ b/net/sctp/sysctl.c
@@ -84,6 +84,16 @@ static struct ctl_table sctp_table[] = {
 	{ /* sentinel */ }
 };
 
+/* The following index defines are used in sctp_sysctl_net_register().
+ * If you add new items to the sctp_net_table, please ensure that
+ * the index values of these defines hold the same meaning indicated by
+ * their macro names when they appear in sctp_net_table.
+ */
+#define SCTP_RTO_MIN_IDX       1
+#define SCTP_RTO_MAX_IDX       2
+#define SCTP_PF_RETRANS_IDX    3
+#define SCTP_PS_RETRANS_IDX    4
+
 static struct ctl_table sctp_net_table[] = {
 	{
 		.procname	= "rto_initial",
@@ -112,6 +122,24 @@ static struct ctl_table sctp_net_table[] = {
 		.extra1         = &init_net.sctp.rto_min,
 		.extra2         = &timer_max
 	},
+	{
+		.procname	= "pf_retrans",
+		.data		= &init_net.sctp.pf_retrans,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= SYSCTL_ZERO,
+		.extra2		= &init_net.sctp.ps_retrans,
+	},
+	{
+		.procname	= "ps_retrans",
+		.data		= &init_net.sctp.ps_retrans,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &init_net.sctp.pf_retrans,
+		.extra2		= &ps_retrans_max,
+	},
 	{
 		.procname	= "rto_alpha_exp_divisor",
 		.data		= &init_net.sctp.rto_alpha,
@@ -207,24 +235,6 @@ static struct ctl_table sctp_net_table[] = {
 		.extra1		= SYSCTL_ONE,
 		.extra2		= SYSCTL_INT_MAX,
 	},
-	{
-		.procname	= "pf_retrans",
-		.data		= &init_net.sctp.pf_retrans,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= &init_net.sctp.ps_retrans,
-	},
-	{
-		.procname	= "ps_retrans",
-		.data		= &init_net.sctp.ps_retrans,
-		.maxlen		= sizeof(int),
-		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= &init_net.sctp.pf_retrans,
-		.extra2		= &ps_retrans_max,
-	},
 	{
 		.procname	= "sndbuf_policy",
 		.data		= &init_net.sctp.sndbuf_policy,
@@ -586,6 +596,11 @@ int sctp_sysctl_net_register(struct net *net)
 	for (i = 0; table[i].data; i++)
 		table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
 
+	table[SCTP_RTO_MIN_IDX].extra2 = &net->sctp.rto_max;
+	table[SCTP_RTO_MAX_IDX].extra1 = &net->sctp.rto_min;
+	table[SCTP_PF_RETRANS_IDX].extra2 = &net->sctp.ps_retrans;
+	table[SCTP_PS_RETRANS_IDX].extra1 = &net->sctp.pf_retrans;
+
 	net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
 	if (net->sctp.sysctl_header == NULL) {
 		kfree(table);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware
  2022-11-25 12:11 [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware Firo Yang
@ 2022-11-25 12:22 ` Marcelo Ricardo Leitner
  2022-11-30  4:48 ` Jakub Kicinski
  1 sibling, 0 replies; 4+ messages in thread
From: Marcelo Ricardo Leitner @ 2022-11-25 12:22 UTC (permalink / raw)
  To: Firo Yang
  Cc: vyasevich, nhorman, mkubecek, davem, edumazet, kuba, pabeni,
	linux-sctp, netdev, linux-kernel, firogm

On Fri, Nov 25, 2022 at 08:11:27PM +0800, Firo Yang wrote:
> Recently, a customer reported that from their container whose
> net namespace is different to the host's init_net, they can't set
> the container's net.sctp.rto_max to any value smaller than
> init_net.sctp.rto_min.
> 
> For instance,
> Host:
> sudo sysctl net.sctp.rto_min
> net.sctp.rto_min = 1000
> 
> Container:
> echo 100 > /mnt/proc-net/sctp/rto_min
> echo 400 > /mnt/proc-net/sctp/rto_max
> echo: write error: Invalid argument
> 
> This is caused by the check made from this'commit 4f3fdf3bc59c
> ("sctp: add check rto_min and rto_max in sysctl")'
> When validating the input value, it's always referring the boundary
> value set for the init_net namespace.
> 
> Having container's rto_max smaller than host's init_net.sctp.rto_min
> does make sense. Consider that the rto between two containers on the
> same host is very likely smaller than it for two hosts.
> 
> So to fix this problem, as suggested by Marcelo, this patch makes the
> extra pointers of rto_min, rto_max, pf_retrans, and ps_retrans point
> to the corresponding variables from the newly created net namespace while
> the new net namespace is being registered in sctp_sysctl_net_register.
> 
> Fixes: 4f3fdf3bc59c ("sctp: add check rto_min and rto_max in sysctl")
> Reviewed-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
> Signed-off-by: Firo Yang <firo.yang@suse.com>

and
Acked-by: Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>

Thanks Firo.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware
  2022-11-25 12:11 [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware Firo Yang
  2022-11-25 12:22 ` Marcelo Ricardo Leitner
@ 2022-11-30  4:48 ` Jakub Kicinski
  2022-12-01  4:11   ` Firo Yang
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Kicinski @ 2022-11-30  4:48 UTC (permalink / raw)
  To: Firo Yang
  Cc: marcelo.leitner, vyasevich, nhorman, mkubecek, davem, edumazet,
	pabeni, linux-sctp, netdev, linux-kernel, firogm

On Fri, 25 Nov 2022 20:11:27 +0800 Firo Yang wrote:
> +#define SCTP_RTO_MIN_IDX       1
> +#define SCTP_RTO_MAX_IDX       2
> +#define SCTP_PF_RETRANS_IDX    3
> +#define SCTP_PS_RETRANS_IDX    4

Use these to index the entries, please, like this:

struct bla table[] = {
	[MY_INDEX_ONE] = {
		.whatever = 1,
	},
	[MY_INDEX_TWO] = {
		.fields = 2,
	},
	{
		.there = 3,
	},
	{
		.are = 4,
	},
};

I think that works even without all entries in the table having the
index.. ?

>  static struct ctl_table sctp_net_table[] = {
>  	{
>  		.procname	= "rto_initial",
> @@ -112,6 +122,24 @@ static struct ctl_table sctp_net_table[] = {
>  		.extra1         = &init_net.sctp.rto_min,
>  		.extra2         = &timer_max
>  	},
> +	{
> +		.procname	= "pf_retrans",
> +		.data		= &init_net.sctp.pf_retrans,
> +		.maxlen		= sizeof(int),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec_minmax,
> +		.extra1		= SYSCTL_ZERO,
> +		.extra2		= &init_net.sctp.ps_retrans,
> +	},
> +	{
> +		.procname	= "ps_retrans",
> +		.data		= &init_net.sctp.ps_retrans,
> +		.maxlen		= sizeof(int),
> +		.mode		= 0644,
> +		.proc_handler	= proc_dointvec_minmax,
> +		.extra1		= &init_net.sctp.pf_retrans,
> +		.extra2		= &ps_retrans_max,
> +	},

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware
  2022-11-30  4:48 ` Jakub Kicinski
@ 2022-12-01  4:11   ` Firo Yang
  0 siblings, 0 replies; 4+ messages in thread
From: Firo Yang @ 2022-12-01  4:11 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: marcelo.leitner, vyasevich, nhorman, mkubecek, davem, edumazet,
	pabeni, linux-sctp, netdev, linux-kernel, firogm

The 11/29/2022 20:48, Jakub Kicinski wrote:
> On Fri, 25 Nov 2022 20:11:27 +0800 Firo Yang wrote:
> > +#define SCTP_RTO_MIN_IDX       1
> > +#define SCTP_RTO_MAX_IDX       2
> > +#define SCTP_PF_RETRANS_IDX    3
> > +#define SCTP_PS_RETRANS_IDX    4
> 
> Use these to index the entries, please, like this:
> 
> struct bla table[] = {
> 	[MY_INDEX_ONE] = {
> 		.whatever = 1,
> 	},
> 	[MY_INDEX_TWO] = {
> 		.fields = 2,
> 	},
> 	{
> 		.there = 3,
> 	},
> 	{
> 		.are = 4,
> 	},
> };
> 
> I think that works even without all entries in the table having the
> index.. ?
> 

Cool. I will send a V3.

Thanks,
// Firo

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-12-01  4:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 12:11 [PATCH v2 1/1] sctp: sysctl: make extra pointers netns aware Firo Yang
2022-11-25 12:22 ` Marcelo Ricardo Leitner
2022-11-30  4:48 ` Jakub Kicinski
2022-12-01  4:11   ` Firo Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).