Skip to content

Commit 1448c72

Browse files
ebiedermroot
authored andcommitted
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. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent a877ee0 commit 1448c72

7 files changed

Lines changed: 14 additions & 11 deletions

File tree

‎arch/mips/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ struct compat_statfs {
111111
int f_bavail;
112112
compat_fsid_t f_fsid;
113113
int f_namelen;
114-
int f_spare[6];
114+
int f_flags;
115+
int f_spare[5];
115116
};
116117

117118
#define COMPAT_RLIM_INFINITY 0x7fffffffUL

‎arch/parisc/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ struct compat_statfs {
105105
__kernel_fsid_t f_fsid;
106106
s32 f_namelen;
107107
s32 f_frsize;
108-
s32 f_spare[5];
108+
s32 f_flags;
109+
s32 f_spare[4];
109110
};
110111

111112
struct compat_sigcontext {

‎arch/powerpc/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ struct compat_statfs {
100100
compat_fsid_t f_fsid;
101101
int f_namelen; /* SunOS ignores this field. */
102102
int f_frsize;
103-
int f_spare[5];
103+
int f_flags;
104+
int f_spare[4];
104105
};
105106

106107
#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff

‎arch/s390/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ struct compat_statfs {
131131
compat_fsid_t f_fsid;
132132
s32 f_namelen;
133133
s32 f_frsize;
134-
s32 f_spare[6];
134+
s32 f_flags;
135+
s32 f_spare[5];
135136
};
136137

137138
#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff

‎arch/sparc/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,8 @@ struct compat_statfs {
134134
compat_fsid_t f_fsid;
135135
int f_namelen; /* SunOS ignores this field. */
136136
int f_frsize;
137-
int f_spare[5];
137+
int f_flags;
138+
int f_spare[4];
138139
};
139140

140141
#define COMPAT_RLIM_INFINITY 0x7fffffff

‎arch/x86/include/asm/compat.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ struct compat_statfs {
108108
compat_fsid_t f_fsid;
109109
int f_namelen; /* SunOS ignores this field. */
110110
int f_frsize;
111-
int f_spare[5];
111+
int f_flags;
112+
int f_spare[4];
112113
};
113114

114115
#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff

‎fs/compat.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,8 @@ static int put_compat_statfs(struct compat_statfs __user *ubuf, struct kstatfs *
247247
__put_user(kbuf->f_fsid.val[0], &ubuf->f_fsid.val[0]) ||
248248
__put_user(kbuf->f_fsid.val[1], &ubuf->f_fsid.val[1]) ||
249249
__put_user(kbuf->f_frsize, &ubuf->f_frsize) ||
250-
__put_user(0, &ubuf->f_spare[0]) ||
251-
__put_user(0, &ubuf->f_spare[1]) ||
252-
__put_user(0, &ubuf->f_spare[2]) ||
253-
__put_user(0, &ubuf->f_spare[3]) ||
254-
__put_user(0, &ubuf->f_spare[4]))
250+
__put_user(kbuf->f_flags, &ubuf->f_flags) ||
251+
__clear_user(ubuf->f_spare, sizeof(ubuf->f_spare)))
255252
return -EFAULT;
256253
return 0;
257254
}

0 commit comments

Comments
 (0)