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 DF3F8C4345F for ; Mon, 22 Apr 2024 13:28:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 065676B007B; Mon, 22 Apr 2024 09:28:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F31B66B0082; Mon, 22 Apr 2024 09:28:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DD1866B0083; Mon, 22 Apr 2024 09:28:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BAA2B6B007B for ; Mon, 22 Apr 2024 09:28:51 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5A09580B83 for ; Mon, 22 Apr 2024 13:28:51 +0000 (UTC) X-FDA: 82037248062.04.774237E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf18.hostedemail.com (Postfix) with ESMTP id 4229B1C0012 for ; Mon, 22 Apr 2024 13:28:48 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aUh7iEef; spf=pass (imf18.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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713792528; 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=J7nGMYM1ObJNYkSWSkE2Vwl6HKyd/jmr+aEnngjs+Gw=; b=Z0lHNKxPjRjsXzDaH2482EH8HDhC05TlG2LNqyc6iiKeGnGrU36f0SQops904uSIS1ytT8 KXGE7kfCCgcTcmQrbHmimygE/NTJ57wnLtA8APdZzUtq53Rz+vLZKTbJGwNc2aX/3MTEkY CSKLhSMTJrlIdchaLemV5F8E3sWSh48= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=aUh7iEef; spf=pass (imf18.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=1713792528; a=rsa-sha256; cv=none; b=7WyXxIXCLWcsdj+/F8vJrAwB36g1vdE4Gz/SIZK/jA7zH0VbLJ/lb+D+726V2qM1Anwrgb LNA5oDlFzcApYHlCd+wOgB2/mPMuTHf92R2hhi323EJE1PJYokhvnUoMR9VFT81lcKNm/G jDKSIrnpAZulTSKs58EVW0pS7EIf704= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713792527; 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=J7nGMYM1ObJNYkSWSkE2Vwl6HKyd/jmr+aEnngjs+Gw=; b=aUh7iEefR62L7yKV0Z72fSkmu4Lm/bC6LELlcTirTCPBd8YU5ElCG5GimA7ryFblyzImXb Chrrlg6M+7hfX//eqivZp+bCRuGy1NFjKtE0suPD8zpr+QoQBLG9K61pUg6dvUmFW2ZDr5 IIdXa3ChD/cSs7kS6eVWu9Ov/oFAC4Q= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-_Ecy3T58PrarGbUgEg8Jgw-1; Mon, 22 Apr 2024 09:28:46 -0400 X-MC-Unique: _Ecy3T58PrarGbUgEg8Jgw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-69627b26a51so405216d6.1 for ; Mon, 22 Apr 2024 06:28:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713792525; x=1714397325; 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 :message-id:reply-to; bh=J7nGMYM1ObJNYkSWSkE2Vwl6HKyd/jmr+aEnngjs+Gw=; b=v/u2baGW8ch/gxDk33rMNB45cTZ3FDPWUk1Jjvbss0DIFGoOMP2JL0Be079/BcjVdU uuhsTU9aXPupNCDQhCws1Xf15evcczb69R9GsqwLImcR/BpUa2Da08jB1vvaaxjldoWp Sg7KzMsZ9843L/SLv76Cj5IGkFSA+jtImAXzDksMkGTezD1NbZG/8u2Xe/VffZ2AG4Kx KvoV3YyZXwkDVkFm+7aRmLCbyyoMzdzkcNW5+ekThd65B4Ve2kT6bJg5yeDP35PZJ3S6 9vp2alv6lcRQd6F1ukDi9y1fNoM0EiA5doLmPcz/y2jyHFIJXaGZENm6iYRby0K2xEcm PVWA== X-Forwarded-Encrypted: i=1; AJvYcCU92VnzoZFUMGoF6/dhjyLE5mIl/ZgCrTdyFpCJYQ5SjVaqwdmFDLU64C/wEnGKC9KL/ptU2VyhsccrHpYGbRNAspU= X-Gm-Message-State: AOJu0Yz1+thTa8DiFIenFdYDvZsrbeJQPErbVK8WhpereoETRBysHXg5 dq0Uf5PKRFec5PwjuMhnuZE88o0Z78CJIzrSMTeSiRvQOtz0FLxzIC6S5/PVI0hnESqW6tHzron TFA2+txXFAANevzMDJbw+nXtumGHd90QoGeVtLL7JDxk1S/ky X-Received: by 2002:a0c:c483:0:b0:6a0:611e:468 with SMTP id u3-20020a0cc483000000b006a0611e0468mr12727253qvi.6.1713792525216; Mon, 22 Apr 2024 06:28:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGjujza0JD41mP8hhaa5pLNh8YrQ9lS+Dksq6zcK9/U+bbdFWeDHpsWDUF2UW0470X0BylS8g== X-Received: by 2002:a0c:c483:0:b0:6a0:611e:468 with SMTP id u3-20020a0cc483000000b006a0611e0468mr12727213qvi.6.1713792524596; Mon, 22 Apr 2024 06:28:44 -0700 (PDT) Received: from x1n (pool-99-254-121-117.cpe.net.cable.rogers.com. [99.254.121.117]) by smtp.gmail.com with ESMTPSA id v15-20020a0c8e0f000000b0069b4ddcbd42sm3366921qvb.0.2024.04.22.06.28.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 06:28:44 -0700 (PDT) Date: Mon, 22 Apr 2024 09:28:42 -0400 From: Peter Xu To: David Hildenbrand Cc: syzbot , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, pasha.tatashin@soleen.com, syzkaller-bugs@googlegroups.com Subject: Re: [syzbot] [mm?] WARNING in __page_table_check_ptes_set Message-ID: References: <000000000000ca4df20616a0fe16@google.com> <71cf84d4-77d2-42d7-a649-b67497b171f6@redhat.com> MIME-Version: 1.0 In-Reply-To: X-Mimecast-Spam-Score: 1 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Stat-Signature: diz1cwwc8efxhcmfys39dek1gzweazmo X-Rspamd-Queue-Id: 4229B1C0012 X-Rspamd-Server: rspam10 X-Rspam-User: X-HE-Tag: 1713792528-209050 X-HE-Meta: U2FsdGVkX1/w3SMvfN2BpUi4NT/fNdiQmTMnkWTCo7UACyiMuoHgx5zTJuHtFSOS9S5PuzK07JaA7Sdph9tO7r0kVk+DCMDovMKyGifimJ5/jo3NtsuwGfOw2aCD9Or2nNvAJ4ACotGlIisf3Mqk9HJgeqLHJuG0mRI+eTxafwDhE3wpZ1AN5bw1dKGWClRhytk2OAIAb20LwxGdjeY7OyDbjyhIKicabeGpfUQHYSubDKxmAmmlOo9/iLkv7Txjt7LjFwec+v72qmrRwXUmsXOWySRvpplp0WOvPVRSCQSUchIdzn8Kv7ISIjoUbUQTcWlQJhvSLEzNmLgvKfyoc4qTM5L4cbAg4woEBs0DmAQHe//rZqNov8I23Z9eSDQZeQwh75p4uVMs950iw/H1rxkQ1oYykTA48rnirY64zDrFrkGEvhd+iVJAYd/RvsIuYrunUBvPvea4wJQu5m6tcC/HtLSa/qlEPVdqPQsYDgNduZgtUkACAVw9iEEGMpltZH781rmHQjz/SQOUE20euHRiENW1H4s2WGSlN2Zp1wPuywIqBNqAKNId7Ur0X1zSb3F49ldTbDznGvoc3G3dUAiZ2sTss89xNcDz0kPPrt58NxoDsJSGJRvc+TzVFHTp/l3XLGjYO/3mdwSZfQW44JdIDDItKQFDTRof+OMO+b+mbo21CqkWRapCyO6S0cM0arMvt5LjbdricHo+GiYsLXkoOtbNPWvLeMB5tvlWPa+Z13u0wwd9vKmfJK7ozq+W8jLlTyEaF9xL5Sd9iRMkoZuKC9982GXUDshyCQI6QDR9lyBXUUgf0/evi11K+bdlAPO0X7m8mOKUCjUkSLiyFYssqp2BqR2AfDnD/1HdkY4eKd3k5MYqn23V6VR9NqCUJtKwPKng6su0vRg0tJ9n2DrT2Kv8lugzhJBpFP3FohiYHrYFLw5qVo/jeZkjqEa0ENW3ZQ6uXdA0BbCOw5m Ih1GnID1 lZ+8z05k/kaDS7OxDu8oMO2ReNzeW4yh4Z5v19wPNsCcoEbZqB0ffCyY/EdRcbIGLOYt20+pnnlXzN64ekxB//34qn9+bK3eRn3UxyDk1PN7unVx8oouJ9prp0xxYE0HaEscWIsnVokW3l3JabUEXnNdFR2feV4zVyg8648lmKUhyzilpamS9fvuhXBaxUuO33kLDLDNN8GzDGllvf32kMpPsUHQ2NI/0h0/RTRdehbXfynmM7PWPTFBfUtKeKUJS8JtQXzAdc3VUZ+NsBntWLPI99dtF+TRFNBM1iIXX2SPCR7miGy5xS2pH3wyidEzK2n0os8PkEUe0Lzs5KPDLwpVcVICsjGbH5evqb7b1rFr+8ujbE4pT1O0o3OcIykTngzvoX3kN8axNYR9b30Xn6wUBy24Cn1L7epPFrsdnQVE9KiAm1VubiDQJDfsMMXf/HE+MNG9Eyt7d5+KOD7J9l6II8j9I05TNDxKUY6LtA4vPSRj4iM13tDNnWgi37FYLvWjlqVn4nvCofXA58ggxJo2Ua/Z1gkSj1vr45tjLOtEefzLv6o606eVlEEnWC0q1D1/D+shF7OU06hNi2rJiPgKRCfnegmglK2Fkf2QOjrSl2otwbzrT5VFiaUHh32w/mYEyAT0u0qZVX7xB9cPsfRy1gy2/ks9p+86XBcV5P0o6Vi+sWGYkfpXqDq1x5er4UIa5mcBRHwB4rkkUfMOPli/60mQuBWZLvw+DgP5vUBtABrdTpRiLVl7EPF1mKMiVfH3Gu2h197pWl0lN3OYiPNuaEsU11OFMKxRK4zneSlOTtg+YbOigNK1TYyXBCx/JNaNM0uzZEXp0Rrpm3KsifAxEGMxCCqTPJo0Kd+Dk5ZsAb44gegtgDkKHuZklgkn8Ot9qdffPj4xEBwKzR3sJbresil+kWUlB0sMLDQWPjZo7QaQZ0P7Uxo+YusGfzzlKQUJ6fM5aiySAOVOtYXl46iE3mbEA EjsiT1aK nUIM8o+W3exWv3wi4a6mcA== 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: List-Subscribe: List-Unsubscribe: On Mon, Apr 22, 2024 at 01:46:20PM +0200, David Hildenbrand wrote: > On 22.04.24 12:38, David Hildenbrand wrote: > > On 22.04.24 12:07, David Hildenbrand wrote: > > > On 21.04.24 22:16, syzbot wrote: > > > > Hello, > > > > > > > > syzbot found the following issue on: > > > > > > > > HEAD commit: 4eab35893071 Add linux-next specific files for 20240417 > > > > git tree: linux-next > > > > console+strace: https://syzkaller.appspot.com/x/log.txt?x=1727a61b180000 > > > > kernel config: https://syzkaller.appspot.com/x/.config?x=27920e47287645ff > > > > dashboard link: https://syzkaller.appspot.com/bug?extid=d8426b591c36b21c750e > > > > compiler: Debian clang version 15.0.6, GNU ld (GNU Binutils for Debian) 2.40 > > > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=156da22d180000 > > > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=163dfec7180000 > > > > > > > > Downloadable assets: > > > > disk image: https://storage.googleapis.com/syzbot-assets/9f7d6c097fb4/disk-4eab3589.raw.xz > > > > vmlinux: https://storage.googleapis.com/syzbot-assets/287b16352982/vmlinux-4eab3589.xz > > > > kernel image: https://storage.googleapis.com/syzbot-assets/23839c65c573/bzImage-4eab3589.xz > > > > > > > > IMPORTANT: if you fix the issue, please add the following tag to the commit: > > > > Reported-by: syzbot+d8426b591c36b21c750e@syzkaller.appspotmail.com > > > > > > > > ------------[ cut here ]------------ > > > > WARNING: CPU: 0 PID: 5084 at mm/page_table_check.c:199 __page_table_check_pte mm/page_table_check.c:199 [inline] > > > > WARNING: CPU: 0 PID: 5084 at mm/page_table_check.c:199 __page_table_check_ptes_set+0x1db/0x420 > > > > > > I think this is > > > > > > if (pte_present(pte) && pte_uffd_wp(pte)) > > > WARN_ON_ONCE(pte_write(pte)); > > > > > > mm/page_table_check.c:213 > > > > Modules linked in: > > > > CPU: 0 PID: 5084 Comm: syz-executor382 Not tainted 6.9.0-rc4-next-20240417-syzkaller #0 > > > > Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 03/27/2024 > > > > RIP: 0010:__page_table_check_pte mm/page_table_check.c:199 [inline] > > > > RIP: 0010:__page_table_check_ptes_set+0x1db/0x420 mm/page_table_check.c:213 > > > > Code: 48 8b 7c 24 40 48 c7 c6 80 19 46 8e e8 ee df 8e ff 41 83 fc 1d 74 18 41 83 fc 1a 75 1d e8 5d da 8e ff eb 10 e8 56 da 8e ff 90 <0f> 0b 90 eb 10 e8 4b da 8e ff 90 0f 0b 90 eb 05 e8 40 da 8e ff 48 > > > > RSP: 0018:ffffc9000366f740 EFLAGS: 00010293 > > > > RAX: ffffffff8207833a RBX: ffffc9000366f7c0 RCX: ffff888022af3c00 > > > > RDX: 0000000000000000 RSI: 0000000000000004 RDI: 0000000000000000 > > > > RBP: ffffc9000366f830 R08: ffffffff820782af R09: 1ffffd40000a6a10 > > > > R10: dffffc0000000000 R11: fffff940000a6a11 R12: 0000000000000000 > > > > R13: 0000000014d42c67 R14: 0000000000000001 R15: 0000000000000000 > > > > FS: 0000555567f79380(0000) GS:ffff8880b9400000(0000) knlGS:0000000000000000 > > > > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > > > > CR2: 000000000066c7e0 CR3: 0000000078cb0000 CR4: 00000000003506f0 > > > > DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 > > > > DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 > > > > Call Trace: > > > > > > > > page_table_check_ptes_set include/linux/page_table_check.h:74 [inline] > > > > set_ptes include/linux/pgtable.h:267 [inline] > > > > __ptep_modify_prot_commit include/linux/pgtable.h:1269 [inline] > > > > ptep_modify_prot_commit include/linux/pgtable.h:1302 [inline] > > > > change_pte_range mm/mprotect.c:194 [inline] > > > > change_pmd_range mm/mprotect.c:424 [inline] > > > > change_pud_range mm/mprotect.c:457 [inline] > > > > change_p4d_range mm/mprotect.c:480 [inline] > > > > change_protection_range mm/mprotect.c:508 [inline] > > > > change_protection+0x2770/0x3cc0 mm/mprotect.c:542 > > > > mprotect_fixup+0x740/0xa90 mm/mprotect.c:655 > > > > do_mprotect_pkey+0x90d/0xe00 mm/mprotect.c:820 > > > > __do_sys_mprotect mm/mprotect.c:841 [inline] > > > > __se_sys_mprotect mm/mprotect.c:838 [inline] > > > > __x64_sys_mprotect+0x80/0x90 mm/mprotect.c:838 > > > > do_syscall_x64 arch/x86/entry/common.c:52 [inline] > > > > do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 > > > > entry_SYSCALL_64_after_hwframe+0x77/0x7f > > > > RIP: 0033:0x7f45514bf429 > > > > Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 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 b8 ff ff ff f7 d8 64 89 01 48 > > > > RSP: 002b:00007ffe52191598 EFLAGS: 00000246 ORIG_RAX: 000000000000000a > > > > RAX: ffffffffffffffda RBX: 00007ffe52191768 RCX: 00007f45514bf429 > > > > RDX: 000000000000000f RSI: 0000000000004000 RDI: 0000000020ffc000 > > > > RBP: 00007f4551532610 R08: 00007ffe52191768 R09: 00007ffe52191768 > > > > R10: 00007ffe52191768 R11: 0000000000000246 R12: 0000000000000001 > > > > R13: 00007ffe52191758 R14: 0000000000000001 R15: 0000000000000001 > > > > > > > > > > Did we find a real issue that involves mprotect()? > > > > > > At least can_change_pte_writable() should always return "false" for > > > userfaultfd_pte_wp(). > > > > > > Do we maybe have a uffd-wp PTE outside of a UFFD_WP VMA? > > > > > > Or was the PTE already writable and we only detect it now as we call > > > mprotect()? (missed to detect it earlier?) > > > > Staring at the reproducer, we do > > > > > > syscall(__NR_mmap, /*addr=*/0x1ffff000ul, /*len=*/0x1000ul, /*prot=*/0ul, > > /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, > > /*offset=*/0ul); > > syscall(__NR_mmap, /*addr=*/0x20000000ul, /*len=*/0x1000000ul, > > /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/ 7ul, > > /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, > > /*offset=*/0ul); > > > > -> Writable anonymous memmory > > > > syscall(__NR_mmap, /*addr=*/0x21000000ul, /*len=*/0x1000ul, /*prot=*/0ul, > > /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/ 0x32ul, /*fd=*/-1, > > /*offset=*/0ul); > > intptr_t res = 0; > > res = syscall(__NR_userfaultfd, > > /*flags=UFFD_USER_MODE_ONLY|O_NONBLOCK*/ 0x801ul); > > if (res != -1) > > r[0] = res; > > *(uint64_t*)0x200004c0 = 0xaa; > > *(uint64_t*)0x200004c8 = 0; > > *(uint64_t*)0x200004d0 = 0; > > syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc018aa3f, /*arg=*/0x200004c0ul); > > > > -> _UFFDIO_API handshake? > > > > syscall(__NR_mprotect, /*addr=*/0x20ffc000ul, /*len=*/0x3000ul, > > /*prot=PROT_SEM|PROT_EXEC*/ 0xcul); > > > > -> Protect target range R/O. I assume: no page populated yet? > > -> 3 pages starting at 0x20ffc000ul; > > > > *(uint64_t*)0x20000180 = 0x20ffc000; > > *(uint64_t*)0x20000188 = 0x3000; > > *(uint64_t*)0x20000190 = 3; > > *(uint64_t*)0x20000198 = 0; > > syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc020aa00, /*arg=*/0x20000180ul); > > > > -> _UFFDIO_REGISTER (aa00) > > -> _range = 3 pages starting at 0x20ffc000ul > > -> _mode = UFFDIO_REGISTER_MODE_WP | UFFDIO_REGISTER_MODE_MINOR > > > > *(uint64_t*)0x20000000 = 0x20ffd000; > > *(uint64_t*)0x20000008 = 0x20ffb000; > > *(uint64_t*)0x20000010 = 0x1000; > > *(uint64_t*)0x20000018 = 3; > > *(uint64_t*)0x20000020 = 0; > > syscall(__NR_ioctl, /*fd=*/r[0], /*cmd=*/0xc028aa03, /*arg=*/0x20000000ul); > > > > -> _UFFDIO_COPY (aa03) > > -> dst = 0x20ffd000 > > -> src = 0x20ffb000 > > -> len = 0x1000 (single page) > > -> mode = UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP > > > > -> We are copying into the R/O range. src should be R/W and trigger a page fault > > on access where we get a fresh page. > > > > *(uint16_t*)0x200000c0 = 1; > > *(uint64_t*)0x200000c8 = 0x20000040; > > *(uint16_t*)0x20000040 = 6; > > *(uint8_t*)0x20000042 = 0; > > *(uint8_t*)0x20000043 = 0; > > *(uint32_t*)0x20000044 = 0x7fffffff; > > res = syscall(__NR_seccomp, /*op=*/1ul, /*flags=*/0ul, /*arg=*/0x200000c0ul); > > if (res != -1) > > r[1] = res; > > syscall(__NR_open_tree, /*dfd=*/-1, /*filename=*/0ul, /*flags=*/0ul); > > > > -> No idea what happens here and if it is relevant. If __NR_seccomp failed, we would > > no set r[1]. > > > > syscall(__NR_close_range, /*fd=*/r[1], /*max_fd=*/-1, /*flags=*/0ul); > > > > -> Is that closing uffd as well, especially if __NR_seccomp failed? > > > > syscall(__NR_mprotect, /*addr=*/0x20ffc000ul, /*len=*/0x4000ul, > > /*prot=PROT_SEM|PROT_WRITE|PROT_READ|PROT_EXEC*/ 0xful); > > > > -> Restore write permissions. This seems to fire the uffd-wp page table check I assume. > > I think the issue is that userfaultfd_release() will clear the VMA UFFD_WP flag, > but it will not clear PTE uffd-wp bits. So we have leftover PTE uffd-wp bits at > the time we wr-unprotect. > > I thought we removed that lazy handling, but looks like we didn't consider the > "close uffd" case in: > > commit f369b07c861435bd812a9d14493f71b34132ed6f > Author: Peter Xu > Date: Thu Aug 11 16:13:40 2022 -0400 > > mm/uffd: reset write protection when unregister with wp-mode > > > close should behave just like unregister. > > > Simplified+readable reproducer: > > #define _GNU_SOURCE > > #include > #include > #include > #include > #include > #include > #include > #include > > int main(void) > { > void *src = mmap(0, 4096, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > void *dst = mmap(0, 4096, PROT_READ, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); > struct uffdio_register uffdio_register = {}; > struct uffdio_copy uffdio_copy = {}; > struct uffdio_api uffdio_api = {}; > int uffd; > > uffd = syscall(SYS_userfaultfd, O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY); > uffdio_api.api = UFFD_API; > ioctl(uffd, UFFDIO_API, &uffdio_api); > > uffdio_register.range.start = (uintptr_t)dst; > uffdio_register.range.len = 4096; > uffdio_register.mode = UFFDIO_REGISTER_MODE_WP; > ioctl(uffd, UFFDIO_REGISTER, &uffdio_register); > > uffdio_copy.dst = (uintptr_t)dst; > uffdio_copy.src = (uintptr_t)src; > uffdio_copy.len = 4096; > uffdio_copy.mode = UFFDIO_COPY_MODE_DONTWAKE|UFFDIO_COPY_MODE_WP; > ioctl(uffd, UFFDIO_COPY, &uffdio_copy); > > close(uffd); > > mprotect(dst, 4096, PROT_READ|PROT_WRITE); > return 0; > } Thanks, I'll post a patch. PS: next time feel free to try "strace ./reproducer", it'll do the translations and I found it handy to work with syzbot. -- Peter Xu