Skip to contentSkip to conversation

tcp: restrict net.ipv4.tcp_adv_min_scale (#20312)

PATCH Superseded Alexey Dobriyan 4 participants 6 messages Nov 14, 2010 – Nov 28, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tcp: restrict net.ipv4.tcp_adv_min_scale (#20312)

tcp_win_from_space() does the following:

	if (sysctl_tcp_adv_win_scale <= 0)
		return space >> (-sysctl_tcp_adv_win_scale);
	else
		return space - (space >> sysctl_tcp_adv_win_scale);

"space" is int.

As per C99 6.5.7 (3) shifting int for 32 or more bits is undefined behaviour.

Indeed, if sysctl_tcp_adv_win_scale is exactly 32, space >> 32 equals space and function returns 0;

Which means we busyloop in tcp_fixup_rcvbuf().

Restrict net.ipv4.tcp_adv_win_scale to [-31, 31].

Fix https://bugzilla.kernel.org/show_bug.cgi?id=20312

Steps to reproduce:

	echo 32 >/proc/sys/net/ipv4/tcp_adv_win_scale
	wget www.kernel.org
	[softlockup]

---

net/ipv4/sysctl_net_ipv4.c +5 -1
@@ -26,6 +26,8 @@ static int zero;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
 static int ip_local_port_range_max[] = { 65535, 65535 };
+static int _minus_31 = -31;
+static int _31 = 31;
 
 /* Update system visible IP port range */
 static void set_local_port_range(int range[2])
@@ -426,7 +428,9 @@ static struct ctl_table ipv4_table[] = {
 		.data		= &sysctl_tcp_adv_win_scale,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &_minus_31,
+		.extra2		= &_31,
 	},
 	{
 		.procname	= "tcp_tw_reuse",
#1 lore raw
Quoted 21 lines · Alexey Dobriyan

tcp_win_from_space() does the following:

	if (sysctl_tcp_adv_win_scale <= 0)
		return space >> (-sysctl_tcp_adv_win_scale);
	else
		return space - (space >> sysctl_tcp_adv_win_scale);

"space" is int.

As per C99 6.5.7 (3) shifting int for 32 or more bits is undefined behaviour.

Indeed, if sysctl_tcp_adv_win_scale is exactly 32, space >> 32 equals space and function returns 0;

Which means we busyloop in tcp_fixup_rcvbuf().

Restrict net.ipv4.tcp_adv_win_scale to [-31, 31].

Fix https://bugzilla.kernel.org/show_bug.cgi?id=20312

Quoted 9 lines

Steps to reproduce:

	echo 32 >/proc/sys/net/ipv4/tcp_adv_win_scale
	wget www.kernel.org
	[softlockup]

---

Please fix your patch title, you speak of adv_min_scale ...

net/ipv4/sysctl_net_ipv4.c static int zero; · line 30

Quoted 8 lines
net/ipv4/sysctl_net_ipv4.c +2 -0
@@ -26,6 +26,8 @@ static int zero;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
 static int ip_local_port_range_max[] = { 65535, 65535 };
+static int _minus_31 = -31;
+static int _31 = 31;

Please use normal symbols, not starting by underscore.

Quoted 4 lines
net/ipv4/sysctl_net_ipv4.c +0 -0
 /* Update system visible IP port range */
 static void set_local_port_range(int range[2])

net/ipv4/sysctl_net_ipv4.c static struct ctl_table ipv4_table[] = { · line 436

Quoted 10 lines
net/ipv4/sysctl_net_ipv4.c +3 -1
@@ -426,7 +428,9 @@ static struct ctl_table ipv4_table[] = {
 		.data		= &sysctl_tcp_adv_win_scale,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &_minus_31,
+		.extra2		= &_31,
 	},
 	{
 		.procname	= "tcp_tw_reuse",

Please change Documentation/networking/ip-sysctl.txt to reflect possible values of adv_win_scale

Thanks

#2 lore raw
Quoted 4 lines · Eric Dumazet

net/ipv4/sysctl_net_ipv4.c static int zero; · line 30

Quoted 2 lines
net/ipv4/sysctl_net_ipv4.c +2 -0
+static int _minus_31 = -31;
+static int _31 = 31;

Please use normal symbols, not starting by underscore.

static int thirty_one = 31? :-)

#3 lore raw
Quoted 7 lines · Alexey Dobriyan
Quoted 4 lines · Eric Dumazet

net/ipv4/sysctl_net_ipv4.c static int zero; · line 30

Quoted 2 lines
net/ipv4/sysctl_net_ipv4.c +2 -0
+static int _minus_31 = -31;
+static int _31 = 31;

Please use normal symbols, not starting by underscore.

static int thirty_one = 31? :-)

How about, oh, I don't know, adv_win_scale_{min,max}?

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#4 lore raw

PATCH v2 1/1 tcp: restrict net.ipv4.tcp_adv_win_scale (#20312)

tcp_win_from_space() does the following:

      if (sysctl_tcp_adv_win_scale <= 0)
              return space >> (-sysctl_tcp_adv_win_scale);
      else
              return space - (space >> sysctl_tcp_adv_win_scale);

"space" is int.

As per C99 6.5.7 (3) shifting int for 32 or more bits is undefined behaviour.

Indeed, if sysctl_tcp_adv_win_scale is exactly 32, space >> 32 equals space and function returns 0.

Which means we busyloop in tcp_fixup_rcvbuf().

Restrict net.ipv4.tcp_adv_win_scale to [-31, 31].

Fix https://bugzilla.kernel.org/show_bug.cgi?id=20312

Steps to reproduce:

      echo 32 >/proc/sys/net/ipv4/tcp_adv_win_scale
      wget www.kernel.org
      [softlockup]

---

 Documentation/networking/ip-sysctl.txt |    1 +
 net/ipv4/sysctl_net_ipv4.c             |    6 +++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
Documentation/networking/ip-sysctl.txt +1 -0
@@ -144,6 +144,7 @@ tcp_adv_win_scale - INTEGER
 	Count buffering overhead as bytes/2^tcp_adv_win_scale
 	(if tcp_adv_win_scale > 0) or bytes-bytes/2^(-tcp_adv_win_scale),
 	if it is <= 0.
+	Possible values are [-31, 31], inclusive.
 	Default: 2
 
 tcp_allowed_congestion_control - STRING
net/ipv4/sysctl_net_ipv4.c +5 -1
@@ -26,6 +26,8 @@ static int zero;
 static int tcp_retr1_max = 255;
 static int ip_local_port_range_min[] = { 1, 1 };
 static int ip_local_port_range_max[] = { 65535, 65535 };
+static int tcp_adv_win_scale_min = -31;
+static int tcp_adv_win_scale_max = 31;
 
 /* Update system visible IP port range */
 static void set_local_port_range(int range[2])
@@ -426,7 +428,9 @@ static struct ctl_table ipv4_table[] = {
 		.data		= &sysctl_tcp_adv_win_scale,
 		.maxlen		= sizeof(int),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec
+		.proc_handler	= proc_dointvec_minmax,
+		.extra1		= &tcp_adv_win_scale_min,
+		.extra2		= &tcp_adv_win_scale_max,
 	},
 	{
 		.procname	= "tcp_tw_reuse",
maintainer
#5 lore raw

Re: [PATCH v2] tcp: restrict net.ipv4.tcp_adv_win_scale (#20312)

From: Alexey Dobriyan <[email protected]>
Date: Tue, 23 Nov 2010 00:54:21 +0200

Quoted 21 lines

tcp_win_from_space() does the following:

      if (sysctl_tcp_adv_win_scale <= 0)
              return space >> (-sysctl_tcp_adv_win_scale);
      else
              return space - (space >> sysctl_tcp_adv_win_scale);

"space" is int.

As per C99 6.5.7 (3) shifting int for 32 or more bits is undefined behaviour.

Indeed, if sysctl_tcp_adv_win_scale is exactly 32, space >> 32 equals space and function returns 0.

Which means we busyloop in tcp_fixup_rcvbuf().

Restrict net.ipv4.tcp_adv_win_scale to [-31, 31].

Fix https://bugzilla.kernel.org/show_bug.cgi?id=20312

Quoted 7 lines

Steps to reproduce:

      echo 32 >/proc/sys/net/ipv4/tcp_adv_win_scale
      wget www.kernel.org
      [softlockup]

I'll aply this, thanks Alexey.