[lkml]   [2018]   [Dec]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Patch in this message
Subject[PATCH] vfat: don't read garbage after last dirent
The FAT32 File System Specification[1] states:

If DIR_Name[0] == 0x00, then the directory entry is free, and there
are no allocated directory entries after this one.

The special 0 value, indicates to FAT file system driver code that
the rest of the entries in this directory do notneed to be examined
because they are all free.

This is not enforced by Linux, and is possible to read garbage if
not all the dirents after the last one are filled with zeroes.


Reported-by: Timothy Redaelli <>
Signed-off-by: Matteo Croce <>
fs/fat/dir.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index c8366cb8eccd..0cec89271349 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -588,7 +588,7 @@ static int __fat_readdir(struct inode *inode, struct file *file,

bh = NULL;
- if (fat_get_entry(inode, &cpos, &bh, &de) == -1)
+ if (fat_get_entry(inode, &cpos, &bh, &de) == -1 || !de->name[0])
goto end_of_dir;
nr_slots = 0;
 \ /
  Last update: 2018-12-07 02:34    [W:0.039 / U:13.992 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site