Skip to content

Commit 8133534

Browse files
sorindumitrudavem330
authored andcommitted
net: limit tcp/udp rmem/wmem to SOCK_{RCV,SND}BUF_MIN
This is similar to b1cb59c(net: sysctl_net_core: check SNDBUF and RCVBUF for min length). I don't think too small values can cause crashes in the case of udp and tcp, but I've seen this set to too small values which triggered awful performance. It also makes the setting consistent across all the wmem/rmem sysctls. Signed-off-by: Sorin Dumitru <sdumitru@ixiacom.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 5befa5e commit 8133534

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

net/ipv4/sysctl_net_ipv4.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ static int tcp_syn_retries_min = 1;
4141
static int tcp_syn_retries_max = MAX_TCP_SYNCNT;
4242
static int ip_ping_group_range_min[] = { 0, 0 };
4343
static int ip_ping_group_range_max[] = { GID_T_MAX, GID_T_MAX };
44+
static int min_sndbuf = SOCK_MIN_SNDBUF;
45+
static int min_rcvbuf = SOCK_MIN_RCVBUF;
4446

4547
/* Update system visible IP port range */
4648
static void set_local_port_range(struct net *net, int range[2])
@@ -528,7 +530,7 @@ static struct ctl_table ipv4_table[] = {
528530
.maxlen = sizeof(sysctl_tcp_wmem),
529531
.mode = 0644,
530532
.proc_handler = proc_dointvec_minmax,
531-
.extra1 = &one,
533+
.extra1 = &min_sndbuf,
532534
},
533535
{
534536
.procname = "tcp_notsent_lowat",
@@ -543,7 +545,7 @@ static struct ctl_table ipv4_table[] = {
543545
.maxlen = sizeof(sysctl_tcp_rmem),
544546
.mode = 0644,
545547
.proc_handler = proc_dointvec_minmax,
546-
.extra1 = &one,
548+
.extra1 = &min_rcvbuf,
547549
},
548550
{
549551
.procname = "tcp_app_win",
@@ -756,15 +758,15 @@ static struct ctl_table ipv4_table[] = {
756758
.maxlen = sizeof(sysctl_udp_rmem_min),
757759
.mode = 0644,
758760
.proc_handler = proc_dointvec_minmax,
759-
.extra1 = &one
761+
.extra1 = &min_rcvbuf,
760762
},
761763
{
762764
.procname = "udp_wmem_min",
763765
.data = &sysctl_udp_wmem_min,
764766
.maxlen = sizeof(sysctl_udp_wmem_min),
765767
.mode = 0644,
766768
.proc_handler = proc_dointvec_minmax,
767-
.extra1 = &one
769+
.extra1 = &min_sndbuf,
768770
},
769771
{ }
770772
};

0 commit comments

Comments
 (0)