[PATCH] fs/partitions/msdos.c Guard against negative sizes

From: Ph. Marek (philipp.marek@bmlv.gv.at)
Date: Mon Jan 27 2003 - 06:30:05 EST


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.

Regards,

Phil

diff -u linux-2.5.59/fs/partitions/msdos.c.orig
linux-2.5.59/fs/partitions/msdos.c
--- 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)
                        continue;
                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 majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Jan 31 2003 - 22:00:16 EST