netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Denis V. Lunev" <den@openvz.org>
To: netdev@vger.kernel.org
Cc: aarapov@redhat.com, dev@openvz.org, den@openvz.org
Subject: [PATCH] division-by-zero in inet_csk_get_port
Date: Wed, 10 Oct 2007 12:55:30 +0400	[thread overview]
Message-ID: <20071010085530.GA7532@iris.sw.ru> (raw)

This patch fixed a possible division-by-zero in inet_csk_get_port
treating situation low > high as if low == high.

Signed-off-by: Denis V. Lunev <den@openvz.org>
CC: Antov Arapov  <aarapov@redhat.com>

--- ./net/ipv4/inet_connection_sock.c.getport	2007-10-09 15:16:02.000000000 +0400
+++ ./net/ipv4/inet_connection_sock.c	2007-10-10 12:44:04.000000000 +0400
@@ -80,7 +80,14 @@ int inet_csk_get_port(struct inet_hashin
 		int low = sysctl_local_port_range[0];
 		int high = sysctl_local_port_range[1];
 		int remaining = (high - low) + 1;
-		int rover = net_random() % (high - low) + low;
+		int rover;
+
+		/* Treat low > high as high == low */
+		if (remaining <= 1) {
+			remaining = 1;
+			rover = low;
+		} else
+			rover = net_random() % (high - low) + low;
 
 		do {
 			head = &hashinfo->bhash[inet_bhashfn(rover, hashinfo->bhash_size)];

             reply	other threads:[~2007-10-10  8:53 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-10  8:55 Denis V. Lunev [this message]
2007-10-10  9:00 ` [PATCH] division-by-zero in inet_csk_get_port Anton Arapov
2007-10-10  9:35   ` David Miller
2007-10-10  9:56     ` Anton Arapov
2007-10-10 10:01       ` David Miller
2007-10-10 12:49         ` Anton Arapov
2007-10-10 15:04           ` Brian Haley

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=20071010085530.GA7532@iris.sw.ru \
    --to=den@openvz.org \
    --cc=aarapov@redhat.com \
    --cc=dev@openvz.org \
    --cc=netdev@vger.kernel.org \
    /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).