]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.19.34/f2fs-ubsan-set-boolean-value-iostat_enable-correctly.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.19.34 / f2fs-ubsan-set-boolean-value-iostat_enable-correctly.patch
CommitLineData
ba172962
SL
1From 825358baf0243b62f80c2f94e422f224a9f3400a Mon Sep 17 00:00:00 2001
2From: Sheng Yong <shengyong1@huawei.com>
3Date: Tue, 15 Jan 2019 20:02:15 +0000
4Subject: f2fs: UBSAN: set boolean value iostat_enable correctly
5
6[ Upstream commit ac92985864e187a1735502f6a02f54eaa655b2aa ]
7
8When setting /sys/fs/f2fs/<DEV>/iostat_enable with non-bool value, UBSAN
9reports the following warning.
10
11[ 7562.295484] ================================================================================
12[ 7562.296531] UBSAN: Undefined behaviour in fs/f2fs/f2fs.h:2776:10
13[ 7562.297651] load of value 64 is not a valid value for type '_Bool'
14[ 7562.298642] CPU: 1 PID: 7487 Comm: dd Not tainted 4.20.0-rc4+ #79
15[ 7562.298653] Hardware name: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006
16[ 7562.298662] Call Trace:
17[ 7562.298760] dump_stack+0x46/0x5b
18[ 7562.298811] ubsan_epilogue+0x9/0x40
19[ 7562.298830] __ubsan_handle_load_invalid_value+0x72/0x90
20[ 7562.298863] f2fs_file_write_iter+0x29f/0x3f0
21[ 7562.298905] __vfs_write+0x115/0x160
22[ 7562.298922] vfs_write+0xa7/0x190
23[ 7562.298934] ksys_write+0x50/0xc0
24[ 7562.298973] do_syscall_64+0x4a/0xe0
25[ 7562.298992] entry_SYSCALL_64_after_hwframe+0x44/0xa9
26[ 7562.299001] RIP: 0033:0x7fa45ec19c00
27[ 7562.299004] Code: 73 01 c3 48 8b 0d 88 92 2c 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f 44 00 00 83 3d dd eb 2c 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48 83 ec 08 e8 ce 8f 01 00 48 89 04 24
28[ 7562.299044] RSP: 002b:00007ffca52b49e8 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
29[ 7562.299052] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fa45ec19c00
30[ 7562.299059] RDX: 0000000000000400 RSI: 000000000093f000 RDI: 0000000000000001
31[ 7562.299065] RBP: 000000000093f000 R08: 0000000000000004 R09: 0000000000000000
32[ 7562.299071] R10: 00007ffca52b47b0 R11: 0000000000000246 R12: 0000000000000400
33[ 7562.299077] R13: 000000000093f000 R14: 000000000093f400 R15: 0000000000000000
34[ 7562.299091] ================================================================================
35
36So, if iostat_enable is enabled, set its value as true.
37
38Signed-off-by: Sheng Yong <shengyong1@huawei.com>
39Reviewed-by: Chao Yu <yuchao0@huawei.com>
40Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
41Signed-off-by: Sasha Levin <sashal@kernel.org>
42---
43 fs/f2fs/sysfs.c | 12 +++++++++---
44 1 file changed, 9 insertions(+), 3 deletions(-)
45
46diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
47index 81c0e5337443..98887187af4c 100644
48--- a/fs/f2fs/sysfs.c
49+++ b/fs/f2fs/sysfs.c
50@@ -273,10 +273,16 @@ out:
51 return count;
52 }
53
54- *ui = t;
55
56- if (!strcmp(a->attr.name, "iostat_enable") && *ui == 0)
57- f2fs_reset_iostat(sbi);
58+ if (!strcmp(a->attr.name, "iostat_enable")) {
59+ sbi->iostat_enable = !!t;
60+ if (!sbi->iostat_enable)
61+ f2fs_reset_iostat(sbi);
62+ return count;
63+ }
64+
65+ *ui = (unsigned int)t;
66+
67 return count;
68 }
69
70--
712.19.1
72