All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Elder <elder@inktank.com>
To: "ceph-devel@vger.kernel.org" <ceph-devel@vger.kernel.org>
Subject: [PATCH 2/3] rbd: check for overflow in rbd_get_num_segments()
Date: Tue, 22 Jan 2013 15:58:14 -0600	[thread overview]
Message-ID: <50FF0B76.5040402@inktank.com> (raw)
In-Reply-To: <50FF0B22.5060201@inktank.com>

The return type of rbd_get_num_segments() is int, but the values it
operates on are u64.  Although it's not likely, there's no guarantee
the result won't exceed what can be respresented in an int.  The
function is already designed to return -ERANGE on error, so just add
this possible overflow as another reason to return that.

Signed-off-by: Alex Elder <elder@inktank.com>
---
 drivers/block/rbd.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c
index 4ed0741..58d01e3 100644
--- a/drivers/block/rbd.c
+++ b/drivers/block/rbd.c
@@ -820,6 +820,7 @@ static int rbd_get_num_segments(struct
rbd_image_header *header,
 {
 	u64 start_seg;
 	u64 end_seg;
+	u64 result;

 	if (!len)
 		return 0;
@@ -829,7 +830,11 @@ static int rbd_get_num_segments(struct
rbd_image_header *header,
 	start_seg = ofs >> header->obj_order;
 	end_seg = (ofs + len - 1) >> header->obj_order;

-	return end_seg - start_seg + 1;
+	result = end_seg - start_seg + 1;
+	if (result > (u64) INT_MAX)
+		return -ERANGE;
+
+	return (int) result;
 }

 /*
-- 
1.7.9.5


  parent reply	other threads:[~2013-01-22 21:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22 21:56 [PATCH 0/3] rbd: a few simple changes Alex Elder
2013-01-22 21:57 ` [PATCH 1/3] rbd: small changes Alex Elder
2013-01-22 22:40   ` Dan Mick
2013-01-24 23:03   ` Josh Durgin
2013-01-22 21:58 ` Alex Elder [this message]
2013-01-22 22:40   ` [PATCH 2/3] rbd: check for overflow in rbd_get_num_segments() Dan Mick
2013-01-24 23:03   ` Josh Durgin
2013-01-22 21:58 ` [PATCH 3/3] rbd: don't retry setting up header watch Alex Elder
2013-01-24 23:09   ` Josh Durgin
2013-01-24 23:30     ` Alex Elder
2013-01-24 23:36       ` Josh Durgin

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=50FF0B76.5040402@inktank.com \
    --to=elder@inktank.com \
    --cc=ceph-devel@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.