[lkml]   [2003]   [Jan]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] fs/partitions/msdos.c Guard against negative sizes
Hello Andries,

I've recently had a partly destroyed pc where the partition size was negative.
I was at that time running a dos recovery disk and having severe problems -
it would not boot.

So I had the idea of looking into the linux kernel to see how it would handle
these. I wrote some checks in fs/partitions/msdos.c.
I'm not sure if just dropping this partitions is the right thing to do - but
as I don't know what could break if there are wrong entries I propose the
following patch: (incomplete - should check in many more places)

If there is a better way of handling this I'd like to know.



diff -u linux-2.5.59/fs/partitions/msdos.c.orig
--- linux-2.5.59/fs/partitions/msdos.c.orig Mon Jan 27 12:22:45 2003
+++ linux-2.5.59/fs/partitions/msdos.c Mon Jan 27 12:24:28 2003
@@ -133,6 +133,8 @@
these sometimes contain random garbage */
offs = START_SECT(p)*sector_size;
size = NR_SECTS(p)*sector_size;
+ if (size<0)
+ continue;
next = this_sector + offs;
if (i >= 2) {
if (offs + size > this_size)
@@ -423,7 +425,7 @@
for (slot = 1 ; slot <= 4 ; slot++, p++) {
u32 start = START_SECT(p)*sector_size;
u32 size = NR_SECTS(p)*sector_size;
- if (!size)
+ if (size <= 0)
if (is_extended_partition(p)) {
/* prevent someone doing mkfs or mkswap on an

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:32    [W:0.031 / U:2.020 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site