From: Abhishek Shah <abhishek.shah@columbia.edu>
To: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Cc: Gabriel Ryan <gabe@cs.columbia.edu>
Subject: Race in mm/ksm.c
Date: Thu, 21 Jul 2022 11:58:52 -0400 [thread overview]
Message-ID: <CAEHB24-Um6khKHAmxMEaGmJgRoLgZVQncSEsZhqunxr1Ypz=qA@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2559 bytes --]
Dear Kernel Maintainers,
We found a race in mm/ksm.c. During the execution of the function
*__ksm_run* which uses variable *ksm_run* to decide the list insertion
point, the variable *ksm_run* can be concurrently modified in the function
*run_store*, which we thought could be undesirable since “KSM pages in
newly forked mms can be missed” (See comment here:
https://elixir.bootlin.com/linux/v5.18-rc5/source/mm/ksm.c#L2498). We would
also like your thoughts on the security impact given it is a TOCTOU bug.
We provide more details below including the trace and reproducing
test cases.
*Trace*
BUG: KCSAN: data-race in __ksm_enter / run_store
write to 0xffffffff881edae0 of 8 bytes by task 6542 on cpu 0:
run_store+0x19a/0x2d0 mm/ksm.c:2897
kobj_attr_store+0x44/0x60 lib/kobject.c:824
sysfs_kf_write+0x16f/0x1a0 fs/sysfs/file.c:136
kernfs_fop_write_iter+0x2ae/0x370 fs/kernfs/file.c:291
call_write_iter include/linux/fs.h:2050 [inline]
new_sync_write fs/read_write.c:504 [inline]
vfs_write+0x779/0x900 fs/read_write.c:591
ksys_write+0xde/0x190 fs/read_write.c:644
__do_sys_write fs/read_write.c:656 [inline]
__se_sys_write fs/read_write.c:653 [inline]
__x64_sys_write+0x43/0x50 fs/read_write.c:653
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0x90 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
read to 0xffffffff881edae0 of 8 bytes by task 6541 on cpu 1:
__ksm_enter+0x114/0x260 mm/ksm.c:2501
ksm_madvise+0x291/0x350 mm/ksm.c:2451
madvise_vma_behavior mm/madvise.c:1039 [inline]
madvise_walk_vmas mm/madvise.c:1221 [inline]
do_madvise+0x656/0xeb0 mm/madvise.c:1399
__do_sys_madvise mm/madvise.c:1412 [inline]
__se_sys_madvise mm/madvise.c:1410 [inline]
__x64_sys_madvise+0x64/0x70 mm/madvise.c:1410
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x3d/0x90 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x44/0xae
Reported by Kernel Concurrency Sanitizer on:
CPU: 1 PID: 6541 Comm: syz-executor2-n Not tainted 5.18.0-rc5+ #107
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1
04/01/2014
---------------------
*Inputs *
Input CPU 0:
r0 = openat$sysctl(0xffffff9c,
&(0x7f0000000100)='/sys/kernel/mm/ksm/run\x00', 0x1, 0x0)
write$sysctl(r0, &(0x7f0000000000)='2\x00', 0x2)
Input CPU 1:
madvise(&(0x7f0000ffc000/0x4000)=nil, 0x4000, 0xc)
mlock2(&(0x7f0000ffe000/0x2000)=nil, 0x2000, 0x0)
madvise(&(0x7f0000ffd000/0x3000)=nil, 0x3000, 0x12)
clone(0x0, 0x0, 0x0, 0x0, 0x0)
[-- Attachment #2: Type: text/html, Size: 3412 bytes --]
next reply other threads:[~2022-07-21 15:59 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-21 15:58 Abhishek Shah [this message]
2022-07-22 1:57 ` Kefeng Wang
2022-08-02 11:44 ` Gabriel Ryan
2022-08-02 12:18 ` Kefeng Wang
2022-08-02 12:33 ` Gabriel Ryan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAEHB24-Um6khKHAmxMEaGmJgRoLgZVQncSEsZhqunxr1Ypz=qA@mail.gmail.com' \
--to=abhishek.shah@columbia.edu \
--cc=akpm@linux-foundation.org \
--cc=gabe@cs.columbia.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox