]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.170/include-linux-swap.h-use-offsetof-instead-of-custom-.patch
remove unneeded perf patch from 4.9
[thirdparty/kernel/stable-queue.git] / releases / 4.9.170 / include-linux-swap.h-use-offsetof-instead-of-custom-.patch
1 From 25841b03f51a20b23d0d74d0254e178bc61d4b53 Mon Sep 17 00:00:00 2001
2 From: Pi-Hsun Shih <pihsun@chromium.org>
3 Date: Wed, 13 Mar 2019 11:44:33 -0700
4 Subject: include/linux/swap.h: use offsetof() instead of custom __swapoffset
5 macro
6
7 [ Upstream commit a4046c06be50a4f01d435aa7fe57514818e6cc82 ]
8
9 Use offsetof() to calculate offset of a field to take advantage of
10 compiler built-in version when possible, and avoid UBSAN warning when
11 compiling with Clang:
12
13 UBSAN: Undefined behaviour in mm/swapfile.c:3010:38
14 member access within null pointer of type 'union swap_header'
15 CPU: 6 PID: 1833 Comm: swapon Tainted: G S 4.19.23 #43
16 Call trace:
17 dump_backtrace+0x0/0x194
18 show_stack+0x20/0x2c
19 __dump_stack+0x20/0x28
20 dump_stack+0x70/0x94
21 ubsan_epilogue+0x14/0x44
22 ubsan_type_mismatch_common+0xf4/0xfc
23 __ubsan_handle_type_mismatch_v1+0x34/0x54
24 __se_sys_swapon+0x654/0x1084
25 __arm64_sys_swapon+0x1c/0x24
26 el0_svc_common+0xa8/0x150
27 el0_svc_compat_handler+0x2c/0x38
28 el0_svc_compat+0x8/0x18
29
30 Link: http://lkml.kernel.org/r/20190312081902.223764-1-pihsun@chromium.org
31 Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
32 Acked-by: Michal Hocko <mhocko@suse.com>
33 Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
34 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
35 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
36 Signed-off-by: Sasha Levin <sashal@kernel.org>
37 ---
38 include/linux/swap.h | 4 ++--
39 1 file changed, 2 insertions(+), 2 deletions(-)
40
41 diff --git a/include/linux/swap.h b/include/linux/swap.h
42 index 55ff5593c193..2228907d08ff 100644
43 --- a/include/linux/swap.h
44 +++ b/include/linux/swap.h
45 @@ -135,9 +135,9 @@ struct swap_extent {
46 /*
47 * Max bad pages in the new format..
48 */
49 -#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
50 #define MAX_SWAP_BADPAGES \
51 - ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
52 + ((offsetof(union swap_header, magic.magic) - \
53 + offsetof(union swap_header, info.badpages)) / sizeof(int))
54
55 enum {
56 SWP_USED = (1 << 0), /* is slot in swap_info[] used? */
57 --
58 2.19.1
59