linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Soheil Hassas Yeganeh <soheil@google.com>,
	Wei Wang <weiwan@google.com>,
	Neal Cardwell <ncardwell@google.com>,
	"David S. Miller" <davem@davemloft.net>,
	Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH 4.4 14/37] tcp: avoid integer overflows in tcp_rcv_space_adjust()
Date: Tue,  5 Jun 2018 19:01:19 +0200	[thread overview]
Message-ID: <20180605170109.740656848@linuxfoundation.org> (raw)
In-Reply-To: <20180605170108.884872354@linuxfoundation.org>

4.4-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Eric Dumazet <edumazet@google.com>

commit 607065bad9931e72207b0cac365d7d4abc06bd99 upstream.

When using large tcp_rmem[2] values (I did tests with 500 MB),
I noticed overflows while computing rcvwin.

Lets fix this before the following patch.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Acked-by: Soheil Hassas Yeganeh <soheil@google.com>
Acked-by: Wei Wang <weiwan@google.com>
Acked-by: Neal Cardwell <ncardwell@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[Backport: sysctl_tcp_rmem is not Namespace-ify'd in older kernels]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 include/linux/tcp.h  |    2 +-
 net/ipv4/tcp_input.c |   10 ++++++----
 2 files changed, 7 insertions(+), 5 deletions(-)

--- a/include/linux/tcp.h
+++ b/include/linux/tcp.h
@@ -324,7 +324,7 @@ struct tcp_sock {
 
 /* Receiver queue space */
 	struct {
-		int	space;
+		u32	space;
 		u32	seq;
 		u32	time;
 	} rcvq_space;
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -557,8 +557,8 @@ static inline void tcp_rcv_rtt_measure_t
 void tcp_rcv_space_adjust(struct sock *sk)
 {
 	struct tcp_sock *tp = tcp_sk(sk);
+	u32 copied;
 	int time;
-	int copied;
 
 	time = tcp_time_stamp - tp->rcvq_space.time;
 	if (time < (tp->rcv_rtt_est.rtt >> 3) || tp->rcv_rtt_est.rtt == 0)
@@ -580,12 +580,13 @@ void tcp_rcv_space_adjust(struct sock *s
 
 	if (sysctl_tcp_moderate_rcvbuf &&
 	    !(sk->sk_userlocks & SOCK_RCVBUF_LOCK)) {
-		int rcvwin, rcvmem, rcvbuf;
+		int rcvmem, rcvbuf;
+		u64 rcvwin;
 
 		/* minimal window to cope with packet losses, assuming
 		 * steady state. Add some cushion because of small variations.
 		 */
-		rcvwin = (copied << 1) + 16 * tp->advmss;
+		rcvwin = ((u64)copied << 1) + 16 * tp->advmss;
 
 		/* If rate increased by 25%,
 		 *	assume slow start, rcvwin = 3 * copied
@@ -605,7 +606,8 @@ void tcp_rcv_space_adjust(struct sock *s
 		while (tcp_win_from_space(rcvmem) < tp->advmss)
 			rcvmem += 128;
 
-		rcvbuf = min(rcvwin / tp->advmss * rcvmem, sysctl_tcp_rmem[2]);
+		do_div(rcvwin, tp->advmss);
+		rcvbuf = min_t(u64, rcvwin * rcvmem, sysctl_tcp_rmem[2]);
 		if (rcvbuf > sk->sk_rcvbuf) {
 			sk->sk_rcvbuf = rcvbuf;
 

  parent reply	other threads:[~2018-06-05 17:29 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 17:01 [PATCH 4.4 00/37] 4.4.136-stable review Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 01/37] arm64: lse: Add early clobbers to some input/output asm operands Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 02/37] powerpc/64s: Clear PCR on boot Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 03/37] USB: serial: cp210x: use tcflag_t to fix incompatible pointer type Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 04/37] sh: New gcc support Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 05/37] xfs: detect agfl count corruption and reset agfl Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 06/37] Revert "ima: limit file hash setting by user to fix and log modes" Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 07/37] Input: elan_i2c_smbus - fix corrupted stack Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 08/37] tracing: Fix crash when freeing instances with event triggers Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 09/37] selinux: KASAN: slab-out-of-bounds in xattr_getsecurity Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 10/37] cfg80211: further limit wiphy names to 64 bytes Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 11/37] rtlwifi: rtl8192cu: Remove variable self-assignment in rf.c Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 12/37] ASoC: Intel: sst: remove redundant variable dma_dev_name Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 13/37] irda: fix overly long udelay() Greg Kroah-Hartman
2018-06-05 17:01 ` Greg Kroah-Hartman [this message]
2018-06-05 17:01 ` [PATCH 4.4 15/37] i2c: rcar: make sure clocks are on when doing clock calculation Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 16/37] i2c: rcar: rework hw init Greg Kroah-Hartman
2018-06-18 18:46   ` Ben Hutchings
2018-06-25 10:05     ` Fabrizio Castro
2018-06-05 17:01 ` [PATCH 4.4 17/37] i2c: rcar: remove unused IOERROR state Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 18/37] i2c: rcar: remove spinlock Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 19/37] i2c: rcar: refactor setup of a msg Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 20/37] i2c: rcar: init new messages in irq Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 21/37] i2c: rcar: dont issue stop when HW does it automatically Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 22/37] i2c: rcar: check master irqs before slave irqs Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 23/37] i2c: rcar: revoke START request early Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 24/37] dmaengine: usb-dmac: fix endless loop in usb_dmac_chan_terminate_all() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 25/37] iio:kfifo_buf: check for uint overflow Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 26/37] MIPS: ptrace: Fix PTRACE_PEEKUSR requests for 64-bit FGRs Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 27/37] MIPS: prctl: Disallow FRE without FR with PR_SET_FP_MODE requests Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 28/37] scsi: scsi_transport_srp: Fix shost to rport translation Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 29/37] stm class: Use vmalloc for the master map Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 30/37] hwtracing: stm: fix build error on some arches Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 32/37] Kbuild: change CC_OPTIMIZE_FOR_SIZE definition Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 33/37] fix io_destroy()/aio_complete() race Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 34/37] mm: fix the NULL mapping case in __isolate_lru_page() Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 35/37] sparc64: Add __multi3 for gcc 7.x and later Greg Kroah-Hartman
2018-06-05 17:01 ` [PATCH 4.4 36/37] sparc64: Dont clibber fixed registers in __multi4 Greg Kroah-Hartman
2018-06-05 21:59 ` [PATCH 4.4 00/37] 4.4.136-stable review Shuah Khan
2018-06-06  0:30 ` Nathan Chancellor
2018-06-06  8:19   ` Greg Kroah-Hartman
2018-06-06 11:18 ` Naresh Kamboju
2018-06-06 12:15   ` Greg Kroah-Hartman
2018-06-06 13:28 ` Guenter Roeck
2018-06-06 13:31   ` Greg Kroah-Hartman
2018-06-06 15:01     ` Guenter Roeck
2018-06-06 15:35       ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180605170109.740656848@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=ncardwell@google.com \
    --cc=soheil@google.com \
    --cc=stable@vger.kernel.org \
    --cc=weiwan@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).