Commit Graph

17 Commits

Author SHA1 Message Date
Fuhai Wang 1508b30ad8 inet: unconstify ipv6_mapped and tcp_request_sock_ipv4/6_ops
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
2020-09-23 19:07:10 +08:00
Hongbo Li 0b46e0dbd4 net: sched when reading udp proc
cat /proc/net/udp may cause long latency.
Add cond_resched() when reading this proc file.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-07-08 16:07:57 +08:00
Hongbo Li 61d7e2b266 net: sched when reading tcp proc
cat /proc/net/tcp may cause long latency.
Add cond_resched() when reading this proc file.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-07-08 16:07:55 +08:00
Zhiping du de427fd173 getsockopt: add SO_MARK2 to get the MARK of flow
[tkernel2 commit c6f2e27f7ad]

add SO_MARK2 to get the MARK of flow

Signed-off-by: brookxu <brookxu@tencent.com>

Signed-off-by: Zhiping Du <zhipingdu@tencent.com>
2020-07-08 16:04:22 +08:00
Hongbo Li aa0cb7f701 net: increase tcp rmem default
increase tcp rmem default from 87380 to 131072

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-05-29 10:40:04 +08:00
Hongbo Li 52643cdf01 route: set the deleted fnhe fnhe_daddr to 0
upstream:
ee60ad219f5c ("route: set the deleted fnhe fnhe_daddr to 0 ")

The race occurs in __mkroute_output() when 2 threads lookup a dst:

      CPU A                 CPU B
      find_exception()
                            find_exception() [fnhe expires]
                            ip_del_fnhe() [fnhe is deleted]
      rt_bind_exception()

In rt_bind_exception() it will bind a deleted fnhe with the new dst, and
this dst will get no chance to be freed. It causes a dev defcnt leak and
consecutive dmesg warnings:

  unregister_netdevice: waiting for ethX to become free. Usage count = 1

Especially thanks Jon to identify the issue.
This patch fixes it by setting fnhe_daddr to 0 in ip_del_fnhe() to stop
binding the deleted fnhe with a new dst when checking fnhe's fnhe_daddr
and daddr in rt_bind_exception().

It works as both ip_del_fnhe() and rt_bind_exception() are protected by
fnhe_lock and the fhne is freed by kfree_rcu().

Fixes: deed49df7390 ("route: check and remove route cache when we get route")

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-05-29 10:39:04 +08:00
Hongbo Li ef9d6889ab net: fix memory limit bug in tcp_fragment
upstream:
b6653b3629e5 ("tcp: refine memory limit test in tcp_fragment")
b617158dc096 ("tcp: be more careful in tcp_fragment")

tcp_fragment() might be called for skbs in the write queue.

Memory limits might have been exceeded because tcp_sendmsg() only
checks limits at full skb (64KB) boundaries.

Therefore, we need to make sure tcp_fragment() wont punish applications
that might have setup very low SO_SNDBUF values.

75c119afe14f ("tcp: implement rb-tree based retransmit queue")
separate transmit queue to transmit queue and retransmit queue.
b6653b36 adds some check to the transmit queue, b617158dc adds some check
on the rtx queue.

So we only backport the b6653b36 patch. use tcp_send_head(sk) instead of
TCP_FRAG_IN_WRITE_QUEUE.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-05-29 10:39:02 +08:00
Hongbo Li 41a3398393 net: modify default value of host max_orphan
when we namespacify net.ipv4.tcp_max_orphans, the default
value of host and container are both 8192. This patch
change the default value of host to the original value.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-05-29 10:39:00 +08:00
Xiaoming Gao c715d50029 tcp: make TCP_RTO_MIN/MAX be tunable
tcp_rto_min,tcp_rto_max control the parameters of them.
remember that the min value of tcp_rto_min is 4ms which
be used to be div by RTO_MAX.

Signed-off-by: Shan Wei <davidshan@tencent.com>
Signed-off-by: Fuhai Wang <fuhaiwang@tencent.com>
Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
2020-01-02 12:20:29 +08:00
Zhiping Du af89c966ab tcp: add tcp_min_snd_mss sysctl
[upstream commit 5f3e2bf008c2221478101ee72f5cb4654b9fc363]

Some TCP peers announce a very small MSS option in their SYN and/or
SYN/ACK messages.

This forces the stack to send packets with a very high network/cpu
overhead.

Linux has enforced a minimal value of 48. Since this value includes
the size of TCP options, and that the options can consume up to 40
bytes, this means that each segment can include only 8 bytes of payload.

In some cases, it can be useful to increase the minimal value
to a saner value.

We still let the default to 48 (TCP_MIN_SND_MSS), for compatibility
reasons.

Note that TCP_MAXSEG socket option enforces a minimal value
of (TCP_MIN_MSS). David Miller increased this minimal value
in commit c39508d6f118 ("tcp: Make TCP_MAXSEG minimum more correct.")
from 64 to 88.

