From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796376454; b=vtgauvnpz9EvOIx7GWUsKtwsWA4uRFlv34cU2ztfzDcKEDdNQs50KpK6H/mkN313nV6m lqei6a2CWUo7FJsLQxPfJIlNAWwYqgS2o9mSJ0oC8fenribLaqJ5WeGiKE5uKl9ImpJLn qniXSvL47Bj8SkWyDU32aeBIDHr+o1ePaIn6zRAINiCA+ttVCDGc2Zg68Ld6D60X3i11B MD8CwEHT3RU/NWtXNehU4pY/VOObVkbdDVR6LcBePXMUm4Aa0eiTUG2h4qSeoL4DJ/3Hm MBMb2Q8DBaOUZtBu+3cMO+xBBV4IJFW0g1dTlqrOTkJuB5q8EN4evgR3cHUvaIMeopg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796376454; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References: Content-Language:From:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=nFYny9MRAH4HfiQD/WROS52UMf1V1cL3FqVrykx/F+0=; b=Ev9KSYjByiEQP2i/qx5kBj9bka2Cv9ijB6flwPsbYBnyBVh0W2hGAZeNK6+zxoISJtYH ZJ2TnUmMj0NOLoIBj41YhgWaGdgtWQizkQhFWe85wxizisszQtmT33LNDgdvhxia8ZrS7 yQhhRIpw7yyZFMBAGa9x+wCHI2qx2e8c/9qZHQZMzhDMFtMe5eD1aYBYJMRKu+iJ/isoS fZy/NtZCiEr1MIAz63v+65Fbc7SrZs+cMVjqQf3IekSL05Pg1uBMQz2Y2sMx+bSFlqdyE Lt2D+htnVQPFpuAhWpoQFLP0tBVWHApCqxbXS2roarB3bjOy29PMlgl3X0xh4mnkJiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HTCsWhZQ; arc=none smtp.remote-ip=209.85.221.45 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B1F4A606A32D for ; Fri, 4 Dec 2026 09:27:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B1F4A606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=HTCsWhZQ Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-490d59c3edaso445331f8f.1 for ; Fri, 04 Dec 2026 01:27:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796376452; x=1796981252; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nFYny9MRAH4HfiQD/WROS52UMf1V1cL3FqVrykx/F+0=; b=HTCsWhZQpGKxjjJz5PqgIYow0GZW5S81UVmyZyxK0L/7RgRjBncn/zUvih4VrFFTY2 uqEE5tpNexYCkdueSIa8W2DiFNBh7R00R03WLgRG2EUehBYoRhbjbIs/rrePYUQe/xBQ 8kEfJ6/WEmuVzAcWbKKzDpTw7Gi2L0BaVoMmaWQBFqvhQ0t0IDB5Lo3wi8QXVnwr5fb4 qRytWNtyAoYpOW7bD+VLfZTk26yyjHhQZyMoFdMuX86kxj2b63XIukEv5u+W8hsPzPmf Oq5eO87sf5jp3qQQpKgyB1mpslqQHsZApZ3gHcaA3UIsUCqcCiGxqXhYwT0CPlVPoFKL FpCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796376452; x=1796981252; h=content-transfer-encoding:content-type:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nFYny9MRAH4HfiQD/WROS52UMf1V1cL3FqVrykx/F+0=; b=N+vD6RiK4AmaUEcjuPjWnH1IRlpJxQBHsWHWsXp857gG/TGVlf2bRgm6q4go21RwtZ VlYWpavE64M3huuhGrvaX0arHyWlmw9ybLDbH0RjOtpXVhZIIT+B451f7PX66jF9UuM9 5lvySLNz32HZTy7n3hw5pqPSW3AcAhkbdreEpYvLhFtKjkUmoF45kvPgp565/fdKBpoW EQ7LxSTGB7AsXHpbXRTVDg3Un79xhcn2oTf/ufDgkv4i/XKwTJRmxafXXYpsdLHuhTw5 VDw69kcPLY8o+BOEkail3M3QGo3rx/Z/liZN/7+wjwdhC4JIX9uITD71SwlEA52oL7Ia vNPA== X-Forwarded-Encrypted: i=1; AL+hErHHZzB2xAdG/nrE+gW5g86cSICttHYNLA2e6av+l43mujLk765tZsGR9WsXJKtJC5odfGO/n6Ut39R82RA=@vger.kernel.org X-Gm-Message-State: APuU4Z/zVooAtYBFuQ+DIpBnSABtLvkQmiksdzHqNExtWXukdUUwu4gf qYwSVu7IAve3TS3Sy/7QnHYzYpzUmh1kRYrA3TWARH4gC+z5/KJtaM+t X-Gm-Gg: AZFdTZf57bNjrftS4TayLP+CaiPZi7comIcSkm4Esw1Ik6xNPviN22/E1xjxynJxkek T1Jyb+1jJJh+24GbbEXJ2fVggRQPzEF6jUm1mhT/p/y36RvPZzqr+vdqn6HdHzp2dzfu5ZdvR16 UoE5dzIZrkhGJXZxr5G5mcpnb97hReEHLzAtGYlyY9Ugsk7SkTVr1kB2KThgc3iu+kLxDmFGx9x fbTQXNdSQQ7KwdtFeAykiLHZexzSUI3k8wTNfT7VJ7BNd4jJbOYfN2YAtnL17NxwQC2uSRYws0g cRFUmJzj4kKek7d6ACT23ZvKkH+e1nqM36UAkGYchJYRyzLWpkXwnKkQzgv+GhSyR2YY7rDpgaK 2v2gKLeUwZ/8vBgPp2ZCaRYWffR05QnIyR5KrbRU060Wxi8z9cO3h73vAelEld8b9OK6yEwHHcw PZzDKXhIxpudMwM218U02uOMoDb+nG7rD7lNwfsojg1vQiH3C9S4tRCqb6tbsixlTeFVxb74duA NkL/7F9hPZ1h+RwRo1nPKieS0FA6vIxoaJqgPMNwHasDO5ePkebmv3HyJj7qXH7iMTm/F6tcJTO uOboXH/oO7dx08R+ixW7nYod2BEiTOA6xp6ZORQgQqaLztu4XW0rab+T9wJfoJtGjEmFz5GZpNb e6Q== X-Received: by 2002:a5d:6602:0:b0:4a9:9a59:c7a6 with SMTP id ffacd0b85a97d-4d1eac5a93emr2374062f8f.16.1796376452106; Fri, 04 Dec 2026 01:27:32 -0800 (PST) Received: from [192.168.1.22] ([83.231.69.9]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d1724ad151sm4197164f8f.15.2026.12.04.01.27.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 04 Dec 2026 01:27:31 -0800 (PST) Message-ID: Date: Fri, 4 Dec 2026 10:27:30 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 1/4] userfaultfd: write-lock the VMA before clearing its uffd state To: "Mike Rapoport (Microsoft)" , Andrew Morton , David Hildenbrand Cc: Peter Xu , Suren Baghdasaryan , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Sashiko References: <20261203-fixes-uffd-sashiko-v2-0-308ce557a7b6@kernel.org> <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org> Content-Language: en-US From: "Jose A. Perez de Azpillaga" In-Reply-To: <20261203-fixes-uffd-sashiko-v2-1-308ce557a7b6@kernel.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 12/3/26 6:15 PM, Mike Rapoport (Microsoft) wrote: > UFFDIO_COPY and other uffd operations run under the per-VMA lock. They > check that the VMA is registered with a userfaultfd, but not that it is > registered with the userfaultfd that issued the operation. > > When a userfaultfd is closed, userfaultfd_release_all() clears the uffd > state of its VMAs without write-locking them. Another userfaultfd of the > same mm can then install a write-protected PTE in a part of the VMA that > userfaultfd_clear_ptes() has already walked. The PTE keeps its uffd bit > after the VMA is unregistered, and a later write fault makes it writable > with the uffd bit still set. > > close(uffd1) UFFDIO_COPY(uffd2, MODE_WP) > > userfaultfd_release_all() > mmap_write_lock() > userfaultfd_clear_vma() > userfaultfd_clear_ptes() > change_protection() > // walks past addr > lock_vma_under_rcu() > validate_dst_vma() > // installs PTE with the uffd bit > // at addr > vma_end_read() > userfaultfd_reset_ctx() > vma_start_write() > mmap_write_unlock() > > write fault at addr > do_wp_page() > // the PTE becomes writable with the uffd bit set > > UFFDIO_UNREGISTER is not affected since > commit 35f7ecd55ce7 ("mm/userfaultfd: write-lock the VMA before waking > waiters when unregistering"). > > Write-lock the VMA in userfaultfd_clear_ptes() before walking it. > > Reported-by: Sashiko > Closes: https://sashiko.dev/bug/linux-5cddfd13-146a-47fc-97f8-feca4b2339b4 > Fixes: c88033efe9a3 ("mm/userfaultfd: reset ptes when close() for wr-protected ones") > Reviewed-by: Suren Baghdasaryan > Signed-off-by: Mike Rapoport (Microsoft) LGTM: Reviewed-by: Jose A. Perez de Azpillaga -- cheers, jose a. p-a