Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1642576rdb; Thu, 25 Jan 2024 01:37:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IF+xmdVQHPCWGKRGOjyxThFU2sNjBTHxJ5Ua/HeH+Pc4sKhQ42gwbbrqzt9Uq23AsHjfwFD X-Received: by 2002:a05:6808:11ce:b0:3bd:b46b:6cc8 with SMTP id p14-20020a05680811ce00b003bdb46b6cc8mr560416oiv.39.1706175462604; Thu, 25 Jan 2024 01:37:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706175462; cv=pass; d=google.com; s=arc-20160816; b=yDboDbjDQeiBkOLQsAqig/eXqRXl+h1CO//SsEDXcl853qDVIYBRaqUi6G0Cu/PqNd yX5LGRcUCGArgjyjAJzi/fcCxSdZ/t1JRZvV/hlmVWFBz4hnbjc8NbDMehARPKxPHhF6 qXMKn5OU+OZfeIQlOroXSU47dl5o7JBd8nC6+IwczH8HgBlVHA62k9iJcJeeOUYAh8jG 2lySYrR8uWcfgoOuSjdOnN+qtsVTAEO5tg0tyO+pNdUxuHJZNbyLW+DYXMVT1BDkpVjl mvTXRc7iqqR9Upq3Hn1qzFAzj+WKdnhmn+qNp3E1aRhcab5s+PNzLl8/rh6OqZvgUD4i IVfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=d4no+t/536MQl/W55U0FMyUk7bvFTRoNFN2/SYfuRTI=; fh=daqX8SLFLH0ZMIJRsSLl/Jup1iz7Tg9oSBSPCay1GWw=; b=Mq7Dfd5ULST5e0yyTORJWktiBAmXTlCAfSoGwcXTQPwKCeZ7Qu9qHaZF3mkas72AN5 C+NOMlFe1m2Enogkf58PpfC6o0XnvblLkDaD2D8Bsuf/oIiyRrMZCRwyZAk2kP6equbS 1rptqvmqeJAxJwPCuqj1WemZuZfgr07OzWz4ltAKuKBtbabJY9A0bE4Wi5qZ14oudJMD je3p5y+LQnpN6HnC3Fjh9yWU9VWjKy0gysg08u1yY26as1qvFmSlUAK+Hecuks2UaoL5 qrjf81AegFdk0naQWiBM2+w8GYdlW2//Yha0NWy4tXDah7SbMd3XZmBy7jLvczDuVnjI ZrVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nwpki+gc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38284-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h18-20020ac85e12000000b0042a2c58fc4dsi12136107qtx.354.2024.01.25.01.37.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 01:37:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nwpki+gc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-38284-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38284-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 4AF981C21214 for ; Thu, 25 Jan 2024 09:37:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9A45F1CA88; Thu, 25 Jan 2024 09:37:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="nwpki+gc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8EA51C6AD; Thu, 25 Jan 2024 09:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706175420; cv=none; b=LrEswRdT8IiqGwiNYOAaA/agmAxxJgpd8bF38RvlMQZh745Ex6N0ElPg/puuHeqCI2L5cD7QTN3Ff8AK3jHkUIwuCZw667aBGTuyli2q4p35zlaQbzjWMEho3PMVW2uGWxoraqrAJ0EiRUPKaafkhV1aW1CiCJR7H6dzuxO1gr4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706175420; c=relaxed/simple; bh=gr94+56P2kzJDDYJRH88M8lUAPhvUUKPfiyNI1RdoIA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MP/sdbi1cEO1HfYZS0GiH9A1z6YlOW/iSwqZi6spSAoXwNEbvwDVueEz4y9IhuyRcmToJMZ9WgVcS+IRIcT+qPFd4+Ts+PaxTw/xXJU55MStAiFJfFwieK4kK1Xqb3wDEWXll7TK0E096mysDtJk+E08vthH/q4TB9oW/EL4CCM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nwpki+gc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C2154C433C7; Thu, 25 Jan 2024 09:36:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706175420; bh=gr94+56P2kzJDDYJRH88M8lUAPhvUUKPfiyNI1RdoIA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nwpki+gcKqJKaqfmZgMJ7UFiFnVP1doqvD1NAyxkVsTKDmQLRRQarzW/fEuRkdAvi 7NfCPwsIyhG1oOwHUUAU0c/faUk7GdbyfFPTU+VmUvyts+VhsCzV97cCgEFFN2cc8F iQY/oCgkaWWxZVSrXsD8JqUOdHEUAFXGCpS+21U5jD//uVrK4KNg6IhoAW8r/Sj1Fv 8Ghl/QpvvIuLu6Hii4QqaN3dJ+95yJ2H+aggMBYLiE/5F7axNinkm6kiPiJn1ouHCa T8NPJchz0ua0P0SFQWufV2Cn5XDZ9AQaehvdJvrMdqoNU/bgeG7TjafSaLtZXbvdPa +B/iVsYKghDgQ== Date: Thu, 25 Jan 2024 11:36:32 +0200 From: Mike Rapoport To: Axel Rasmussen Cc: Andrew Morton , Lokesh Gidra , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, selinux@vger.kernel.org, surenb@google.com, kernel-team@android.com, aarcange@redhat.com, peterx@redhat.com, david@redhat.com, bgeffon@google.com, willy@infradead.org, jannh@google.com, kaleshsingh@google.com, ngeoffray@google.com Subject: Re: [PATCH] userfaultfd: fix mmap_changing checking in mfill_atomic_hugetlb Message-ID: References: <20240117223729.1444522-1-lokeshgidra@google.com> <20240118135941.c7795d52881f486aa21aeea8@linux-foundation.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Jan 18, 2024 at 03:17:14PM -0800, Axel Rasmussen wrote: > > On Thu, Jan 18, 2024 at 1:59 PM Andrew Morton > wrote: > > On Wed, 17 Jan 2024 14:37:29 -0800 Lokesh Gidra > wrote: > > > In mfill_atomic_hugetlb(), mmap_changing isn't being checked > > again if we drop mmap_lock and reacquire it. When the lock is not held, > > mmap_changing could have been incremented. This is also inconsistent > > with the behavior in mfill_atomic(). > > > The change looks reasonable to me. I'm not sure I can conclusively say there > isn't some other mechanism specific to hugetlbfs which means this isn't needed, > though.   There's nothing specific to hugetlb, if a non-cooperative uffdio_copy races with mremap/fork etc, the vma under it may change > Thanks. Could you and reviewers please consider > > - what might be the userspace-visible runtime effects? For users of non-cooperative uffd with hugetlb, this would fix crashes caused by races between uffd operations that update memory and the operations that change the VM layout. Pretty much the same fix as df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races") for !hugetlb memory. I doubt such users exist, though... > - Should the fix be backported into earlier kernels? > - A suitable Fixes: target? > > Hmm, 60d4d2d2b40e4 added __mcopy_atomic_hugetlb without this. But, at that > point in history, none of the other functions had mmap_changing either. > > So, I think the right Fixes: target is df2cc96e77011 ("userfaultfd: prevent > non-cooperative events vs mcopy_atomic races") ? It seems to have missed the > hugetlb path. This was introduced in 4.18. > > Based on that commit's message, essentially what can happen if the race > "succeeds" is, memory can be accessed without userfaultfd being notified of > this fact. Depending on what userfaultfd is being used for, from > userspace's perspective this can appear like memory corruption for example. So, > based on that it seems to me reasonable to backport this to stable kernels > (4.19+). I agree with Axel, Fixes: df2cc96e77011 ("userfaultfd: prevent non-cooperative events vs mcopy_atomic races") seems appropriate. -- Sincerely yours, Mike.