]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/include-linux-swap.h-use-offsetof-instead-of-custom-.patch
add bpf changelog comment update for 4.14.y
[thirdparty/kernel/stable-queue.git] / queue-4.4 / include-linux-swap.h-use-offsetof-instead-of-custom-.patch
1 From 7169afce8a08816f34c321d1f15948a5d38c5fa8 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 --- a/include/linux/swap.h
42 +++ b/include/linux/swap.h
43 @@ -135,9 +135,9 @@ struct swap_extent {
44 /*
45 * Max bad pages in the new format..
46 */
47 -#define __swapoffset(x) ((unsigned long)&((union swap_header *)0)->x)
48 #define MAX_SWAP_BADPAGES \
49 - ((__swapoffset(magic.magic) - __swapoffset(info.badpages)) / sizeof(int))
50 + ((offsetof(union swap_header, magic.magic) - \
51 + offsetof(union swap_header, info.badpages)) / sizeof(int))
52
53 enum {
54 SWP_USED = (1 << 0), /* is slot in swap_info[] used? */