* [patch] udf: potential integer overflow
@ 2010-03-15 8:21 Dan Carpenter
2010-03-15 12:08 ` Jan Kara
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2010-03-15 8:21 UTC (permalink / raw)
To: Jan Kara
Cc: Pekka Enberg, Hannes Eder, Akinobu Mita, Al Viro, linux-kernel,
kernel-janitors
bloc->logicalBlockNum is unsigned so it's never less than zero.
When I saw that, it made me worry that "bloc->logicalBlockNum + count"
could overflow. That's why I changed the check for less than zero
to an overflow check. (The test works because "count" is also
unsigned.)
Signed-off-by: Dan Carpenter <error27@gmail.com>
---
GCC 4.1 apparently optimizes overflow checks like this away, but it should
work for other versions of gcc. I tested with GCC 4.3.
http://www.fefe.de/intof.html
diff --git a/fs/udf/balloc.c b/fs/udf/balloc.c
index 19626e2..9a9378b 100644
--- a/fs/udf/balloc.c
+++ b/fs/udf/balloc.c
@@ -125,9 +125,8 @@ static void udf_bitmap_free_blocks(struct super_block *sb,
mutex_lock(&sbi->s_alloc_mutex);
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
- if (bloc->logicalBlockNum < 0 ||
- (bloc->logicalBlockNum + count) >
- partmap->s_partition_len) {
+ if (bloc->logicalBlockNum + count < count ||
+ (bloc->logicalBlockNum + count) > partmap->s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n",
bloc->logicalBlockNum, 0, bloc->logicalBlockNum,
count, partmap->s_partition_len);
@@ -393,9 +392,8 @@ static void udf_table_free_blocks(struct super_block *sb,
mutex_lock(&sbi->s_alloc_mutex);
partmap = &sbi->s_partmaps[bloc->partitionReferenceNum];
- if (bloc->logicalBlockNum < 0 ||
- (bloc->logicalBlockNum + count) >
- partmap->s_partition_len) {
+ if (bloc->logicalBlockNum + count < count ||
+ (bloc->logicalBlockNum + count) > partmap->s_partition_len) {
udf_debug("%d < %d || %d + %d > %d\n",
bloc->logicalBlockNum, 0, bloc->logicalBlockNum, count,
partmap->s_partition_len);
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [patch] udf: potential integer overflow
2010-03-15 8:21 [patch] udf: potential integer overflow Dan Carpenter
@ 2010-03-15 12:08 ` Jan Kara
0 siblings, 0 replies; 2+ messages in thread
From: Jan Kara @ 2010-03-15 12:08 UTC (permalink / raw)
To: Dan Carpenter
Cc: Jan Kara, Pekka Enberg, Hannes Eder, Akinobu Mita, Al Viro,
linux-kernel, kernel-janitors
On Mon 15-03-10 11:21:13, Dan Carpenter wrote:
> bloc->logicalBlockNum is unsigned so it's never less than zero.
>
> When I saw that, it made me worry that "bloc->logicalBlockNum + count"
> could overflow. That's why I changed the check for less than zero
> to an overflow check. (The test works because "count" is also
> unsigned.)
>
> Signed-off-by: Dan Carpenter <error27@gmail.com>
Thanks. Merged.
> ---
> GCC 4.1 apparently optimizes overflow checks like this away, but it should
> work for other versions of gcc. I tested with GCC 4.3.
> http://www.fefe.de/intof.html
It should only optimize them out for signed types (moreover kernel has
this optimization turned off so it's a non-issue for us anyway).
Honza
--
Jan Kara <jack@suse.cz>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-15 12:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-15 8:21 [patch] udf: potential integer overflow Dan Carpenter
2010-03-15 12:08 ` Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox