Skip to contentSkip to conversation

fat: FAT sector offsets overflow on large disks and/or FAT partitions

PATCH New Aaron Williams 3 participants 6 messages May 3, 2012 – May 22, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fat: FAT sector offsets overflow on large disks and/or FAT partitions

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. There are many cases which can cause an overflow, including large FAT32 partitions and partitions that start at a sufficiently large offset on the storage device.

Numerous issues were observed and fixed when a 64GB FAT32 filesystem was accessed due to truncation.

---
 include/fat.h |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
include/fat.h +5 -5
index 4c92442..7215628 100644
@@ -178,12 +178,12 @@ typedef struct dir_slot {
 typedef struct {
        __u8    *fatbuf;        /* Current FAT buffer */
        int     fatsize;        /* Size of FAT in bits */
-       __u16   fatlength;      /* Length of FAT in sectors */
-       __u16   fat_sect;       /* Starting sector of the FAT */
-       __u16   rootdir_sect;   /* Start sector of root directory */
-       __u16   sect_size;      /* Size of sectors in bytes */
+       __u32   fat_sect;       /* Starting sector of the FAT */
+       __u32   rootdir_sect;   /* Start sector of root directory */
+       __u32   fatlength;      /* Length of FAT in sectors */
        __u16   clust_size;     /* Size of clusters in sectors */
-       short   data_begin;     /* The sector of the first cluster, can be negative */
+       __u16   sect_size;      /* Size of sectors in bytes */
+       int     data_begin;     /* The sector of the first cluster, can be negative */
        int     fatbufnum;      /* Used by get_fatent, init to -1 */
 } fsdata;
 
Signature · 1 line
1.7.7
#1 lore raw

PATCH 1/1 fat: FAT sector offsets overflow on large disks and/or FAT partitions

Any comments on this patch?

Quoted 35 lines · Aaron Williams

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. There are many cases which can cause an overflow, including large FAT32 partitions and partitions that start at a sufficiently large offset on the storage device.

Numerous issues were observed and fixed when a 64GB FAT32 filesystem was accessed due to truncation.

---
 include/fat.h |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
include/fat.h +5 -5
index 4c92442..7215628 100644
@@ -178,12 +178,12 @@ typedef struct dir_slot {
 typedef struct {
        __u8    *fatbuf;        /* Current FAT buffer */
        int     fatsize;        /* Size of FAT in bits */
-       __u16   fatlength;      /* Length of FAT in sectors */
-       __u16   fat_sect;       /* Starting sector of the FAT */
-       __u16   rootdir_sect;   /* Start sector of root directory */
-       __u16   sect_size;      /* Size of sectors in bytes */
+       __u32   fat_sect;       /* Starting sector of the FAT */
+       __u32   rootdir_sect;   /* Start sector of root directory */
+       __u32   fatlength;      /* Length of FAT in sectors */
        __u16   clust_size;     /* Size of clusters in sectors */
-       short   data_begin;     /* The sector of the first cluster, can be negative */
+       __u16   sect_size;      /* Size of sectors in bytes */
+       int     data_begin;     /* The sector of the first cluster, can be negative */
        int     fatbufnum;      /* Used by get_fatent, init to -1 */
 } fsdata;
 
Signature · 4 lines
Aaron Williams
Software Engineer
Cavium, Inc.
(408) 943-7198  (510) 789-8988 (cell)
#2 lore raw

PATCH 1/1 fat: FAT sector offsets overflow on large disks and/or FAT partitions

In reply to Aaron Williams

Hello,

Quoted 4 lines · On Wed, 02 May 2012 19:17:41 -0700 Aaron Williams <[email protected]>…

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. There are many cases which can cause an overflow, including large FAT32 partitions and partitions that start at a sufficiently large offset on the storage device.

For large FAT32 partitions only changing of fatlength, rootdir_sect and data_begin is needed to avoid overflows. Changing of fat_sect shouldn't be needed.

What do you mean exactly by "partitions starting at a sufficiently large offset on the storage device"? How do you create such partition? I've tested with a 210 GB FAT32 partition as the fourth primary partition on a 2 TB disk. This partition is the last partition on the disk, so its offset is sufficiently large. For this test only fatlength, rootdir_sect and data_begin was changed to __u32 and int and I do not see issues when listing or loading the files from this partition.

Quoted 19 lines

Numerous issues were observed and fixed when a 64GB FAT32 filesystem was accessed due to truncation.

---
 include/fat.h |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
include/fat.h +0 -3
index 4c92442..7215628 100644
@@ -178,12 +178,12 @@ typedef struct dir_slot {
 typedef struct {
        __u8    *fatbuf;        /* Current FAT buffer */
        int     fatsize;        /* Size of FAT in bits */
-       __u16   fatlength;      /* Length of FAT in sectors */
-       __u16   fat_sect;       /* Starting sector of the FAT */
-       __u16   rootdir_sect;   /* Start sector of root directory */

include/fat.h typedef struct dir_slot { · line 188

Quoted 10 lines
include/fat.h +5 -2
-       __u16   sect_size;      /* Size of sectors in bytes */
+       __u32   fat_sect;       /* Starting sector of the FAT */
+       __u32   rootdir_sect;   /* Start sector of root directory */
+       __u32   fatlength;      /* Length of FAT in sectors */
        __u16   clust_size;     /* Size of clusters in sectors */
-       short   data_begin;     /* The sector of the first cluster, can be negative */
+       __u16   sect_size;      /* Size of sectors in bytes */
+       int     data_begin;     /* The sector of the first cluster, can be negative */
        int     fatbufnum;      /* Used by get_fatent, init to -1 */
 } fsdata;

The patch is probably corrupted by your mailer, it doesn't apply.

Thanks,
Anatolij

#3 lore raw

PATCH 1/1 fat: FAT sector offsets overflow on large disks and/or FAT partitions

Hi Anatolij,

Quoted 13 lines · Anatolij Gustschin

Hello,

Quoted 4 lines · On Wed, 02 May 2012 19:17:41 -0700 Aaron Williams <[email protected]>…

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. There are many cases which can cause an overflow, including large FAT32 partitions and partitions that start at a sufficiently large offset on the storage device.

For large FAT32 partitions only changing of fatlength, rootdir_sect and data_begin is needed to avoid overflows. Changing of fat_sect shouldn't be needed.

Quoted 7 lines

What do you mean exactly by "partitions starting at a sufficiently large offset on the storage device"? How do you create such partition? I've tested with a 210 GB FAT32 partition as the fourth primary partition on a 2 TB disk. This partition is the last partition on the disk, so its offset is sufficiently large. For this test only fatlength, rootdir_sect and data_begin was changed to __u32 and int and I do not see issues when listing or loading the files from this partition.

You are correct about fat_sect, I misread the code and changed that one as well. I don't think it really matters since another changing it back to a __u16 won't save any space in the data structure on most platforms.

It looks like the corruption problems I was seeing were due to the fact that the file I was reading was after a number of very large files in a 64GB FAT32 partition and I ran into overflows. The partition location shouldn't have any impact unless we're talking about 2+TB drives, in which case I expect there will be numerous other things that will break.

Quoted 31 lines
Quoted 19 lines

Numerous issues were observed and fixed when a 64GB FAT32 filesystem was accessed due to truncation.

---
 include/fat.h |   10 +++++-----
 1 files changed, 5 insertions(+), 5 deletions(-)
include/fat.h +0 -3
index 4c92442..7215628 100644
@@ -178,12 +178,12 @@ typedef struct dir_slot {
 typedef struct {
        __u8    *fatbuf;        /* Current FAT buffer */
        int     fatsize;        /* Size of FAT in bits */
-       __u16   fatlength;      /* Length of FAT in sectors */
-       __u16   fat_sect;       /* Starting sector of the FAT */
-       __u16   rootdir_sect;   /* Start sector of root directory */

include/fat.h typedef struct dir_slot { · line 188

Quoted 10 lines
include/fat.h +5 -2
-       __u16   sect_size;      /* Size of sectors in bytes */
+       __u32   fat_sect;       /* Starting sector of the FAT */
+       __u32   rootdir_sect;   /* Start sector of root directory */
+       __u32   fatlength;      /* Length of FAT in sectors */
        __u16   clust_size;     /* Size of clusters in sectors */
-       short   data_begin;     /* The sector of the first cluster, can be negative */
+       __u16   sect_size;      /* Size of sectors in bytes */
+       int     data_begin;     /* The sector of the first cluster, can be negative */
        int     fatbufnum;      /* Used by get_fatent, init to -1 */
 } fsdata;

The patch is probably corrupted by your mailer, it doesn't apply.

Quoted 3 lines

Thanks,
Anatolij

Unfortunately our outbound Exchange mail server tends to "fix" mail formatting making patch submission rather difficult. I'll see what I can do to try and bypass it.

-Aaron

Signature · 4 lines
Aaron Williams
Software Engineer
Cavium, Inc.
(408) 943-7198  (510) 789-8988 (cell)
#4 lore raw

PATCH 1/1 fat: fix FAT sector offsets overflow on large FAT partitions

In reply to Aaron Williams

From: Aaron Williams <[email protected]>

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. The cases where an overflow can happen when accessing large FAT32 partitions are:

- length of FAT in sectors
- start sector of root directory
- the sector of the first cluster

These issues were observed when reading files from a 64GB FAT32 filesystem.

---
 include/fat.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
include/fat.h +3 -3
index 4c92442..f1b4a0d 100644
@@ -178,12 +178,12 @@ typedef struct dir_slot {
 typedef struct {
 	__u8	*fatbuf;	/* Current FAT buffer */
 	int	fatsize;	/* Size of FAT in bits */
-	__u16	fatlength;	/* Length of FAT in sectors */
+	__u32	fatlength;	/* Length of FAT in sectors */
 	__u16	fat_sect;	/* Starting sector of the FAT */
-	__u16	rootdir_sect;	/* Start sector of root directory */
+	__u32	rootdir_sect;	/* Start sector of root directory */
 	__u16	sect_size;	/* Size of sectors in bytes */
 	__u16	clust_size;	/* Size of clusters in sectors */
-	short	data_begin;	/* The sector of the first cluster, can be negative */
+	int	data_begin;	/* The sector of the first cluster, can be negative */
 	int	fatbufnum;	/* Used by get_fatent, init to -1 */
 } fsdata;
 
Signature · 1 line
1.7.1
#5 lore raw

PATCH 1/1 fat: fix FAT sector offsets overflow on large FAT partitions

Dear Anatolij Gustschin,

Quoted 13 lines · In message <[email protected]> you wrote:

From: Aaron Williams <[email protected]>

This patch fixes several issues where sector offsets can overflow due to being limited to 16-bits. The cases where an overflow can happen when accessing large FAT32 partitions are:

- length of FAT in sectors
- start sector of root directory
- the sector of the first cluster

These issues were observed when reading files from a 64GB FAT32 filesystem.

Quoted 6 lines
---
 include/fat.h |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

Applied, thanks.

Best regards,

Wolfgang Denk

Signature · 6 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The face of war has never changed.  Surely it is more logical to heal
than to kill.
	-- Surak of Vulcan, "The Savage Curtain", stardate 5906.5