Skip to contentSkip to conversation

fat: Fix uninitialized field in nostale filehandles

PATCH Applied Jan Kara 2 participants 2 messages Feb 5, 2024

Subsystems (2)
lore
Share & tools
lore

Jan Kara

author reviewer
#0 lore raw

PATCH 1/1 fat: Fix uninitialized field in nostale filehandles

When fat_encode_fh_nostale() encodes file handle without a parent it stores only first 10 bytes of the file handle. However the length of the file handle must be a multiple of 4 so the file handle is actually 12 bytes long and the last two bytes remain uninitialized. This is not great at we potentially leak uninitialized information with the handle to userspace. Properly initialize the full handle length.

Reported-by [email protected]
Fixes ea3983ace6b7 ("fat: restructure export_operations")
---
 fs/fat/nfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/fat/nfs.c +6 -0
index c52e63e10d35..509eea96a457 100644
@@ -130,6 +130,12 @@ fat_encode_fh_nostale(struct inode *inode, __u32 *fh, int *lenp,
 		fid->parent_i_gen = parent->i_generation;
 		type = FILEID_FAT_WITH_PARENT;
 		*lenp = FAT_FID_SIZE_WITH_PARENT;
+	} else {
+		/*
+		 * We need to initialize this field because the fh is actually
+		 * 12 bytes long
+		 */
+		fid->parent_i_pos_hi = 0;
 	}
 
 	return type;
Signature · 1 line
2.35.3
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Jan Kara

When fat_encode_fh_nostale() encodes file handle without a parent it stores only first 10 bytes of the file handle. However the length of the file handle must be a multiple of 4 so the file handle is actually 12 bytes long and the last two bytes remain uninitialized. This is not great at we potentially leak uninitialized information with the handle to userspace. Properly initialize the full handle length.

Reported-by [email protected]
Fixes ea3983ace6b7 ("fat: restructure export_operations")

We can clean up more though, the fix itself looks good. Thanks.

Quoted 21 lines
---
 fs/fat/nfs.c | 6 ++++++
 1 file changed, 6 insertions(+)
fs/fat/nfs.c +6 -0
index c52e63e10d35..509eea96a457 100644
@@ -130,6 +130,12 @@ fat_encode_fh_nostale(struct inode *inode, __u32 *fh, int *lenp,
 		fid->parent_i_gen = parent->i_generation;
 		type = FILEID_FAT_WITH_PARENT;
 		*lenp = FAT_FID_SIZE_WITH_PARENT;
+	} else {
+		/*
+		 * We need to initialize this field because the fh is actually
+		 * 12 bytes long
+		 */
+		fid->parent_i_pos_hi = 0;
 	}
 
 	return type;
Signature · 1 line
OGAWA Hirofumi <[email protected]>