2024-03-31 15:11:35

by Oliver Sang

[permalink] [raw]
Subject: Re: [PATCH 7/9] mm: Free up PG_slab



Hello,

kernel test robot noticed "UBSAN:shift-out-of-bounds_in_fs/proc/page.c" on:

commit: 30e5296811312a13938b83956a55839ac1e3aa40 ("[PATCH 7/9] mm: Free up PG_slab")
url: https://github.com/intel-lab-lkp/linux/commits/Matthew-Wilcox-Oracle/mm-Always-initialise-folio-_deferred_list/20240321-222800
base: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git 23956900041d968f9ad0f30db6dede4daccd7aa9
patch link: https://lore.kernel.org/all/[email protected]/
patch subject: [PATCH 7/9] mm: Free up PG_slab

in testcase: ltp
version: ltp-x86_64-14c1f76-1_20240323
with following parameters:

disk: 1HDD
fs: ext4
test: fs-00



compiler: gcc-12
test machine: 4 threads 1 sockets Intel(R) Core(TM) i3-3220 CPU @ 3.30GHz (Ivy Bridge) with 8G memory

(please refer to attached dmesg/kmsg for entire log/backtrace)



If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-lkp/[email protected]


kern :warn : [ 528.627387] ------------[ cut here ]------------
kern :err : [ 528.627589] UBSAN: shift-out-of-bounds in fs/proc/page.c:107:18
kern :err : [ 528.627884] shift exponent 4096 is too large for 64-bit type 'long long unsigned int'
kern :warn : [ 528.628200] CPU: 0 PID: 4703 Comm: proc01 Tainted: G S 6.8.0-11774-g30e529681131 #1
kern :warn : [ 528.628446] Hardware name: Hewlett-Packard p6-1451cx/2ADA, BIOS 8.15 02/05/2013
kern :warn : [ 528.628659] Call Trace:
kern :warn : [ 528.628814] <TASK>
kern :warn : [ 528.628960] dump_stack_lvl (lib/dump_stack.c:117 (discriminator 1))
kern :warn : [ 528.629134] __ubsan_handle_shift_out_of_bounds (lib/ubsan.c:218 lib/ubsan.c:454)
kern :warn : [ 528.629360] stable_page_flags.part.0.cold (include/linux/page-flags.h:284 fs/proc/page.c:184)
kern :warn : [ 528.629506] kpageflags_read (fs/proc/page.c:238 fs/proc/page.c:250)
kern :warn : [ 528.629623] vfs_read (fs/read_write.c:474)
kern :warn : [ 528.629737] ? do_sys_openat2 (fs/open.c:1415)
kern :warn : [ 528.629898] ? kmem_cache_free (mm/slub.c:4280 mm/slub.c:4344)
kern :warn : [ 528.630063] ? __pfx_vfs_read (fs/read_write.c:457)
kern :warn : [ 528.630225] ? do_sys_openat2 (fs/open.c:1415)
kern :warn : [ 528.630388] ? __pfx_do_sys_openat2 (fs/open.c:1392)
kern :warn : [ 528.630552] ? __do_sys_newfstatat (fs/stat.c:464)
kern :warn : [ 528.630717] ? __fget_light (include/linux/atomic/atomic-arch-fallback.h:479 include/linux/atomic/atomic-instrumented.h:50 fs/file.c:1145)
kern :warn : [ 528.630888] ksys_read (fs/read_write.c:619)
kern :warn : [ 528.631051] ? __pfx_ksys_read (fs/read_write.c:609)
kern :warn : [ 528.631216] ? kmem_cache_free (mm/slub.c:4280 mm/slub.c:4344)
kern :warn : [ 528.631415] do_syscall_64 (arch/x86/entry/common.c:52 arch/x86/entry/common.c:83)
kern :warn : [ 528.631555] entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:129)
kern :warn : [ 528.631756] RIP: 0033:0x7f90bf2ba19d
kern :warn : [ 528.631913] Code: 31 c0 e9 c6 fe ff ff 50 48 8d 3d 66 54 0a 00 e8 49 ff 01 00 66 0f 1f 84 00 00 00 00 00 80 3d 41 24 0e 00 00 74 17 31 c0 0f 05 <48> 3d 00 f0 ff ff 77 5b c3 66 2e 0f 1f 84 00 00 00 00 00 48 83 ec
All code
========
0: 31 c0 xor %eax,%eax
2: e9 c6 fe ff ff jmpq 0xfffffffffffffecd
7: 50 push %rax
8: 48 8d 3d 66 54 0a 00 lea 0xa5466(%rip),%rdi # 0xa5475
f: e8 49 ff 01 00 callq 0x1ff5d
14: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
1b: 00 00
1d: 80 3d 41 24 0e 00 00 cmpb $0x0,0xe2441(%rip) # 0xe2465
24: 74 17 je 0x3d
26: 31 c0 xor %eax,%eax
28: 0f 05 syscall
2a:* 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax <-- trapping instruction
30: 77 5b ja 0x8d
32: c3 retq
33: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
3a: 00 00 00
3d: 48 rex.W
3e: 83 .byte 0x83
3f: ec in (%dx),%al

