Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page

From: zhangliang (AG)
Date: Fri Jan 14 2022 - 00:09:08 EST




On 2022/1/14 0:48, David Hildenbrand wrote:
> On 13.01.22 17:37, Linus Torvalds wrote:
>> On Thu, Jan 13, 2022 at 6:39 AM Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:
>>>
>>> Let's bring Linus in on this, but I think this reintroduces all of the
>>> mapcount problems that we've been discussing recently.
>>>
>>> How about this as an alternative?
>>
>> No, at that point reuse_swap_page() is the better thing to do.
>>
>> Don't play games with page_count() (or even worse games with
>> swap_count). The page count is only stable if it's 1. Any other value
>> means that it can fluctuate due to concurrent lookups, some of which
>> can be done locklessly under RCU.
>
> I'm pretty sure the patch as is will reintroduce the CVE. So I think in

Actually, I wonder how reuse_swap_page() in this patch can reintroduce CVE,
I think the invoking logic here is as same as that in do_swap_page().
So, could you give me some hint about this? Thanks :)

> addition to the reuse_swap_page() check we need more.
>
> I'm wondering if we can get rid of the mapcount checks in
> reuse_swap_page() and instead check for page_count() and swapcount only.
>
> We don't care if it's unstable in a sense than it will be bigger than
> what we expect. In that case we COW as we would already do.
>
> Thoughts?
>

--
Best Regards,
Liang Zhang