[PATCH] mm: khugepaged.c: check for anonymous VMA

1 view
Skip to first unread message

B K Karthik

unread,
Jul 22, 2020, 4:47:29 AM7/22/20
to syzbot+ed318e...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, kir...@shutemov.name, hda...@sina.com, gre...@linuxfoundation.org, sk...@linuxfoundation.org
#syz test: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git master

fix general protection fault in khugepaged by checking
for anonymous VMA in hugepage_vma_revalidate()

Cc: Kirill A. Shutemov <kir...@shutemov.name>
Cc: Hillf Danton <hda...@sina.com>
Reported-by: syzbot+ed318e...@syzkaller.appspotmail.com
Signed-off-by: B K Karthik <bkka...@pesu.pes.edu>
---
mm/khugepaged.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/mm/khugepaged.c b/mm/khugepaged.c
index b043c40a21d4..9df73cea8cca 100644
--- a/mm/khugepaged.c
+++ b/mm/khugepaged.c
@@ -958,6 +958,8 @@ static int hugepage_vma_revalidate(struct mm_struct *mm, unsigned long address,
return SCAN_ADDRESS_RANGE;
if (!hugepage_vma_check(vma, vma->vm_flags))
return SCAN_VMA_CHECK;
+ if (vma->anon_vma)
+ return SCAN_VMA_NULL;
return 0;
}

--
2.20.1

signature.asc

Dan Carpenter

unread,
Jul 22, 2020, 5:30:38 AM7/22/20
to B K Karthik, syzbot+ed318e...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, kir...@shutemov.name, hda...@sina.com, gre...@linuxfoundation.org, sk...@linuxfoundation.org
Gar... Gmail has been marking a bunch of syzbot emails as spam so I
never recieved Kirill or Hillf's responses to this thread. I've
updated my filters so we'll see how it goes. I suspect that
lore.kernel.org also marked Hillf's response as spam because it doesn't
have a copy of that email.

This email wasn't sent as a response to the thread anyway so it wouldn't
have necessarily helped me.

On Wed, Jul 22, 2020 at 02:17:20PM +0530, B K Karthik wrote:
> #syz test: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git master
>
> fix general protection fault in khugepaged by checking
> for anonymous VMA in hugepage_vma_revalidate()
>
> Cc: Kirill A. Shutemov <kir...@shutemov.name>
> Cc: Hillf Danton <hda...@sina.com>
> Reported-by: syzbot+ed318e...@syzkaller.appspotmail.com
> Signed-off-by: B K Karthik <bkka...@pesu.pes.edu>
> ---

Here is really what I would prefer for a commit message.

Syzbot triggered an Oops:
https://lore.kernel.org/lkml/00000000000035...@google.com/
The problem is that the anonymous VMA got replaced by file VMA under us.

Fixes: 99cb0dbd47a1 ("mm,thp: add read-only THP support for (non-shmem) FS")

The important thing is that it has a link to the original thread and a
basic explanation and a fixes tag.

I didn't see any discussion on the thread why Kirill's fix wasn't
correct. It's sort of surprising.

regards,
dan carpenter

B K Karthik

unread,
Jul 22, 2020, 5:37:42 AM7/22/20
to Dan Carpenter, syzbot+ed318e...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, kir...@shutemov.name, Hillf Danton, Greg Kroah-Hartman, Shuah Khan
Understood, I will follow this from the next time.

>
> I didn't see any discussion on the thread why Kirill's fix wasn't
> correct. It's sort of surprising.
Forgive me, but I thought this was simpler.
please let me know if I am wrong.

thanks,

karthik

Kirill A. Shutemov

unread,
Jul 22, 2020, 6:15:24 AM7/22/20
to B K Karthik, syzbot+ed318e...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, hda...@sina.com, gre...@linuxfoundation.org, sk...@linuxfoundation.org
On Wed, Jul 22, 2020 at 02:17:20PM +0530, B K Karthik wrote:
It excludes all anonoymous VMAs and effectively prevent khugepaged from
doing its job.

--
Kirill A. Shutemov

B K Karthik

unread,
Jul 22, 2020, 7:13:10 AM7/22/20
to Kirill A. Shutemov, syzbot+ed318e...@syzkaller.appspotmail.com, syzkall...@googlegroups.com, Hillf Danton, Greg Kroah-Hartman, Shuah Khan
Understood. Thank you for the clarification. :)

syzbot

