lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <673991ef-90d0-456f-ae75-8d70bff3ea4d@huawei.com>
Date: Thu, 7 Nov 2024 17:30:42 +0800
From: mawupeng <mawupeng1@...wei.com>
To: <david@...hat.com>, <peterx@...hat.com>
CC: <mawupeng1@...wei.com>, <linux-kernel@...r.kernel.org>,
	<linux-mm@...ck.org>, <x86@...nel.org>, <xrivendell7@...il.com>,
	<wang1315768607@....com>, <fleischermarius@...il.com>,
	<dave.hansen@...ux.intel.com>, <luto@...nel.org>, <peterz@...radead.org>,
	<tglx@...utronix.de>, <mingo@...hat.com>, <bp@...en8.de>, <hpa@...or.com>,
	<akpm@...ux-foundation.org>
Subject: Re: [PATCH v1] x86/mm/pat: fix VM_PAT handling when fork() fails in
 copy_page_range()



On 2024/11/7 17:08, David Hildenbrand wrote:
> On 07.11.24 09:43, mawupeng wrote:
>>
>>
>> On 2024/10/31 17:47, David Hildenbrand wrote:
>>> On 30.10.24 22:32, Peter Xu wrote:
>>>> On Tue, Oct 29, 2024 at 10:03:31PM +0100, David Hildenbrand wrote:
>>>>> If track_pfn_copy() fails, we already added the dst VMA to the maple
>>>>> tree. As fork() fails, we'll cleanup the maple tree, and stumble over
>>>>> the dst VMA for which we neither performed any reservation nor copied
>>>>> any page tables.
>>>>>
>>>>> Consequently untrack_pfn() will see VM_PAT and try obtaining the
>>>>> PAT information from the page table -- which fails because the page
>>>>> table was not copied.
>>>>>
>>>>> The easiest fix would be to simply clear the VM_PAT flag of the dst VMA
>>>>> if track_pfn_copy() fails. However, the whole thing is about "simply"
>>>>> clearing the VM_PAT flag is shaky as well: if we passed track_pfn_copy()
>>>>> and performed a reservation, but copying the page tables fails, we'll
>>>>> simply clear the VM_PAT flag, not properly undoing the reservation ...
>>>>> which is also wrong.
>>>>
>>>> David,
>>>>
>>>
>>> Hi Peter,
>>>
>>>> Sorry to not have chance yet reply to your other email..
>>>>
>>>> The only concern I have with the current fix to fork() is.. we started to
>>>> have device drivers providing fault() on PFNMAPs as vfio-pci does, then I
>>>> think it means we could potentially start to hit the same issue even
>>>> without fork(), but as long as the 1st pgtable entry of the PFNMAP range is
>>>> not mapped when the process with VM_PAT vma exit()s, or munmap() the vma.
>>>
>>> As these drivers are not using remap_pfn_range, there is no way they could currently get VM_PAT set.
>>>
>>> So what you describe is independent of the current state we are fixing here, and this fix should sort out the issues with current VM_PAT handling.
>>>
>>> It indeed is an interesting question how to handle reservations when *not* using remap_pfn_range() to cover the whole area.
>>>
>>> remap_pfn_range() handles VM_PAT automatically because it can do it: it knows that the whole range will map consecutive PFNs with the same protection, and we expect not parts of the range suddenly getting unmapped (and any driver that does that is buggy).
>>>
>>> This behavior is, however, not guaranteed to be the case when remap_pfn_range() is *not* called on the whole range.
>>>
>>> For that case (i.e., vfio-pci) I still wonder if the driver shouldn't do the reservation and leave VM_PAT alone.
>>>
>>> In the driver, we'd do the reservation once and not worry about fork() etc ... and we'd undo the reservation once the last relevant VM_PFNMAP VMA is gone or the driver let's go of the device. I assume there are already mechanisms in place to deal with that to some degree, because the driver cannot go away while any VMA still has the VM_PFNMAP mapping -- otherwise something would be seriously messed up.
>>>
>>> Long story short: let's look into not using VM_PAT for that use case.
>>>
>>> Looking at the VM_PAT issues we had over time, not making it more complicated sounds like a very reasonable thing to me :)
>>
>> Hi David,
>>
>> The VM_PAT reservation do seems complicated. It can trigger the same warning in get_pat_info if remap_p4d_range fails:
>>
>> remap_pfn_range
>>    remap_pfn_range_notrack
>>      remap_pfn_range_internal
>>        remap_p4d_range    // page allocation can failed here
>>      zap_page_range_single
>>        unmap_single_vma
>>          untrack_pfn
>>            get_pat_info
>>              WARN_ON_ONCE(1);
>>
>> Any idea on this problem?
> 
> In remap_pfn_range(), if remap_pfn_range_notrack() fails, we call untrack_pfn(), to undo the tracking.
> 
> The problem is that zap_page_range_single() shouldn't do that untrack_pfn() call.
> 
> That should be fixed by Peter's patch:
> 
> https://lore.kernel.org/all/20240712144244.3090089-1-peterx@redhat.com/T/#u

Thank you for your prompt reply.

This do fix this issue.

> 


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