Commit d865a115 authored by bingtian.ly@taobao.com's avatar bingtian.ly@taobao.com Committed by Zefan Li

net: avoid to hang up on sending due to sysctl configuration overflow.

commit cdda8891 upstream.

    I found if we write a larger than 4GB value to some sysctl
variables, the sending syscall will hang up forever, because these
variables are 32 bits, such large values make them overflow to 0 or
negative.

    This patch try to fix overflow or prevent from zero value setup
of below sysctl variables:

net.core.wmem_default
net.core.rmem_default

net.core.rmem_max
net.core.wmem_max

net.ipv4.udp_rmem_min
net.ipv4.udp_wmem_min

net.ipv4.tcp_wmem
net.ipv4.tcp_rmem
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarLi Yu <raise.sail@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
[lizf: Backported to 3.4: adjust context]
Signed-off-by: default avatarZefan Li <lizefan@huawei.com>
parent 3cda8eb0
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
static int zero = 0; static int zero = 0;
static int ushort_max = USHRT_MAX; static int ushort_max = USHRT_MAX;
static int one = 1;
#ifdef CONFIG_RPS #ifdef CONFIG_RPS
static int rps_sock_flow_sysctl(ctl_table *table, int write, static int rps_sock_flow_sysctl(ctl_table *table, int write,
void __user *buffer, size_t *lenp, loff_t *ppos) void __user *buffer, size_t *lenp, loff_t *ppos)
...@@ -94,28 +96,32 @@ static struct ctl_table net_core_table[] = { ...@@ -94,28 +96,32 @@ static struct ctl_table net_core_table[] = {
.data = &sysctl_wmem_max, .data = &sysctl_wmem_max,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "rmem_max", .procname = "rmem_max",
.data = &sysctl_rmem_max, .data = &sysctl_rmem_max,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "wmem_default", .procname = "wmem_default",
.data = &sysctl_wmem_default, .data = &sysctl_wmem_default,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "rmem_default", .procname = "rmem_default",
.data = &sysctl_rmem_default, .data = &sysctl_rmem_default,
.maxlen = sizeof(int), .maxlen = sizeof(int),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "dev_weight", .procname = "dev_weight",
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <net/tcp_memcontrol.h> #include <net/tcp_memcontrol.h>
static int zero; static int zero;
static int one = 1;
static int tcp_retr1_max = 255; static int tcp_retr1_max = 255;
static int ip_local_port_range_min[] = { 1, 1 }; static int ip_local_port_range_min[] = { 1, 1 };
static int ip_local_port_range_max[] = { 65535, 65535 }; static int ip_local_port_range_max[] = { 65535, 65535 };
...@@ -486,14 +487,16 @@ static struct ctl_table ipv4_table[] = { ...@@ -486,14 +487,16 @@ static struct ctl_table ipv4_table[] = {
.data = &sysctl_tcp_wmem, .data = &sysctl_tcp_wmem,
.maxlen = sizeof(sysctl_tcp_wmem), .maxlen = sizeof(sysctl_tcp_wmem),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "tcp_rmem", .procname = "tcp_rmem",
.data = &sysctl_tcp_rmem, .data = &sysctl_tcp_rmem,
.maxlen = sizeof(sysctl_tcp_rmem), .maxlen = sizeof(sysctl_tcp_rmem),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec .proc_handler = proc_dointvec_minmax,
.extra1 = &one,
}, },
{ {
.procname = "tcp_app_win", .procname = "tcp_app_win",
...@@ -700,7 +703,7 @@ static struct ctl_table ipv4_table[] = { ...@@ -700,7 +703,7 @@ static struct ctl_table ipv4_table[] = {
.maxlen = sizeof(sysctl_udp_rmem_min), .maxlen = sizeof(sysctl_udp_rmem_min),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_dointvec_minmax,
.extra1 = &zero .extra1 = &one
}, },
{ {
.procname = "udp_wmem_min", .procname = "udp_wmem_min",
...@@ -708,7 +711,7 @@ static struct ctl_table ipv4_table[] = { ...@@ -708,7 +711,7 @@ static struct ctl_table ipv4_table[] = {
.maxlen = sizeof(sysctl_udp_wmem_min), .maxlen = sizeof(sysctl_udp_wmem_min),
.mode = 0644, .mode = 0644,
.proc_handler = proc_dointvec_minmax, .proc_handler = proc_dointvec_minmax,
.extra1 = &zero .extra1 = &one
}, },
{ } { }
}; };
......
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