From mboxrd@z Thu Jan 1 00:00:00 1970 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 A7EF9378812 for ; Tue, 31 Mar 2026 11:56:40 +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=1774958200; cv=none; b=OMKe2k1G6tYyMHUj0z9tr8EsagSb+EezU8ds5GMxyNtKewhCST1GsfxnyQtmLGGUw4RTHRCj0RzPW18e0oBE8+MQXC2CAOxE/czg1FwTxEEAELyvrVx3NHRleazhn4tvklG9Zmara3RfXDVsPuiKjSGG+pl7S1zqUwOYJmc9l6Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774958200; c=relaxed/simple; bh=FMyI+hF8rpe/NqjE9yc1wgMGr70W/8wNEBMJNTw+CEs=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=jNdccKnpLIALhpE5i/qB0ga8s90dw5qWM0B7S1s1WeYdke8MoQjuF6SSPyKxIgmLVOsl85KrTtERu4lihhnFpP7T0nb3WgVwtSBuLpnigFl4ptdPbq1escocmzPoLWvn4rt1IBMrxzJjfQZv16MVXtQXbIiYKp63fOmzr+F9H0A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BeFzkVmi; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="BeFzkVmi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D835FC19423; Tue, 31 Mar 2026 11:56:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774958200; bh=FMyI+hF8rpe/NqjE9yc1wgMGr70W/8wNEBMJNTw+CEs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=BeFzkVmimymyHmwLsFeymfxbRTc6ipv0ec8kukVBw1ecHuDomyng9YcdVwlB3yCVA gMhNj9hx34sznU4d7IW98tdbTZso9CJzekFw6KtSOJkMgE9WVoSmiTS8z+MS6IpcBx Zg5quKZqA1NNKn45/Pru6/3DPUyVoYnWlTPpovD/W9YzFUuTt4tKY8cUysKZsTXote rlCwBOAK9KcujLxnXXZA3D7vxwSBlf+oOjauq2UjEiknKs0+f32e5gofoE2thqtaDd TT4fID0wuhtNCzQ7mEfPS0UeNYIVYnsgRkV9Iw1NwN6skPK5kLXJghhShlTOC8s9Re LepzmQCuei9Eg== Date: Tue, 31 Mar 2026 14:56:34 +0300 From: Mike Rapoport To: David Carlier Cc: Peter Xu , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Lorenzo Stoakes Subject: Re: [PATCH v2] mm/userfaultfd: detect VMA replacement after copy retry in mfill_copy_folio_retry() Message-ID: References: <20260330202909.136776-1-devnexen@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20260330202909.136776-1-devnexen@gmail.com> (added VMA folks) Hi, On Mon, Mar 30, 2026 at 09:29:09PM +0100, David Carlier wrote: > In mfill_copy_folio_retry(), all locks are dropped to retry > copy_from_user() with page faults enabled. During this window, the VMA > can be replaced entirely (e.g. munmap + mmap + UFFDIO_REGISTER by > another thread), but the caller proceeds with a folio allocated from the > original VMA's backing store. Is it possible at all that after all that dance vma pointer will remain the same? > Checking ops alone is insufficient: the replacement VMA could be the > same type (e.g. shmem -> shmem) with identical flags but a different > backing inode. Take a snapshot of the VMA's inode and flags before > dropping locks, and compare after re-acquiring them. If anything > changed, bail out with -EAGAIN. > > Suggested-by: Peter Xu > Signed-off-by: David Carlier Sashiko has comments and they seem quite relevant to me: https://sashiko.dev/#/patchset/20260330214948.148349-1-devnexen%40gmail.com > --- > mm/userfaultfd.c | 64 ++++++++++++++++++++++++++++++++++++++++++------ > 1 file changed, 57 insertions(+), 7 deletions(-) ... > + if (vma_snapshot_changed(state->vma, &s)) { > + err = -EAGAIN; Whatever we do verify the VMA this should not be EAGAIN. EINVAL or ENOENT like mfill_get_vma() returns seem more appropriate. > + goto out; > + } -- Sincerely yours, Mike.