
From: Andries Brouwer <Andries.Brouwer@cwi.nl>

The patch examines a putative partition table, and if that doesnt look like a
valid partition table it goes away again.

Some devices have partition tables (and there are many styles of such), some
don't.  Traditionally fixed disks have one, floppies don't.  Nobody knows what
happens with ZIP disks, USB sticks and other such things.  Both the DOS-type
partition table, and the "big floppy" whole disk FAT filesystem are common. 
It is undesirable for the kernel to detect partitions where there are none. 
This leads to great confusion, sometimes to kernel crashes.

In the particular case of DOS-type partition tables a partition entry has a
1-byte field boot_ind that traditionally is 0x80 for the boot partition and 0
for the other three primary partitions.  Linux does not use this field, and
one sometimes sees tables with all four entries zero.

The patch tells the kernel not to think that something is a valid DOS-type
partition table when a value other than 0 or 0x80 is encountered.  I think it
is a fairly safe change: I do not know of any fdisk-type program that will
write other values there.


---

 25-akpm/fs/partitions/msdos.c |   17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletion(-)

diff -puN fs/partitions/msdos.c~partition-table-validity-checking fs/partitions/msdos.c
--- 25/fs/partitions/msdos.c~partition-table-validity-checking	2004-05-23 12:39:03.968908776 -0700
+++ 25-akpm/fs/partitions/msdos.c	2004-05-23 12:39:03.971908320 -0700
@@ -389,8 +389,23 @@ int msdos_partition(struct parsed_partit
 		put_dev_sector(sect);
 		return 0;
 	}
+
+	/*
+	 * Now that the 55aa signature is present, this is probably
+	 * either the boot sector of a FAT filesystem or a DOS-type
+	 * partition table. Reject this in case the boot indicator
+	 * is not 0 or 0x80.
+	 */
 	p = (struct partition *) (data + 0x1be);
+	for (slot = 1; slot <= 4; slot++, p++) {
+		if (p->boot_ind != 0 && p->boot_ind != 0x80) {
+			put_dev_sector(sect);
+			return 0;
+		}
+	}
+
 #ifdef CONFIG_EFI_PARTITION
+	p = (struct partition *) (data + 0x1be);
 	for (slot = 1 ; slot <= 4 ; slot++, p++) {
 		/* If this is an EFI GPT disk, msdos should ignore it. */
 		if (SYS_IND(p) == EFI_PMBR_OSTYPE_EFI_GPT) {
@@ -398,8 +413,8 @@ int msdos_partition(struct parsed_partit
 			return 0;
 		}
 	}
-	p = (struct partition *) (data + 0x1be);
 #endif
+	p = (struct partition *) (data + 0x1be);
 
 	/*
 	 * Look for partitions in two passes:

_