Code starting with the faulting instruction
===========================================
0: 48 3d 00 f0 ff ff cmp $0xfffffffffffff000,%rax
6: 77 5b ja 0x63
8: c3 retq
9: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
10: 00 00 00
13: 48 rex.W
14: 83 .byte 0x83
15: ec in (%dx),%al
kern :warn : [ 528.632309] RSP: 002b:00007ffe2eb3c008 EFLAGS: 00000246 ORIG_RAX: 0000000000000000
kern :warn : [ 528.632540] RAX: ffffffffffffffda RBX: 00007ffe2eb3d1b0 RCX: 00007f90bf2ba19d
kern :warn : [ 528.632757] RDX: 0000000000000400 RSI: 000055e284e68c40 RDI: 0000000000000005
kern :warn : [ 528.632960] RBP: 0000000000000000 R08: 0000000000000000 R09: 0000000000000073
kern :warn : [ 528.633156] R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000005
kern :warn : [ 528.633399] R13: 000055e284e68c40 R14: 000055e2a975f8cb R15: 00007ffe2eb3d1b0
kern :warn : [ 528.633645] </TASK>
kern :warn : [ 528.633813] ---[ end trace ]---



The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20240331/[email protected]



--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki



2024-04-02 05:26:25

by Matthew Wilcox

[permalink] [raw]
Subject: Re: [PATCH 7/9] mm: Free up PG_slab

On Sun, Mar 31, 2024 at 11:11:10PM +0800, kernel test robot wrote:
> kernel test robot noticed "UBSAN:shift-out-of-bounds_in_fs/proc/page.c" on:
>
> commit: 30e5296811312a13938b83956a55839ac1e3aa40 ("[PATCH 7/9] mm: Free up PG_slab")

Quite right. Spotted another one while I was at it. Not able to test
right now, but this should do the trick:

diff --git a/fs/proc/page.c b/fs/proc/page.c
index 5bc82828c6aa..55b01535eb22 100644
--- a/fs/proc/page.c
+++ b/fs/proc/page.c
@@ -175,6 +175,8 @@ u64 stable_page_flags(const struct page *page)
u |= 1 << KPF_OFFLINE;
if (PageTable(page))
u |= 1 << KPF_PGTABLE;
+ if (folio_test_slab(folio))
+ u |= 1 << KPF_SLAB;

#if defined(CONFIG_PAGE_IDLE_FLAG) && defined(CONFIG_64BIT)
u |= kpf_copy_bit(k, KPF_IDLE, PG_idle);
@@ -184,7 +186,6 @@ u64 stable_page_flags(const struct page *page)
#endif

u |= kpf_copy_bit(k, KPF_LOCKED, PG_locked);
- u |= kpf_copy_bit(k, KPF_SLAB, PG_slab);
u |= kpf_copy_bit(k, KPF_ERROR, PG_error);
u |= kpf_copy_bit(k, KPF_DIRTY, PG_dirty);
u |= kpf_copy_bit(k, KPF_UPTODATE, PG_uptodate);
diff --git a/tools/cgroup/memcg_slabinfo.py b/tools/cgroup/memcg_slabinfo.py
index 1d3a90d93fe2..270c28a0d098 100644
--- a/tools/cgroup/memcg_slabinfo.py
+++ b/tools/cgroup/memcg_slabinfo.py
@@ -146,12 +146,11 @@ def detect_kernel_config():


def for_each_slab(prog):
- PGSlab = 1 << prog.constant('PG_slab')
- PGHead = 1 << prog.constant('PG_head')
+ PGSlab = ~prog.constant('PG_slab')

for page in for_each_page(prog):
try:
- if page.flags.value_() & PGSlab:
+ if page.page_type.value_() == PGSlab:
yield cast('struct slab *', page)
except FaultError:
pass