[Linux-ia64] [PATCH] linux/fs/partitions/efi.c error handling

Alex Williamson
2002-02-14T17:11:19Z

[-- Attachment #1: Type: text/plain, Size: 807 bytes --]

I was testing w/ some disks that appear to have bad partition
tables and was getting the following error messages:

SCSI device sdt: 35566480 512-byte hdwr sectors (18210 MB)
sdt:<4> Warning: Disk has a valid GPT signature but invalid PMBR.
Use GNU Parted to correct disk.

Unfortunately, that's not where the problem stopped. I got
random pointer dereference problems, and was apparently having
data structures freed out from under them. Turns out the
find_valid_gpt() was freeing data structures more than once and
passing back pointers to freed structures. Patch below.

Alex

--
Alex Williamson Linux Development Lab
alex_williamson@hp.com Hewlett Packard
970-898-9173 Fort Collins, CO

[-- Attachment #2: efi.diff --]
[-- Type: text/plain, Size: 692 bytes --]

--- linux/fs/partitions/efi.c~ 25 Jan 2002 20:15:06 -0000 1.2
+++ linux/fs/partitions/efi.c 14 Feb 2002 16:50:07 -0000
@@ -549,10 +549,14 @@ find_valid_gpt(struct gendisk *hd, struc

*gpt = pgpt;
*ptes = pptes;
- if (agpt)
+ if (agpt) {
kfree(agpt);
- if (aptes)
+ agpt = NULL;
+ }
+ if (aptes) {
kfree(aptes);
+ aptes = NULL;
+ }
} /* if primary is valid */
else {
/* Primary GPT is bad, check the Alternate GPT */
@@ -602,6 +606,8 @@ find_valid_gpt(struct gendisk *hd, struc
/* Both primary and alternate GPTs are bad, and/or PMBR is invalid.
* This isn't our disk, return 0.
*/
+ *gpt = *ptes = NULL;
+
if (pgpt) {
kfree(pgpt);
pgpt = NULL;