Skip to contentSkip to conversation

compat: sync compat_stats with statfs.

PATCH In review Eric W. Biederman 2 participants 2 messages Oct 17, 2011 – Oct 19, 2011

Subsystems (8)
x86 VFS PowerPC MIPS +4 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 compat: sync compat_stats with statfs.

This was found by inspection while tracking a similar bug in compat_statfs64, that has been fixed in mainline since decemeber.

- This fixes a bug where not all of the f_spare fields were cleared on mips and s390.
- Add the f_flags field to struct compat_statfs
- Copy f_flags to userspace in case someone cares.
- Use __clear_user to copy the f_spare field to userspace to ensure that all of the elements of f_spare are cleared. On some architectures f_spare is has 5 ints and on some architectures f_spare only has 4 ints. Which makes the previous technique of clearing each int individually broken.

I don't expect anyone actually uses the old statfs system call anymore but if they do let them benefit from having the compat and the native version working the same.

---
 arch/mips/include/asm/compat.h    |    3 ++-
 arch/parisc/include/asm/compat.h  |    3 ++-
 arch/powerpc/include/asm/compat.h |    3 ++-
 arch/s390/include/asm/compat.h    |    3 ++-
 arch/sparc/include/asm/compat.h   |    3 ++-
 arch/x86/include/asm/compat.h     |    3 ++-
 fs/compat.c                       |    7 ++-----
 7 files changed, 14 insertions(+), 11 deletions(-)
arch/mips/include/asm/compat.h +2 -1
index dbc5106..b77df03 100644
@@ -111,7 +111,8 @@ struct compat_statfs {
 	int		f_bavail;
 	compat_fsid_t	f_fsid;
 	int		f_namelen;
-	int		f_spare[6];
+	int		f_flags;
+	int		f_spare[5];
 };
 
 #define COMPAT_RLIM_INFINITY	0x7fffffffUL
arch/parisc/include/asm/compat.h +2 -1
index efa0b60..760f331 100644
@@ -105,7 +105,8 @@ struct compat_statfs {
 	__kernel_fsid_t	f_fsid;
 	s32		f_namelen;
 	s32		f_frsize;
-	s32		f_spare[5];
+	s32		f_flags;
+	s32		f_spare[4];
 };
 
 struct compat_sigcontext {
arch/powerpc/include/asm/compat.h +2 -1
index 91010e8..88e602f 100644
@@ -100,7 +100,8 @@ struct compat_statfs {
 	compat_fsid_t	f_fsid;
 	int		f_namelen;	/* SunOS ignores this field. */
 	int		f_frsize;
-	int		f_spare[5];
+	int		f_flags;
+	int		f_spare[4];
 };
 
 #define COMPAT_RLIM_OLD_INFINITY	0x7fffffff
arch/s390/include/asm/compat.h +2 -1
index da359ca..cdb9b78 100644
@@ -131,7 +131,8 @@ struct compat_statfs {
 	compat_fsid_t	f_fsid;
 	s32		f_namelen;
 	s32		f_frsize;
-	s32		f_spare[6];
+	s32		f_flags;
+	s32		f_spare[5];
 };
 
 #define COMPAT_RLIM_OLD_INFINITY	0x7fffffff
arch/sparc/include/asm/compat.h +2 -1
index 6f57325..b8be20d 100644
@@ -134,7 +134,8 @@ struct compat_statfs {
 	compat_fsid_t	f_fsid;
 	int		f_namelen;	/* SunOS ignores this field. */
 	int		f_frsize;
-	int		f_spare[5];
+	int		f_flags;
+	int		f_spare[4];
 };
 
 #define COMPAT_RLIM_INFINITY 0x7fffffff
arch/x86/include/asm/compat.h +2 -1
index 1d9cd27..30d737e 100644
@@ -108,7 +108,8 @@ struct compat_statfs {
 	compat_fsid_t	f_fsid;
 	int		f_namelen;	/* SunOS ignores this field. */
 	int		f_frsize;
-	int		f_spare[5];
+	int		f_flags;
+	int		f_spare[4];
 };
 
 #define COMPAT_RLIM_OLD_INFINITY	0x7fffffff
fs/compat.c +2 -5
index 58b1da4..0f1ab46 100644
@@ -247,11 +247,8 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
 	    __put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
 	    __put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
 	    __put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
-	    __put_user(0, &ubuf->f_spare[0]) || 
-	    __put_user(0, &ubuf->f_spare[1]) || 
-	    __put_user(0, &ubuf->f_spare[2]) || 
-	    __put_user(0, &ubuf->f_spare[3]) || 
-	    __put_user(0, &ubuf->f_spare[4]))
+	    __put_user(kbuf->f_flags, &ubuf->f_flags) ||
+	    __clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
 		return -EFAULT;
 	return 0;
 }
Signature · 1 line
1.7.2.5
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · On Monday 17 October 2011 13:40:02 Eric W. Biederman wrote:

This was found by inspection while tracking a similar bug in compat_statfs64, that has been fixed in mainline since decemeber.

- This fixes a bug where not all of the f_spare fields were cleared on mips and s390.
- Add the f_flags field to struct compat_statfs
- Copy f_flags to userspace in case someone cares.
- Use __clear_user to copy the f_spare field to userspace to ensure that all of the elements of f_spare are cleared. On some architectures f_spare is has 5 ints and on some architectures f_spare only has 4 ints. Which makes the previous technique of clearing each int individually broken.

Quoted 5 lines

I don't expect anyone actually uses the old statfs system call anymore but if they do let them benefit from having the compat and the native version working the same.

Looks good to me.

Apparently, this could have been worse on tile, which has #define compat_statfs statfs, so that the old "__put_user(0, &ubuf->f_spare[4]))" was writing beyond the end of struct statfs. Fortunately, this never gets called on tile, which only provides compat_sys_statfs64 to user space, not compat_sys_statfs.

Arnd