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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAMgjq7CTtJ69W=6kOaEn740seY9Nh7To7WL+JTb_hFUHJ-TqAg@mail.gmail.com>
Date: Mon, 28 Apr 2025 10:58:09 +0800
From: Kairui Song <ryncsn@...il.com>
To: Matthew Wilcox <willy@...radead.org>
Cc: linux-mm@...ck.org, Andrew Morton <akpm@...ux-foundation.org>, 
	David Hildenbrand <david@...hat.com>, Hugh Dickins <hughd@...gle.com>, Chris Li <chrisl@...nel.org>, 
	Yosry Ahmed <yosryahmed@...gle.com>, "Huang, Ying" <ying.huang@...ux.alibaba.com>, 
	Nhat Pham <nphamcs@...il.com>, Johannes Weiner <hannes@...xchg.org>, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/6] filemap: do not use folio_contains for swap cache folios

On Mon, Apr 28, 2025 at 8:44 AM Matthew Wilcox <willy@...radead.org> wrote:
>
> On Mon, Apr 28, 2025 at 02:59:06AM +0800, Kairui Song wrote:
> > For filemap and truncate, folio_contains is only used for sanity checks
> > to verify the folio index matches the expected lookup/invalidation target.
> > The swap cache does not utilize filemap or truncate helpers in ways that
> > would trigger these checks, as it mostly implements its own cache management.
> >
> > Shmem won't interact with these sanity checks either unless thing went
> > wrong, it would directly trigger a BUG, because swap cache index are
> > unrelated to shmem index, and would almost certainly mismatch (unless
> > on collide).
>
> It does happen though.  If shmem is writing the folio to swap at the
> same time that the file containing the folio is being truncated, we
> can hit this.

Thanks for the info! I didn't check it in detail because that would
likley trigger a BUG_ON but so far I didn't see any BUG_ON commit from
there.

Just checked there are two users in truncate:

One will lock the folio and check if `folio->mapping != mapping`
first, on swapout shmem removes the folio from shmem mapping so this
check will skip the folio_contains check.

Another seems might hit the check, the time window is extremely tiny
though, only if the truncate's `xa_is_value(folio)` check passed while
another CPU is running between `folio_alloc_swap` and
`shmem_delete_from_page_cache` in shmem_writepage, then the next
VM_BUG_ON_FOLIO(!folio_contains) will fail as folio is now  a
swap cache, not shmem folio anymore. Let me double check if this needs
another fix.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