From: Vlastimil Babka <vbabka@suse.cz>
To: David Hildenbrand <david@redhat.com>,
Yang Shi <shy828301@gmail.com>,
kirill.shutemov@linux.intel.com, jannh@google.com,
willy@infradead.org, akpm@linux-foundation.org
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [v4 PATCH] fs/proc: task_mmu.c: don't read mapcount for migration entry
Date: Thu, 23 Mar 2023 11:11:40 +0100 [thread overview]
Message-ID: <64ec7939-0733-7925-0ec0-d333e62c5f21@suse.cz> (raw)
In-Reply-To: <9ba70a5e-4e12-0e9f-a6a4-d955bf25d0fe@redhat.com>
On 3/23/23 11:08, David Hildenbrand wrote:
> On 23.03.23 10:52, Vlastimil Babka wrote:
>> On 2/3/22 19:26, Yang Shi wrote:
>>> --- a/fs/proc/task_mmu.c
>>> +++ b/fs/proc/task_mmu.c
>>> @@ -440,7 +440,8 @@ static void smaps_page_accumulate(struct mem_size_stats *mss,
>>> }
>>>
>>> static void smaps_account(struct mem_size_stats *mss, struct page *page,
>>> - bool compound, bool young, bool dirty, bool locked)
>>> + bool compound, bool young, bool dirty, bool locked,
>>> + bool migration)
>>> {
>>> int i, nr = compound ? compound_nr(page) : 1;
>>> unsigned long size = nr * PAGE_SIZE;
>>> @@ -467,8 +468,15 @@ static void smaps_account(struct mem_size_stats *mss, struct page *page,
>>> * page_count(page) == 1 guarantees the page is mapped exactly once.
>>> * If any subpage of the compound page mapped with PTE it would elevate
>>> * page_count().
>>> + *
>>> + * The page_mapcount() is called to get a snapshot of the mapcount.
>>> + * Without holding the page lock this snapshot can be slightly wrong as
>>> + * we cannot always read the mapcount atomically. It is not safe to
>>> + * call page_mapcount() even with PTL held if the page is not mapped,
>>> + * especially for migration entries. Treat regular migration entries
>>> + * as mapcount == 1.
>>> */
>>> - if (page_count(page) == 1) {
>>> + if ((page_count(page) == 1) || migration) {
>>
>> Since this is now apparently a CVE-2023-1582 for whatever RHeasons...
>>
>> wonder if the patch actually works as intended when
>> (page_count() || migration) is in this particular order and not the other one?
>
> Only the page_mapcount() call to a page that should be problematic, not
> the page_count() call. There might be the rare chance of the page
Oh right, page_mapcount() vs page_count(), I need more coffee.
> getting remove due to memory offlining... but we're still holding the
> page table lock with the migration entry, so we should be protected
> against that.
>
> Regarding the CVE, IIUC the main reason for the CVE should be
> RHEL-specific -- which behaves differently than other code bases; for
> other code bases, it's just a way to trigger a BUG_ON as described here.
That's good to know so at least my bogus mail was useful for that, thanks!
next prev parent reply other threads:[~2023-03-23 10:11 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 18:26 Yang Shi
2022-02-03 22:12 ` Andrew Morton
2022-02-03 22:18 ` Yang Shi
2023-03-23 9:52 ` Vlastimil Babka
2023-03-23 10:08 ` David Hildenbrand
2023-03-23 10:11 ` Vlastimil Babka [this message]
2023-03-23 20:45 ` Yang Shi
2023-03-24 11:25 ` Vlastimil Babka
2023-03-24 20:12 ` Yang Shi
2023-04-03 7:29 ` David Hildenbrand
2023-04-04 0:50 ` Yang Shi
2023-04-13 23:58 ` David Rientjes
2023-04-18 21:17 ` Yang Shi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64ec7939-0733-7925-0ec0-d333e62c5f21@suse.cz \
--to=vbabka@suse.cz \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=jannh@google.com \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shy828301@gmail.com \
--cc=stable@vger.kernel.org \
--cc=willy@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox