mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] fs/partitions/msdos.c Guard against negative sizes
@ 2003-01-27 11:30 Ph. Marek
  2003-01-27 14:03 ` Andries Brouwer
  0 siblings, 1 reply; 4+ messages in thread
From: Ph. Marek @ 2003-01-27 11:30 UTC (permalink / raw)
  To: aeb; +Cc: linux-kernel

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



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/partitions/msdos.c Guard against negative sizes
  2003-01-27 11:30 [PATCH] fs/partitions/msdos.c Guard against negative sizes Ph. Marek
@ 2003-01-27 14:03 ` Andries Brouwer
  0 siblings, 0 replies; 4+ messages in thread
From: Andries Brouwer @ 2003-01-27 14:03 UTC (permalink / raw)
  To: Ph. Marek; +Cc: aeb, linux-kernel

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

On Mon, Jan 27, 2003 at 12:30:05PM +0100, Ph. Marek wrote:

>                 u32 size = NR_SECTS(p)*sector_size;
> -               if (!size)
> +               if (size <= 0)

This doesnt work since size is unsigned.

Andries

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/partitions/msdos.c Guard against negative sizes
@ 2003-01-27 16:48 Andries.Brouwer
  0 siblings, 0 replies; 4+ messages in thread
From: Andries.Brouwer @ 2003-01-27 16:48 UTC (permalink / raw)
  To: Andries.Brouwer, philipp.marek; +Cc: linux-kernel

    u32 start = START_SECT(p)*sector_size;
    u32 size = NR_SECTS(p)*sector_size;
    And this looks as if it was calculated in bytes

But it is not. It converts hardware sector size units
to 512-byte units. For example, some MO disks use
2048-byte sectors, and also have the partition tables
in that unit.

    What about overflow?

More detailed checking of the table is certainly possible.

[But then, weird tables only occur when people fiddle with
the partition table themselves. Or when an accident happened.
I am not sure inhibiting access to partitions that look strange
is useful. It might make rescue operations difficult or impossible.]

    And btw, when can a partition that extends beyond the end
    be "allowed or even necessary"?

One reason is that "the end" is not well-defined. E.g.,
disk manufacturers invent jumpers that make the disk appear
smaller than it is in reality in order to avoid BIOS bugs.
See http://www.win.tue.nl/~aeb/linux/Large-Disk-11.html#ss11.3

In many cases the kernel option CONFIG_IDEDISK_STROKE will tell
the kernel to automatically fix up fake lengths. If that doesn't
work, a user mode utility may be needed to give the disk full size.
Since that utility is run after the kernel does the partition detection,
it is often easiest to let the last logical partition start just before
the fake end.

Andries

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fs/partitions/msdos.c Guard against negative sizes
       [not found] <UTC200301271203.h0RC3Sb19647.aeb@smtp.cwi.nl>
@ 2003-01-27 15:38 ` Ph. Marek
  0 siblings, 0 replies; 4+ messages in thread
From: Ph. Marek @ 2003-01-27 15:38 UTC (permalink / raw)
  To: Andries.Brouwer; +Cc: linux-kernel

> >             u32 size = NR_SECTS(p)*sector_size;
> > -           if (!size)
> > +           if (size <= 0)
>
> But an unsigned variable cannot be negative, so what you write
> is the same as what was there already.
>
> In other words, your "negative" sizes are just very large positive.
>
> The test should be whether the partition extends beyond the end
> of the disk, but sometimes that is allowed, even necessary, so
> there could be a warning only.
Sorry, didn't pay enough attention.
On second look: it's an u32.
But that brings the next question up: what about overflow? u32 means a max of 
4GB.
	u32 start = START_SECT(p)*sector_size;
	u32 size = NR_SECTS(p)*sector_size;
And this looks as if it was calculated in bytes - but I'm sure that 4GB is not 
the max size! Where am I wrong??

And btw, when can a partition that extends beyond the end be "allowed or even 
necessary"?


Thanks for your answer!


Regards,

Phil



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-01-27 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-01-27 11:30 [PATCH] fs/partitions/msdos.c Guard against negative sizes Ph. Marek
2003-01-27 14:03 ` Andries Brouwer
     [not found] <UTC200301271203.h0RC3Sb19647.aeb@smtp.cwi.nl>
2003-01-27 15:38 ` Ph. Marek
2003-01-27 16:48 Andries.Brouwer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®