* [PATCH] blkdiscard: fix underflow when offset is greater than device size
@ 2014-10-09 0:46 Raphael S. Carvalho
2014-10-14 10:14 ` Karel Zak
0 siblings, 1 reply; 2+ messages in thread
From: Raphael S. Carvalho @ 2014-10-09 0:46 UTC (permalink / raw)
To: util-linux; +Cc: Raphael S. Carvalho
From: "Raphael S. Carvalho" <raphaelsc@cloudius-systems.com>
If offset (range[0]) is greater than device size (blksize), the variable 'end'
will be greater than blksize, and range[1] (length) will be recalculated.
The underflow happens when subtracting range[0] (offset) from blksize, thus
range[1] will be the result of an underflow. The bug leads to unwanted behavior
from the program, where range[1] is likely to be a high number and then will
discard a considerable amount of blocks from the device. The fix consists of
exitting the program with an error message when the condition stated above is
true. Spotted while auditing the code.
Signed-off-by: Raphael S. Carvalho <raphaelsc@cloudius-systems.com>
---
sys-utils/blkdiscard.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/sys-utils/blkdiscard.c b/sys-utils/blkdiscard.c
index 2ddcdb1..2f22af7 100644
--- a/sys-utils/blkdiscard.c
+++ b/sys-utils/blkdiscard.c
@@ -149,6 +149,8 @@ int main(int argc, char **argv)
range[1] &= ~(secsize - 1);
/* is the range end behind the end of the device ?*/
+ if (range[0] > blksize)
+ err(EXIT_FAILURE, _("%s: offset is greater than device size"), path);
end = range[0] + range[1];
if (end < range[0] || end > blksize)
range[1] = blksize - range[0];
--
1.9.3
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] blkdiscard: fix underflow when offset is greater than device size
2014-10-09 0:46 [PATCH] blkdiscard: fix underflow when offset is greater than device size Raphael S. Carvalho
@ 2014-10-14 10:14 ` Karel Zak
0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2014-10-14 10:14 UTC (permalink / raw)
To: Raphael S. Carvalho; +Cc: util-linux
On Wed, Oct 08, 2014 at 09:46:07PM -0300, Raphael S. Carvalho wrote:
> sys-utils/blkdiscard.c | 2 ++
> 1 file changed, 2 insertions(+)
Applied, thanks.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-10-14 10:14 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-09 0:46 [PATCH] blkdiscard: fix underflow when offset is greater than device size Raphael S. Carvalho
2014-10-14 10:14 ` Karel Zak
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).