Skip to contentSkip to conversation

fs/partitions/msdos.c Guard against negative sizes

PATCH In review Ph. Marek 2 participants 2 messages Jan 27, 2003

lore
Share & tools
lore

Ph. Marek

author
#0 lore raw

PATCH 1/1 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.

Regards,

Phil

diff -u linux-2.5.59/fs/partitions/msdos.c.orig
linux-2.5.59/fs/partitions/msdos.c

fs/partitions/msdos.c Mon Jan 27 12:24:28 2003 renamed from fs/partitions/msdos.c.orig Mon Jan 27 12:22:45 2003 +3 -1
@@ -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
#1 lore raw

[ach, I didnt pay attention, had not seen that this was cc-ed to l-k; let me repeat on l-k]

fs/partitions/msdos.c Mon Jan 27 12:24:28 2003 line 428

Quoted 3 lines · Ph. Marek
                u32 size = NR_SECTS(p)*sector_size;
fs/partitions/msdos.c Mon Jan 27 12:24:28 2003 renamed from fs/partitions/msdos.c.orig Mon Jan 27 12:22:45 2003 +1 -1
-               if (!size)
+               if (size <= 0)

This doesnt work since size is unsigned.

Andries