Skip to contentSkip to conversation

fat: Fix non-atomic NFS i_pos read

PATCH Superseded Steven J. Magnani 2 participants 4 messages Jun 29, 2012 VFAT/FAT/msdos filesystem

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fat: Fix non-atomic NFS i_pos read

fat_encode_fh() can fetch an invalid i_pos value on systems where 64-bit accesses are not atomic. Make it use the same accessor as the rest of the FAT code.

---

fs/fat/inode.c +7 -7
diff -uprN linux-3.5-rc4/fs/fat/inode.c new/fs/fat/inode.c
@@ -738,22 +738,22 @@ static int
 fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
 {
 	int len = *lenp;
-	u32 ipos_h, ipos_m, ipos_l;
+	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);
+	loff_t i_pos;
 
 	if (len < 5) {
 		*lenp = 5;
 		return 255; /* no room */
 	}
 
-	ipos_h = MSDOS_I(inode)->i_pos >> 8;
-	ipos_m = (MSDOS_I(inode)->i_pos & 0xf0) << 24;
-	ipos_l = (MSDOS_I(inode)->i_pos & 0x0f) << 28;
+	i_pos = fat_i_pos_read(sbi, inode);
 	*lenp = 5;
 	fh[0] = inode->i_ino;
 	fh[1] = inode->i_generation;
-	fh[2] = ipos_h;
-	fh[3] = ipos_m | MSDOS_I(inode)->i_logstart;
-	fh[4] = ipos_l;
+	fh[2] = i_pos >> 8;
+	fh[3] = ((i_pos & 0xf0) << 24) | MSDOS_I(inode)->i_logstart;
+	fh[4] = (i_pos & 0x0f) << 28;
 	if (parent)
 		fh[4] |= MSDOS_I(parent)->i_logstart;
 	return 3;
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Steven J. Magnani

fat_encode_fh() can fetch an invalid i_pos value on systems where 64-bit accesses are not atomic. Make it use the same accessor as the rest of the FAT code.

---
diff -uprN linux-3.5-rc4/fs/fat/inode.c new/fs/fat/inode.c

fs/fat/inode.c static int · line 742

Quoted 6 lines
fs/fat/inode.c +2 -1
@@ -738,22 +738,22 @@ static int
 fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
 {
 	int len = *lenp;
-	u32 ipos_h, ipos_m, ipos_l;
+	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);

sb seems to be unused. So, we can just

	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);

true? Otherwise, ack.

Just curious, this happened on the real system? I recently heard about NFS issue.

Thanks.

Quoted 24 lines
fs/fat/inode.c +5 -6
+	loff_t i_pos;
 
 	if (len < 5) {
 		*lenp = 5;
 		return 255; /* no room */
 	}
 
-	ipos_h = MSDOS_I(inode)->i_pos >> 8;
-	ipos_m = (MSDOS_I(inode)->i_pos & 0xf0) << 24;
-	ipos_l = (MSDOS_I(inode)->i_pos & 0x0f) << 28;
+	i_pos = fat_i_pos_read(sbi, inode);
 	*lenp = 5;
 	fh[0] = inode->i_ino;
 	fh[1] = inode->i_generation;
-	fh[2] = ipos_h;
-	fh[3] = ipos_m | MSDOS_I(inode)->i_logstart;
-	fh[4] = ipos_l;
+	fh[2] = i_pos >> 8;
+	fh[3] = ((i_pos & 0xf0) << 24) | MSDOS_I(inode)->i_logstart;
+	fh[4] = (i_pos & 0x0f) << 28;
 	if (parent)
 		fh[4] |= MSDOS_I(parent)->i_logstart;
 	return 3;
Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw
Quoted 21 lines · OGAWA Hirofumi
Quoted 10 lines · Steven J. Magnani

fat_encode_fh() can fetch an invalid i_pos value on systems where 64-bit accesses are not atomic. Make it use the same accessor as the rest of the FAT code.

---
diff -uprN linux-3.5-rc4/fs/fat/inode.c new/fs/fat/inode.c

fs/fat/inode.c static int · line 742

Quoted 6 lines
fs/fat/inode.c +2 -1
@@ -738,22 +738,22 @@ static int
 fat_encode_fh(struct inode *inode, __u32 *fh, int *lenp, struct inode *parent)
 {
 	int len = *lenp;
-	u32 ipos_h, ipos_m, ipos_l;
+	struct super_block *sb = inode->i_sb;
+	struct msdos_sb_info *sbi = MSDOS_SB(sb);

sb seems to be unused. So, we can just

Quoted 3 lines
	struct msdos_sb_info *sbi = MSDOS_SB(inode->i_sb);

true? Otherwise, ack.

OK, I'll repost with that change.

Quoted 5 lines

Just curious, this happened on the real system? I recently heard about NFS issue.

Not that I'm aware of. Can you point me to any discussion of the NFS issue? I've spent a lot of time recently studying the FAT NFS implementation and come to the conclusion that it is extremely vulnerable to inode eviction. More to follow...

Regards,
Steve

maintainer
#3 lore raw
Quoted 6 lines · Steven J. Magnani
Quoted 2 lines

Just curious, this happened on the real system? I recently heard about NFS issue.

Not that I'm aware of. Can you point me to any discussion of the NFS issue? I've spent a lot of time recently studying the FAT NFS implementation and come to the conclusion that it is extremely vulnerable to inode eviction. More to follow...

It is true, I also know NFS support of FAT is broken, but I'm not sure if it was read-only. Sorry, recent report was by private email, not public.

Signature · 1 line
OGAWA Hirofumi <[email protected]>