Skip to content

Commit b8668fd

Browse files
heicarstMartin Schwidefsky
authored andcommitted
s390/uapi: change struct statfs[64] member types to unsigned values
Kay Sievers reported that coreutils' stat tool has a problem with s390's statfs[64] definition: > The definition of struct statfs::f_type needs a fix. s390 is the only > architecture in the kernel that uses an int and expects magic > constants lager than INT_MAX to fit into. > > A fix is needed to make Fedora boot on s390, it currently fails to do > so. Userspace does not want to add code to paper-over this issue. [...] > Even coreutils cannot handle it: > #define RAMFS_MAGIC 0x858458f6 > # stat -f -c%t / > ffffffff858458f6 > > #define BTRFS_SUPER_MAGIC 0x9123683E > # stat -f -c%t /mnt > ffffffff9123683e The bug is caused by an implicit sign extension within the stat tool: out_uint_x (pformat, prefix_len, statfsbuf->f_type); where the format finally will be "%lx". A similar problem can be found in the 'tail' tool. s390 is the only architecture which has an int type f_type member in struct statfs[64]. Other architectures have either unsigned ints or long values, so that the problem doesn't occur there. Therefore change the type of the f_type member to unsigned int, so that we get zero extension instead of sign extension when assignment to a long value happens. This patch changes the s390 uapi struct stafs[64] definition in the kernel to contain only unsigned values. This was true for 32 bit builds anyway, since we use the generic uapi header file in that case. So lets not include conditionally the generic uapi header file but have the s390 implementation completely independent. Also fix the types of struct compat_stafs to match reality and move the definition of struct compat_statfs64 to asm/compat.h since it is not part of the api. Reported-by: Kay Sievers <[email protected]> Signed-off-by: Heiko Carstens <[email protected]> Signed-off-by: Martin Schwidefsky <[email protected]>
1 parent 186f50f commit b8668fd

File tree

2 files changed

+48
-52
lines changed

2 files changed

+48
-52
lines changed

arch/s390/include/asm/compat.h

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,33 @@ struct compat_flock64 {
140140
};
141141

142142
struct compat_statfs {
143-
s32 f_type;
144-
s32 f_bsize;
145-
s32 f_blocks;
146-
s32 f_bfree;
147-
s32 f_bavail;
148-
s32 f_files;
149-
s32 f_ffree;
143+
u32 f_type;
144+
u32 f_bsize;
145+
u32 f_blocks;
146+
u32 f_bfree;
147+
u32 f_bavail;
148+
u32 f_files;
149+
u32 f_ffree;
150150
compat_fsid_t f_fsid;
151-
s32 f_namelen;
152-
s32 f_frsize;
153-
s32 f_flags;
154-
s32 f_spare[4];
151+
u32 f_namelen;
152+
u32 f_frsize;
153+
u32 f_flags;
154+
u32 f_spare[4];
155+
};
156+
157+
struct compat_statfs64 {
158+
u32 f_type;
159+
u32 f_bsize;
160+
u64 f_blocks;
161+
u64 f_bfree;
162+
u64 f_bavail;
163+
u64 f_files;
164+
u64 f_ffree;
165+
compat_fsid_t f_fsid;
166+
u32 f_namelen;
167+
u32 f_frsize;
168+
u32 f_flags;
169+
u32 f_spare[4];
155170
};
156171

157172
#define COMPAT_RLIM_OLD_INFINITY 0x7fffffff

arch/s390/include/uapi/asm/statfs.h

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
#ifndef _S390_STATFS_H
88
#define _S390_STATFS_H
99

10-
#ifndef __s390x__
11-
#include <asm-generic/statfs.h>
12-
#else
1310
/*
1411
* We can't use <asm-generic/statfs.h> because in 64-bit mode
1512
* we mix ints of different sizes in our struct statfs.
@@ -21,49 +18,33 @@ typedef __kernel_fsid_t fsid_t;
2118
#endif
2219

2320
struct statfs {
24-
int f_type;
25-
int f_bsize;
26-
long f_blocks;
27-
long f_bfree;
28-
long f_bavail;
29-
long f_files;
30-
long f_ffree;
21+
unsigned int f_type;
22+
unsigned int f_bsize;
23+
unsigned long f_blocks;
24+
unsigned long f_bfree;
25+
unsigned long f_bavail;
26+
unsigned long f_files;
27+
unsigned long f_ffree;
3128
__kernel_fsid_t f_fsid;
32-
int f_namelen;
33-
int f_frsize;
34-
int f_flags;
35-
int f_spare[4];
29+
unsigned int f_namelen;
30+
unsigned int f_frsize;
31+
unsigned int f_flags;
32+
unsigned int f_spare[4];
3633
};
3734

3835
struct statfs64 {
39-
int f_type;
40-
int f_bsize;
41-
long f_blocks;
42-
long f_bfree;
43-
long f_bavail;
44-
long f_files;
45-
long f_ffree;
36+
unsigned int f_type;
37+
unsigned int f_bsize;
38+
unsigned long f_blocks;
39+
unsigned long f_bfree;
40+
unsigned long f_bavail;
41+
unsigned long f_files;
42+
unsigned long f_ffree;
4643
__kernel_fsid_t f_fsid;
47-
int f_namelen;
48-
int f_frsize;
49-
int f_flags;
50-
int f_spare[4];
44+
unsigned int f_namelen;
45+
unsigned int f_frsize;
46+
unsigned int f_flags;
47+
unsigned int f_spare[4];
5148
};
5249

53-
struct compat_statfs64 {
54-
__u32 f_type;
55-
__u32 f_bsize;
56-
__u64 f_blocks;
57-
__u64 f_bfree;
58-
__u64 f_bavail;
59-
__u64 f_files;
60-
__u64 f_ffree;
61-
__kernel_fsid_t f_fsid;
62-
__u32 f_namelen;
63-
__u32 f_frsize;
64-
__u32 f_flags;
65-
__u32 f_spare[4];
66-
};
67-
68-
#endif /* __s390x__ */
6950
#endif

0 commit comments

Comments
 (0)