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 EFA8BC47258 for ; Thu, 25 Jan 2024 09:37:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 840E2280003; Thu, 25 Jan 2024 04:37:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F13A280001; Thu, 25 Jan 2024 04:37:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6B8CD280003; Thu, 25 Jan 2024 04:37:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 5C0E9280001 for ; Thu, 25 Jan 2024 04:37:08 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 2AAA840292 for ; Thu, 25 Jan 2024 09:37:08 +0000 (UTC) X-FDA: 81717329736.23.852DF65 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf01.hostedemail.com (Postfix) with ESMTP id CA75740009 for ; Thu, 25 Jan 2024 09:37:05 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nwpki+gc; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706175426; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=d4no+t/536MQl/W55U0FMyUk7bvFTRoNFN2/SYfuRTI=; b=elqUcI5ikX1DfzngWGA6UbeKJPMipw2XJ8GscDe++HFXKSblRNQa0ASgOlBNfG2QBZtsSd MvSeDWSiV4B/cdpSQME5gGef1aVkiwiv9SNnFH5gnoPjkgUG3llSEO9QB5VNflfu4vZx3I C1ifktXDIBkLslKdVrX5NmDsCbo0WkY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706175426; a=rsa-sha256; cv=none; b=YNckV/qW5N6UH5bnVbKM55l4AIR9FrTm8pxhKxotyKXwErnMUMkWIoP1/oulUN58lAnEac I/erA7erV+Aq6vagQrLgRgSL3gdEd2MDEAnEVh1PXWUO11RvHRlbF4Ff3yPBYIqwYKKYgy Ypq2yyfHXIoWYDFENCpbnTcInWW1R/g= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=nwpki+gc; spf=pass (imf01.hostedemail.com: domain of rppt@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=none) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 8E856CE32F4; Thu, 25 Jan 2024 09:37:01 +0000 (UTC) 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Stat-Signature: bngzr4w75bnip6wmw6mf8gtzx4yqie1d X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: CA75740009 X-Rspam-User: X-HE-Tag: 1706175425-20768 X-HE-Meta: U2FsdGVkX1/9y/mrikn1Yb0daO0kXXJrsT09U0EarO7PRAAzAcblfIbsEKR88+fito9ZAlcEXREx0k3JVlGVB7KU/ezaayjexAvwaTa8ujv4wZTh1rfr6VeuyK9eQGp+Me45/q6MjulBlGgs4i6LuhTabVzGluK0RF2LC4XDusHJGk7b/jsmttp8k0PSy4hrFotJCZVfyT/eJRpf+Ndraarlc1eU4iGGQEdVDtN+09DbDGHGOndktPXmK6AsEc0+OD8EYnbbwTvoNWoAW+HybBUiORciujmjbNdV3q7zHKqkgarNjoI4MYZbqoHIWwl3w9Uex3dqqgpPGs3hiW3cL8LrP0qS+gpfgaGJsCrt8nMZasKAasSRrsM6+AWX91ljw8Fi6B+f6EwvIGXZsS+STAMRng5A6M7fe7CcAc7q50sd8kN/05YdefqEzdx0ee4xvBqWBMDc0rVku/WTqZm/t2GerTxZI7flbezZcFKlm3gyaMPz+h0FXEZNJgaLpVuIBxUgmOVp+xHftP8kKBumHhuXgmfTkV8A13jGOnlDxaD/tJ7yriWL7sAWd1hoQseKydp06mhJFSXOpnX/rXJytSQ3v8KCf5EO4OfzS7WrMo7aaFdleRMJvNmPPooa88Gb8dssK9aSFRkexYYqWnXcNs4/mqkFeK7E9O1Dh4k+MslLj6g0rj93p6O0V/uocdInltB5ddN8A24DCx1bVnMnuFhI8bnfgB7ZZyuTjLHXjxwk61Q+3YTIcVZXshroyrCwtrwHhWT7C9T3WIsgAxw/t2PLJBsTbLNX9pCedXu0LMT9Ye4R1mNB+stttdM0gtF/FrtjLQJElTSKGt0QAeBDt18RCfX8fCefuJ/kxI8Svm1RoSr8tEAywYH2gmlKZfqDewy2GUzXxhSfST3OS76vgrSV4uHy1rXJgu2+5ELNdu7vPW7ajcVgeKY1mV23zDo9rZlsGX5Di7XHpkQODr7 cYEGdmhm BgfJGMvJA0gKIkp2UL/DeXh42RO5rroCxbCf4cqLFW1oN5H7VXPvHqwFOkXWUDrobq1rpa8T4F0rJHBAUgulbcg87c+NWgw6RRCI0aaEjvhMKPk10Nm4qE83ZvffoSbSUbLZwoN9fgQAprf9/9yFAsFEMnnm5jBup/lZU05v1o/d2Hg4kjNckC1UbUTasa4tsQnHNaRZV/zGchcSCbdATIBn43XdeRDhyaSyhhNjXRmxa3eRrMj3/q8tn3HGHTp8AlF251FsAbpTcUfQrVHomF9RDpZ2IrWQndfWleruXyBZr+P5q5BU4wQ0uIs8HRQKu2+ZA 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 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.