]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.154/ext4-sysfs-print-ext4_super_block-fields-as-little-endian.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.154 / ext4-sysfs-print-ext4_super_block-fields-as-little-endian.patch
CommitLineData
f15b2821
GKH
1From a4d2aadca184ece182418950d45ba4ffc7b652d2 Mon Sep 17 00:00:00 2001
2From: Arnd Bergmann <arnd@arndb.de>
3Date: Sun, 29 Jul 2018 15:48:00 -0400
4Subject: ext4: sysfs: print ext4_super_block fields as little-endian
5
6From: Arnd Bergmann <arnd@arndb.de>
7
8commit a4d2aadca184ece182418950d45ba4ffc7b652d2 upstream.
9
10While working on extended rand for last_error/first_error timestamps,
11I noticed that the endianess is wrong; we access the little-endian
12fields in struct ext4_super_block as native-endian when we print them.
13
14This adds a special case in ext4_attr_show() and ext4_attr_store()
15to byteswap the superblock fields if needed.
16
17In older kernels, this code was part of super.c, it got moved to
18sysfs.c in linux-4.4.
19
20Cc: stable@vger.kernel.org
21Fixes: 52c198c6820f ("ext4: add sysfs entry showing whether the fs contains errors")
22Reviewed-by: Andreas Dilger <adilger@dilger.ca>
23Signed-off-by: Arnd Bergmann <arnd@arndb.de>
24Signed-off-by: Theodore Ts'o <tytso@mit.edu>
25Signed-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);