We might in the future merge TCP_MIN_SND_MSS and TCP_MIN_MSS.

CVE-2019-11479 -- tcp mss hardcoded to 48

[upstream commit: 967c05aee439e6e5d7d805e195b3a20ef5c433d6]

tcp: enforce tcp_min_snd_mss in tcp_mtu_probing()

If mtu probing is enabled tcp_mtu_probing() could very well end up
with a too small MSS.

Use the new sysctl tcp_min_snd_mss to make sure MSS search
is performed in an acceptable range.

Signed-off-by: Zhiping Du <zhipingdu@tencent.com>
2020-01-02 12:16:53 +08:00
Zhiping Du 5a87e33d04 tcp: tcp_fragment() should apply sane memory limits
[upstream commit f070ef2ac66716357066b683fb0baf55f8191a2e]

Jonathan Looney reported that a malicious peer can force a sender
to fragment its retransmit queue into tiny skbs, inflating memory
usage and/or overflow 32bit counters.

TCP allows an application to queue up to sk_sndbuf bytes,
so we need to give some allowance for non malicious splitting
of retransmit queue.

A new SNMP counter is added to monitor how many times TCP
did not allow to split an skb if the allowance was exceeded.

Note that this counter might increase in the case applications
use SO_SNDBUF socket option to lower sk_sndbuf.

CVE-2019-11478 : tcp_fragment, prevent fragmenting a packet when the
	socket is already using more than half the allowed space

Signed-off-by: Zhiping Du <zhipingdu@tencent.com>
2020-01-02 12:16:41 +08:00
Zhiping du aee5a5fcc0 tcp: limit payload size of sacked skbs
[upstream commit 3b4929f65b0d8249f19a50245cd88ed1a2f78cff]

Jonathan Looney reported that TCP can trigger the following crash
in tcp_shifted_skb() :

	BUG_ON(tcp_skb_pcount(skb) < pcount);

This can happen if the remote peer has advertized the smallest
MSS that linux TCP accepts : 48

An skb can hold 17 fragments, and each fragment can hold 32KB
on x86, or 64KB on PowerPC.

This means that the 16bit witdh of TCP_SKB_CB(skb)->tcp_gso_segs
can overflow.

Note that tcp_sendmsg() builds skbs with less than 64KB
of payload, so this problem needs SACK to be enabled.
SACK blocks allow TCP to coalesce multiple skbs in the retransmit
queue, thus filling the 17 fragments to maximal capacity.

CVE-2019-11477 -- u16 overflow of TCP_SKB_CB(skb)->tcp_gso_segs

[upstream commit cd4ffa93f16efea290bb70537f98f518e1927e63]

tcp: fix fack_count accounting on
tcp_shift_skb_data()

v4.15 or since commit 737ff314563 ("tcp: use sequence distance to
detect reordering") had switched from the packet-based FACK tracking
to sequence-based.

v4.14 and older still have the old logic and hence on
tcp_skb_shift_data() needs to retain its original logic and have
@fack_count in sync. In other words, we keep the increment of pcount
with
tcp_skb_pcount(skb) to later used that to update fack_count. To make it
more explicit we track the new skb that gets incremented to pcount in
@next_pcount, and we get to avoid the constant invocation of
tcp_skb_pcount(skb) all together.

Fixes: a5f1faa40101 ("tcp: limit payload size of sacked skbs")

Fixes: 832d11c5cd07 ("tcp: Try to restore large SKBs while SACK processing")

Signed-off-by: Zhiping Du <zhipingdu@tencent.com>
2020-01-02 12:16:23 +08:00
Hongbo Li 963299648d net: namespaceify sysctl_tcp_rmem and sysctl_tcp_wmem
upstream commit: 356d1833b638bd465672aefeb71def3ab93fc17d

Note that when a new netns is created, it inherits its
sysctl_tcp_rmem and sysctl_tcp_wmem from initial netns.

This change is needed so that we can refine TCP rcvbuf autotuning,
to take RTT into consideration.

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-01-02 11:34:10 +08:00
Hongbo Li d4b4a18384 net: namespaceify sysctl_tcp_workaround_signed_windows
upstream commit: ceef9ab6be7234f9e49f79769e0da88d1dccfcc7

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-01-02 11:31:18 +08:00
Hongbo Li 4bd3c7c579 net: namespaceify sysctl_tcp_max_orphans
Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-01-02 11:29:45 +08:00
Hongbo Li 26fb4c44c9 net: namespaceify sysctl_tcp_no_delay_ack
isolate sysctl_tcp_no_delay_ack as net namespace

Signed-off-by: Hongbo Li <herberthbli@tencent.com>
2020-01-02 11:29:03 +08:00
Xiaoming Gao 78a8c3c2c2 Init Repo base on 4.14.105 long term, and add base tlinux kernel interfaces
Signed-off-by: Xiaoming Gao <newtongao@tencent.com>
2020-01-02 10:51:04 +08:00