From: Baolin Wang <baolin.wang@linux.alibaba.com>
To: Kemeng Shi <shikemeng@huaweicloud.com>,
akpm@linux-foundation.org, willy@infradead.org
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org
Subject: Re: [PATCH v3 1/5] Xarray: Do not return sibling entries from xas_find_marked()
Date: Fri, 13 Dec 2024 14:12:47 +0800 [thread overview]
Message-ID: <1f8b523e-d68f-4382-8b1e-2475eb47ae81@linux.alibaba.com> (raw)
In-Reply-To: <20241213122523.12764-2-shikemeng@huaweicloud.com>
On 2024/12/13 20:25, Kemeng Shi wrote:
> Similar to issue fixed in commit cbc02854331ed ("XArray: Do not return
> sibling entries from xa_load()"), we may return sibling entries from
> xas_find_marked as following:
> Thread A: Thread B:
> xa_store_range(xa, entry, 6, 7, gfp);
> xa_set_mark(xa, 6, mark)
> XA_STATE(xas, xa, 6);
> xas_find_marked(&xas, 7, mark);
> offset = xas_find_chunk(xas, advance, mark);
> [offset is 6 which points to a valid entry]
> xa_store_range(xa, entry, 4, 7, gfp);
> entry = xa_entry(xa, node, 6);
> [entry is a sibling of 4]
> if (!xa_is_node(entry))
> return entry;
>
> Skip sibling entry like xas_find() does to protect caller from seeing
> sibling entry from xas_find_marked() or caller may use sibling entry
> as a valid entry and crash the kernel.
>
> Besides, load_race() test is modified to catch mentioned issue and modified
> load_race() only passes after this fix is merged.
>
> Here is an example how this bug could be triggerred in tmpfs which
> enables large folio in mapping:
> Let's take a look at involved racer:
> 1. How pages could be created and dirtied in shmem file.
> write
> ksys_write
> vfs_write
> new_sync_write
> shmem_file_write_iter
> generic_perform_write
> shmem_write_begin
> shmem_get_folio
> shmem_allowable_huge_orders
> shmem_alloc_and_add_folios
> shmem_alloc_folio
> __folio_set_locked
> shmem_add_to_page_cache
> XA_STATE_ORDER(..., index, order)
> xax_store()
> shmem_write_end
> folio_mark_dirty()
>
> 2. How dirty pages could be deleted in shmem file.
> ioctl
> do_vfs_ioctl
> file_ioctl
> ioctl_preallocate
> vfs_fallocate
> shmem_fallocate
> shmem_truncate_range
> shmem_undo_range
> truncate_inode_folio
> filemap_remove_folio
> page_cache_delete
> xas_store(&xas, NULL);
>
> 3. How dirty pages could be lockless searched
> sync_file_range
> ksys_sync_file_range
> __filemap_fdatawrite_range
> filemap_fdatawrite_wbc
Seems not a good example, IIUC, tmpfs doesn't support writeback
(mapping_can_writeback() will return false), right?
> do_writepages
> writeback_use_writepage
> writeback_iter
> writeback_get_folio
> filemap_get_folios_tag
> find_get_entry
> folio = xas_find_marked()
> folio_try_get(folio)
>
next prev parent reply other threads:[~2024-12-13 6:12 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-13 12:25 [PATCH v3 0/5] Fixes and cleanups to xarray Kemeng Shi
2024-12-13 12:25 ` [PATCH v3 1/5] Xarray: Do not return sibling entries from xas_find_marked() Kemeng Shi
2024-12-13 6:12 ` Baolin Wang [this message]
2024-12-16 7:05 ` Kemeng Shi
2024-12-16 14:04 ` Matthew Wilcox
2024-12-17 0:59 ` Kemeng Shi
2024-12-13 12:25 ` [PATCH v3 2/5] Xarray: move forward index correctly in xas_pause() Kemeng Shi
2024-12-13 12:25 ` [PATCH v3 3/5] Xarray: distinguish large entries correctly in xas_split_alloc() Kemeng Shi
2024-12-13 12:25 ` [PATCH v3 4/5] Xarray: remove repeat check in xas_squash_marks() Kemeng Shi
2024-12-13 12:25 ` [PATCH v3 5/5] Xarray: use xa_mark_t in xas_squash_marks() to keep code consistent Kemeng 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=1f8b523e-d68f-4382-8b1e-2475eb47ae81@linux.alibaba.com \
--to=baolin.wang@linux.alibaba.com \
--cc=akpm@linux-foundation.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shikemeng@huaweicloud.com \
--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