From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3E9DC433FE for ; Sat, 1 Oct 2022 01:04:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 27EEB6B0071; Fri, 30 Sep 2022 21:04:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 22E676B0072; Fri, 30 Sep 2022 21:04:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0D1F88D0001; Fri, 30 Sep 2022 21:04:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id EFCA06B0071 for ; Fri, 30 Sep 2022 21:04:01 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id C357A1C71CD for ; Sat, 1 Oct 2022 01:04:01 +0000 (UTC) X-FDA: 79970583882.19.2680D0E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf26.hostedemail.com (Postfix) with ESMTP id AF49C140015 for ; Sat, 1 Oct 2022 01:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1664586240; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=LD3agpc4zljNFlze98iS2sqjJDVEZTxkfgbwF36PnZ0=; b=KAhPyGWqqJODGdETbSo0UOfNL1BQ/hbqiAby49WT0NEs26nTv2EuDnxHM2UArPCFgmag/i ki0cWxmtMp7DPirR84DItZjmDgO85wdYrv1Sa4aSu4rOuQrXy/mhvOsY3QuopPQMpdIquS 06PIYz3fCHV7+dFMYM6eWKTb8jcc/fI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-656-P3OjKFg2OLGBWYPoGZqHXA-1; Fri, 30 Sep 2022 21:03:56 -0400 X-MC-Unique: P3OjKFg2OLGBWYPoGZqHXA-1 Received: by mail-qk1-f200.google.com with SMTP id j13-20020a05620a288d00b006be7b2a758fso4930021qkp.1 for ; Fri, 30 Sep 2022 18:03:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date; bh=zc0SaAKpDNbb3UwCWe65+Ca5KZLIn58yTui8h1PFlaU=; b=YTMvzpWM7k0RpUkdog4klLLgTn3EXN+tgmW6gC65VnHCQVx8vSRQw0T7ZAaFYV1vLV oXUJ2vFS6IqNX9jcafHFLX03oH9F38Tgeen6sEd8PDdOuBzqS4ilYxvESysPAgBW/2Fw 9iH5gZD2gYp+MT+pGABHAHhD5XTo+RZgKkSgAukAL6peASNQ3UteUq+JF55Ahh6pgERD B7jvBFsy3e8I3VtGcqZ8dS9F/TbmmHiqDmJdl1OOOclB4bN9pr25n3Iu0niBeLbD6H4z 5RF1r7VeVKWvKjEZ2wEH+3Eh9nj8YfcRLQ3OquHmcbBVeUb8LHWyC9sIC++cnLxsYULn V8tg== X-Gm-Message-State: ACrzQf3osB870w1TyBvMah+vS2L2CtBGWe4Uefsc6UsYKBfKRigdRP74 n9asj6KQx1jC3b6ZhybyBqCLJ5iCZYGZ9Im1R5eYYvS4mZIxp21PksTzGOWPp/ZkL6tIXW1HPG8 x99i74ThIW90= X-Received: by 2002:a05:620a:4054:b0:6ce:192a:831e with SMTP id i20-20020a05620a405400b006ce192a831emr8226921qko.671.1664586235282; Fri, 30 Sep 2022 18:03:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM47tFZGrpm77W5knYNcCk/OIOK9UGl/UkGa3jAh2M9qO1SBeMvNlvbWjHSRwK3EinDqRUeXCA== X-Received: by 2002:a05:620a:4054:b0:6ce:192a:831e with SMTP id i20-20020a05620a405400b006ce192a831emr8226903qko.671.1664586235025; Fri, 30 Sep 2022 18:03:55 -0700 (PDT) Received: from x1n (bras-base-aurron9127w-grc-46-70-31-27-79.dsl.bell.ca. [70.31.27.79]) by smtp.gmail.com with ESMTPSA id fz17-20020a05622a5a9100b00359961365f1sm2943494qtb.68.2022.09.30.18.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Sep 2022 18:03:54 -0700 (PDT) Date: Fri, 30 Sep 2022 21:03:53 -0400 From: Peter Xu To: Andrew Morton Cc: syzbot , linux-kernel@vger.kernel.org, linux-mm@kvack.org, syzkaller-bugs@googlegroups.com, Edward Liaw , Axel Rasmussen , Liu Shixin , Brian Geffon , Mike Kravetz Subject: Re: [syzbot] WARNING in change_protection Message-ID: References: <00000000000046580505e9dea8e4@google.com> <20220930164211.b8215770d44e1a3803f1e660@linux-foundation.org> MIME-Version: 1.0 In-Reply-To: <20220930164211.b8215770d44e1a3803f1e660@linux-foundation.org> X-Mimecast-Spam-Score: 1 X-Mimecast-Originator: redhat.com Content-Type: multipart/mixed; boundary="kOcqf18aKGDJ2WF5" Content-Disposition: inline ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KAhPyGWq; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664586241; a=rsa-sha256; cv=none; b=qvhym1AV3YNSTkI46Z0CgO3B1VyQpfcNqWCUuhZPK4l2o+t4gxzsqhO5BSWrzQph34kT2E 1dc8q8dYT+Z4VRBRuprEhrkARKNH2IVvL6D3j9d3Mo6SkBZ1EHCoZSYRJIUQOllVgOqwUg LQWjHbcaTBGuJfJwL1HbNCbzJHer3ts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664586241; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LD3agpc4zljNFlze98iS2sqjJDVEZTxkfgbwF36PnZ0=; b=bgWeBI+D7DkDKMXTLAPo1lGJOH8FrQ4Xx4XZ8FkRrg5kXNcZkyZX1ZH87v6M6ZG1/xsi/4 jFD1/fOlt54VFHyMGXkqVEtPKHmUwXgW/nlHzZ9/kPDj2vDlwLv/UEtvb0aRJro9dyguZj wxO48+yQnuB3Lcp4O1grDW4hHO31X4U= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: AF49C140015 X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=KAhPyGWq; spf=pass (imf26.hostedemail.com: domain of peterx@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: wtgai1c8sg51escq5bbpdzjbag87zb6e X-HE-Tag: 1664586240-525608 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: --kOcqf18aKGDJ2WF5 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline On Fri, Sep 30, 2022 at 04:42:11PM -0700, Andrew Morton wrote: > On Thu, 29 Sep 2022 22:56:38 -0700 syzbot wrote: > > > Hello, > > Thanks. Let's cc a few userfaultfd people. I remembered there was a similar report and there might have a patch already, but I can't find it. The timing is a bit unfortunate.. Anyway, a new patch is attached, and I verified it with the reproducer this time. Thanks, > > > syzbot found the following issue on: > > > > HEAD commit: 511cce163b75 Merge tag 'net-6.0-rc8' of git://git.kernel.o.. > > git tree: upstream > > console+strace: https://syzkaller.appspot.com/x/log.txt?x=135cf5c4880000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=a1992c90769e07 > > dashboard link: https://syzkaller.appspot.com/bug?extid=2b9b4f0895be09a6dec3 > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1164d0ec880000 > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=15c3c2e0880000 > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > Reported-by: syzbot+2b9b4f0895be09a6dec3@syzkaller.appspotmail.com > > > > ------------[ cut here ]------------ > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 make_pte_marker_entry include/linux/swapops.h:323 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 make_pte_marker include/linux/swapops.h:346 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_pte_range mm/mprotect.c:270 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_pmd_range mm/mprotect.c:409 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_pud_range mm/mprotect.c:438 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_p4d_range mm/mprotect.c:459 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_protection_range mm/mprotect.c:483 [inline] > > WARNING: CPU: 1 PID: 3612 at include/linux/swapops.h:323 change_protection+0x16e9/0x4280 mm/mprotect.c:505 > > Modules linked in: > > CPU: 1 PID: 3612 Comm: syz-executor181 Not tainted 6.0.0-rc7-syzkaller-00130-g511cce163b75 #0 > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022 > > RIP: 0010:make_pte_marker_entry include/linux/swapops.h:323 [inline] > > RIP: 0010:make_pte_marker include/linux/swapops.h:346 [inline] > > RIP: 0010:change_pte_range mm/mprotect.c:270 [inline] > > RIP: 0010:change_pmd_range mm/mprotect.c:409 [inline] > > RIP: 0010:change_pud_range mm/mprotect.c:438 [inline] > > RIP: 0010:change_p4d_range mm/mprotect.c:459 [inline] > > RIP: 0010:change_protection_range mm/mprotect.c:483 [inline] > > RIP: 0010:change_protection+0x16e9/0x4280 mm/mprotect.c:505 > > Code: ff 48 8b 84 24 90 00 00 00 80 38 00 0f 85 25 29 00 00 48 8b 44 24 10 48 83 b8 90 00 00 00 00 0f 84 8f f9 ff ff e8 a7 d6 c3 ff <0f> 0b 48 ba 00 00 00 00 00 fc ff df 48 8b 04 24 48 c1 e8 03 80 3c > > RSP: 0018:ffffc90002fbf968 EFLAGS: 00010293 > > RAX: 0000000000000000 RBX: 0000000000000004 RCX: 0000000000000000 > > RDX: ffff888073714180 RSI: ffffffff81b76079 RDI: 0000000000000007 > > RBP: 0000000000000000 R08: 0000000000000007 R09: 0000000000000000 > > R10: 0000000000000004 R11: 0000000000000000 R12: 0000000000000000 > > R13: ffff8880000001e8 R14: 0000000000000000 R15: 000000002063e000 > > FS: 000055555624d300(0000) GS:ffff8880b9b00000(0000) knlGS:0000000000000000 > > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > > CR2: 00000000005d84c8 CR3: 000000007c916000 CR4: 00000000003506e0 > > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > > Call Trace: > > > > uffd_wp_range+0xf0/0x180 mm/userfaultfd.c:718 > > mwriteprotect_range+0x2ea/0x420 mm/userfaultfd.c:768 > > userfaultfd_writeprotect fs/userfaultfd.c:1827 [inline] > > userfaultfd_ioctl+0x438/0x43a0 fs/userfaultfd.c:1999 > > vfs_ioctl fs/ioctl.c:51 [inline] > > __do_sys_ioctl fs/ioctl.c:870 [inline] > > __se_sys_ioctl fs/ioctl.c:856 [inline] > > __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856 > > do_syscall_x64 arch/x86/entry/common.c:50 [inline] > > do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80 > > entry_SYSCALL_64_after_hwframe+0x63/0xcd > > RIP: 0033:0x7f77d7707bb9 > > Code: 28 c3 e8 2a 14 00 00 66 2e 0f 1f 84 00 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 c0 ff ff ff f7 d8 64 89 01 48 > > RSP: 002b:00007ffe74be7168 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 > > RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007f77d7707bb9 > > RDX: 00000000200000c0 RSI: 00000000c018aa06 RDI: 0000000000000003 > > RBP: 00007f77d76cbd60 R08: 0000000000000000 R09: 0000000000000000 > > R10: 0000000000000000 R11: 0000000000000246 R12: 00007f77d76cbdf0 > > R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000 > > > > > > > > --- > > This report is generated by a bot. It may contain errors. > > See https://goo.gl/tpsmEJ for more information about syzbot. > > syzbot engineers can be reached at syzkaller@googlegroups.com. > > > > syzbot will keep track of this issue. See: > > https://goo.gl/tpsmEJ#status for how to communicate with syzbot. > > syzbot can test patches for this issue, for details see: > > https://goo.gl/tpsmEJ#testing-patches > -- Peter Xu --kOcqf18aKGDJ2WF5 Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0001-mm-uffd-Fix-warning-without-PTE_MARKER_UFFD_WP-compi.patch" >From f965f8879301a5cb04b5b1ca91cb8852b9c17237 Mon Sep 17 00:00:00 2001 From: Peter Xu Date: Fri, 30 Sep 2022 20:25:55 -0400 Subject: [PATCH] mm/uffd: Fix warning without PTE_MARKER_UFFD_WP compiled in Content-type: text/plain When PTE_MARKER_UFFD_WP not configured, it's still possible to reach pte marker code and trigger an warning. Add a few CONFIG_PTE_MARKER_UFFD_WP ifdefs to make sure the code won't be reached when not compiled in. Reported-by: syzbot+2b9b4f0895be09a6dec3@syzkaller.appspotmail.com Signed-off-by: Peter Xu --- mm/hugetlb.c | 4 ++++ mm/memory.c | 2 ++ mm/mprotect.c | 2 ++ 3 files changed, 8 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 0bdfc7e1c933..dd29cba46e9e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5059,6 +5059,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct * unmapped and its refcount is dropped, so just clear pte here. */ if (unlikely(!pte_present(pte))) { +#ifdef CONFIG_PTE_MARKER_UFFD_WP /* * If the pte was wr-protected by uffd-wp in any of the * swap forms, meanwhile the caller does not want to @@ -5070,6 +5071,7 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct set_huge_pte_at(mm, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); else +#endif huge_pte_clear(mm, address, ptep, sz); spin_unlock(ptl); continue; @@ -5098,11 +5100,13 @@ static void __unmap_hugepage_range(struct mmu_gather *tlb, struct vm_area_struct tlb_remove_huge_tlb_entry(h, tlb, ptep, address); if (huge_pte_dirty(pte)) set_page_dirty(page); +#ifdef CONFIG_PTE_MARKER_UFFD_WP /* Leave a uffd-wp pte marker if needed */ if (huge_pte_uffd_wp(pte) && !(zap_flags & ZAP_FLAG_DROP_MARKER)) set_huge_pte_at(mm, address, ptep, make_pte_marker(PTE_MARKER_UFFD_WP)); +#endif hugetlb_count_sub(pages_per_huge_page(h), mm); page_remove_rmap(page, vma, true); diff --git a/mm/memory.c b/mm/memory.c index a78814413ac0..de0dbe09b013 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1393,10 +1393,12 @@ zap_install_uffd_wp_if_needed(struct vm_area_struct *vma, unsigned long addr, pte_t *pte, struct zap_details *details, pte_t pteval) { +#ifdef CONFIG_PTE_MARKER_UFFD_WP if (zap_drop_file_uffd_wp(details)) return; pte_install_uffd_wp_if_needed(vma, addr, pte, pteval); +#endif } static unsigned long zap_pte_range(struct mmu_gather *tlb, diff --git a/mm/mprotect.c b/mm/mprotect.c index bc6bddd156ca..51e7dbd26b6a 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -260,6 +260,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb, } else { /* It must be an none page, or what else?.. */ WARN_ON_ONCE(!pte_none(oldpte)); +#ifdef CONFIG_PTE_MARKER_UFFD_WP if (unlikely(uffd_wp && !vma_is_anonymous(vma))) { /* * For file-backed mem, we need to be able to @@ -271,6 +272,7 @@ static unsigned long change_pte_range(struct mmu_gather *tlb, make_pte_marker(PTE_MARKER_UFFD_WP)); pages++; } +#endif } } while (pte++, addr += PAGE_SIZE, addr != end); arch_leave_lazy_mmu_mode(); -- 2.37.3 --kOcqf18aKGDJ2WF5--