unread,
Jul 22, 2020, 7:19:06 AM7/22/20
to bkka...@pesu.pes.edu, gre...@linuxfoundation.org, hda...@sina.com, kir...@shutemov.name, sk...@linuxfoundation.org, syzkall...@googlegroups.com
Hello,

syzbot has tested the proposed patch but the reproducer is still triggering an issue:
general protection fault in free_netdev

IPVS: ftp: loaded support on port[0] = 21
general protection fault, probably for non-canonical address 0xdffffc0000000080: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000400-0x0000000000000407]
CPU: 1 PID: 15641 Comm: syz-executor.2 Not tainted 5.8.0-rc4-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:netif_free_tx_queues net/core/dev.c:9371 [inline]
RIP: 0010:free_netdev+0x41/0x480 net/core/dev.c:10042
Code: d2 be 39 27 00 00 48 c7 c7 e0 77 fd 88 e8 07 37 1c fb 48 8d bd 00 04 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 f4 03 00 00 48 8b bd 00 04 00 00 e8 49 c3 69 fb
RSP: 0018:ffffc900076efc10 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: ffff88808fdbe000 RCX: ffffffff86fada0b
RDX: 0000000000000080 RSI: ffffffff89bc0e00 RDI: 0000000000000400
RBP: 0000000000000000 R08: 0000000000000001 R09: ffffffff8a7b5447
R10: 0000000000000000 R11: 0000000000000000 R12: 00000000fffffff4
R13: ffff8880a8b35410 R14: ffff88806aee3000 R15: ffff8880a36734b8
FS: 00007f13cb47c700(0000) GS:ffff8880ae700000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00000000004fdcf0 CR3: 00000000a773a000 CR4: 00000000001406e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
ip6gre_init_net+0x546/0x610 net/ipv6/ip6_gre.c:1595
ops_init+0xaf/0x470 net/core/net_namespace.c:151
setup_net+0x2d8/0x850 net/core/net_namespace.c:341
copy_net_ns+0x2cf/0x5e0 net/core/net_namespace.c:482
create_new_namespaces+0x3f6/0xb10 kernel/nsproxy.c:110
unshare_nsproxy_namespaces+0xbd/0x1f0 kernel/nsproxy.c:231
ksys_unshare+0x36c/0x9a0 kernel/fork.c:2979
__do_sys_unshare kernel/fork.c:3047 [inline]
__se_sys_unshare kernel/fork.c:3045 [inline]
__x64_sys_unshare+0x2d/0x40 kernel/fork.c:3045
do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:384
entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x45cba9
Code: Bad RIP value.
RSP: 002b:00007f13cb47bc78 EFLAGS: 00000246 ORIG_RAX: 0000000000000110
RAX: ffffffffffffffda RBX: 000000000050bb60 RCX: 000000000045cba9
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000040000000
RBP: 000000000078bfa0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000ffffffff
R13: 0000000000000c91 R14: 00000000004cef3e R15: 00007f13cb47c6d4
Modules linked in:
---[ end trace 3d28a0c8c4731f0a ]---
RIP: 0010:netif_free_tx_queues net/core/dev.c:9371 [inline]
RIP: 0010:free_netdev+0x41/0x480 net/core/dev.c:10042
Code: d2 be 39 27 00 00 48 c7 c7 e0 77 fd 88 e8 07 37 1c fb 48 8d bd 00 04 00 00 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <80> 3c 02 00 0f 85 f4 03 00 00 48 8b bd 00 04 00 00 e8 49 c3 69 fb
RSP: 0018:ffffc900076efc10 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: ffff88808fdbe000 RCX: ffffffff86fada0b
RDX: 0000000000000080 RSI: ffffffff89bc0e00 RDI: 0000000000000400
RBP: 0000000000000000 R08: 0000000000000001 R09: ffffffff8a7b5447
R10: 0000000000000000 R11: 0000000000000000 R12: 00000000fffffff4
R13: ffff8880a8b35410 R14: ffff88806aee3000 R15: ffff8880a36734b8
FS: 00007f13cb47c700(0000) GS:ffff8880ae600000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00005618c25064c0 CR3: 00000000a773a000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


Tested on:

commit: fa56a987 Merge branch 'ionic-updates'
git tree: https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=13ce0c30900000
kernel config: https://syzkaller.appspot.com/x/.config?x=c4583cf0a8f95675
dashboard link: https://syzkaller.appspot.com/bug?extid=ed318e8b790ca72c5ad0
compiler: gcc (GCC) 10.1.0-syz 20200507
patch: https://syzkaller.appspot.com/x/patch.diff?x=12e8f437100000

Reply all
Reply to author
Forward
0 new messages