From: Matthew Wilcox <willy@infradead.org>
To: Pedro Falcato <pfalcato@suse.de>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-mm@kvack.org, linux-hardening@vger.kernel.org,
Kees Cook <kees@kernel.org>, Mateusz Guzik <mjguzik@gmail.com>
Subject: Re: [RFC PATCH] fs/splice: allow for a way to block splice() with read-only files
Date: Sun, 17 May 2026 00:07:05 +0100 [thread overview]
Message-ID: <agj4mXKRVW44ZJ18@casper.infradead.org> (raw)
In-Reply-To: <20260516182126.530498-1-pfalcato@suse.de>
On Sat, May 16, 2026 at 07:21:26PM +0100, Pedro Falcato wrote:
> +static bool may_write_to_page(struct page *page, struct address_space **plast)
> +{
> + struct folio *folio = page_folio(page);
> + struct address_space *mapping, *last = *plast;
> + struct inode *inode;
> + bool may = false;
> +
> + if (!READ_ONCE(sysctl_splice_needs_write))
> + return true;
> + /*
> + * Always fine to write to anon folios.
> + */
> + if (folio_test_anon(folio))
> + return true;
What about KSM? It's not something we've seen attacked yet, but it'd be
pretty nasty to be able to change a KSM page in another process.
I just got off a flight, so hopefully I'm semicoherent.
> + mapping = READ_ONCE(folio->mapping);
> + WARN_ON((unsigned long) mapping & FOLIO_MAPPING_FLAGS);
> +
> + /* If it is the same (locklessly), then LGTM, proceed. */
> + if (mapping == last)
> + return true;
> + /*
> + * Else we have to recheck with the folio lock held, for mapping
> + * stability. TODO: killable?
I wouldn't've thought that'd be necessary. The folio can't be being
read because it's mapped, and we won't map a folio until it's uptodate.
> + */
> + folio_lock(folio);
> + mapping = folio_mapping(folio);
I think you're safe to just look at folio->mapping here. You have a
refcount on the folio so it can't be freed, and I'm not sure there's a
way to transition from page cache folio to anon folio without taking a
trip through the page allocator.
> + /* May have been truncated, etc */
> + if (!mapping)
> + goto out_lock;
typically we call this "out_unlock".
> + inode = mapping->host;
> + may = inode_owner_or_capable(&nop_mnt_idmap, inode) ||
> + inode_permission(&nop_mnt_idmap, inode, MAY_WRITE) == 0;
> + if (likely(may))
> + *plast = mapping;
> +out_lock:
> + folio_unlock(folio);
> + return may;
> +}
I don't have a problem with the idea, other than it's really sad we have
to do this.
next prev parent reply other threads:[~2026-05-16 23:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-16 18:21 [RFC PATCH] fs/splice: allow for a way to block splice() with read-only files Pedro Falcato
2026-05-16 23:07 ` Matthew Wilcox [this message]
2026-05-17 0:59 ` Pedro Falcato
2026-05-17 1:17 ` Matthew Wilcox
2026-05-17 9:01 ` Pedro Falcato
2026-05-17 22:30 ` Matthew Wilcox
2026-05-16 23:51 ` Mateusz Guzik
2026-05-17 0:52 ` Pedro Falcato
2026-05-18 11:44 ` Christian Brauner
2026-05-18 12:20 ` Christian Brauner
2026-05-18 13:02 ` Pedro Falcato
2026-05-18 18:59 ` Jann Horn
2026-05-19 6:39 ` Christoph Hellwig
2026-05-19 9:49 ` Christian Brauner
2026-05-19 10:51 ` Mateusz Guzik
2026-05-19 10:59 ` Christian Brauner
2026-05-19 11:56 ` Mateusz Guzik
2026-05-22 13:11 ` Christian Brauner
2026-05-28 12:59 ` Pedro Falcato
2026-05-19 13:28 ` James Bottomley
2026-05-19 16:28 ` Jann Horn
2026-05-23 20:41 ` Askar Safin
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=agj4mXKRVW44ZJ18@casper.infradead.org \
--to=willy@infradead.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=kees@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mjguzik@gmail.com \
--cc=pfalcato@suse.de \
--cc=viro@zeniv.linux.org.uk \
/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