]>
Commit | Line | Data |
---|---|---|
f15b2821 GKH |
1 | From a4d2aadca184ece182418950d45ba4ffc7b652d2 Mon Sep 17 00:00:00 2001 |
2 | From: Arnd Bergmann <arnd@arndb.de> | |
3 | Date: Sun, 29 Jul 2018 15:48:00 -0400 | |
4 | Subject: ext4: sysfs: print ext4_super_block fields as little-endian | |
5 | ||
6 | From: Arnd Bergmann <arnd@arndb.de> | |
7 | ||
8 | commit a4d2aadca184ece182418950d45ba4ffc7b652d2 upstream. | |
9 | ||
10 | While working on extended rand for last_error/first_error timestamps, | |
11 | I noticed that the endianess is wrong; we access the little-endian | |
12 | fields in struct ext4_super_block as native-endian when we print them. | |
13 | ||
14 | This adds a special case in ext4_attr_show() and ext4_attr_store() | |
15 | to byteswap the superblock fields if needed. | |
16 | ||
17 | In older kernels, this code was part of super.c, it got moved to | |
18 | sysfs.c in linux-4.4. | |
19 | ||
20 | Cc: stable@vger.kernel.org | |
21 | Fixes: 52c198c6820f ("ext4: add sysfs entry showing whether the fs contains errors") | |
22 | Reviewed-by: Andreas Dilger <adilger@dilger.ca> | |
23 | Signed-off-by: Arnd Bergmann <arnd@arndb.de> | |
24 | Signed-off-by: Theodore Ts'o <tytso@mit.edu> | |
25 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
26 | ||
27 | --- | |
28 | fs/ext4/sysfs.c | 13 ++++++++++--- | |
29 | 1 file changed, 10 insertions(+), 3 deletions(-) | |
30 | ||
31 | --- a/fs/ext4/sysfs.c | |
32 | +++ b/fs/ext4/sysfs.c | |
33 | @@ -277,8 +277,12 @@ static ssize_t ext4_attr_show(struct kob | |
34 | case attr_pointer_ui: | |
35 | if (!ptr) | |
36 | return 0; | |
37 | - return snprintf(buf, PAGE_SIZE, "%u\n", | |
38 | - *((unsigned int *) ptr)); | |
39 | + if (a->attr_ptr == ptr_ext4_super_block_offset) | |
40 | + return snprintf(buf, PAGE_SIZE, "%u\n", | |
41 | + le32_to_cpup(ptr)); | |
42 | + else | |
43 | + return snprintf(buf, PAGE_SIZE, "%u\n", | |
44 | + *((unsigned int *) ptr)); | |
45 | case attr_pointer_atomic: | |
46 | if (!ptr) | |
47 | return 0; | |
48 | @@ -311,7 +315,10 @@ static ssize_t ext4_attr_store(struct ko | |
49 | ret = kstrtoul(skip_spaces(buf), 0, &t); | |
50 | if (ret) | |
51 | return ret; | |
52 | - *((unsigned int *) ptr) = t; | |
53 | + if (a->attr_ptr == ptr_ext4_super_block_offset) | |
54 | + *((__le32 *) ptr) = cpu_to_le32(t); | |
55 | + else | |
56 | + *((unsigned int *) ptr) = t; | |
57 | return len; | |
58 | case attr_inode_readahead: | |
59 | return inode_readahead_blks_store(a, sbi, buf, len); |