mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] erofs: verify metadata accesses for file-backed mounts
@ 2026-03-30  2:20 Gao Xiang
  2026-03-30  2:29 ` Gao Xiang
  2026-04-02  6:46 ` Chunhai Guo
  0 siblings, 2 replies; 3+ messages in thread
From: Gao Xiang @ 2026-03-30  2:20 UTC (permalink / raw)
  To: linux-erofs; +Cc: LKML, Jan Kara, Christian Brauner, Gao Xiang, Amir Goldstein

For file-backed mounts, metadata is fetched via the page cache of
backing inodes to avoid double caching and redundant copy ops, which is
currently used by Android APEXes, ComposeFS and containerd for example.
However, rw_verify_area() was missing prior to metadata accesses.

Similar to vfs_iocb_iter_read(), fix this by:
 - Enabling fanotify pre-content hooks on metadata accesses;
 - security_file_permission() for security modules.

Verified that fanotify pre-content hooks now works correctly.

Fixes: fb176750266a ("erofs: add file-backed mount support")
Acked-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/data.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index f79ee80627d9..cf27b8fbaaa1 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -30,6 +30,20 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
 {
 	pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
 	struct folio *folio = NULL;
+	loff_t fpos;
+	int err;
+
+	/*
+	 * Metadata access for file-backed mounts reuses page cache of backing
+	 * fs inodes only folio data will be needed) to prevent double caching.
+	 * However, the data access range must be verified here in advance.
+	 */
+	if (buf->file) {
+		fpos = index << PAGE_SHIFT;
+		err = rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE);
+		if (err)
+			return ERR_PTR(err);
+	}
 
 	if (buf->page) {
 		folio = page_folio(buf->page);
-- 
2.43.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] erofs: verify metadata accesses for file-backed mounts
  2026-03-30  2:20 [PATCH] erofs: verify metadata accesses for file-backed mounts Gao Xiang
@ 2026-03-30  2:29 ` Gao Xiang
  2026-04-02  6:46 ` Chunhai Guo
  1 sibling, 0 replies; 3+ messages in thread
From: Gao Xiang @ 2026-03-30  2:29 UTC (permalink / raw)
  To: linux-erofs
  Cc: LKML, Jan Kara, Christian Brauner, Yifan Zhao, Gao Xiang, Amir Goldstein

For file-backed mounts, metadata is fetched via the page cache of
backing inodes to avoid double caching and redundant copy ops just out
of RO uptodate folios, which is useful for Android APEXes, ComposeFS,
containerd and more for example.  However, rw_verify_area() was missing
prior to metadata accesses.

Similar to vfs_iocb_iter_read(), fix this by:
 - Enabling fanotify pre-content hooks on metadata accesses;
 - security_file_permission() for security modules.

Verified that fanotify pre-content hooks now works correctly.

Fixes: fb176750266a ("erofs: add file-backed mount support")
Acked-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
v2:
 - fix the code comment.

 fs/erofs/data.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index f79ee80627d9..687cf7e4ded0 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -30,6 +30,20 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
 {
 	pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
 	struct folio *folio = NULL;
+	loff_t fpos;
+	int err;
+
+	/*
+	 * Metadata access for file-backed mounts reuses page cache of backing
+	 * fs inodes (only folio data will be needed) to prevent double caching.
+	 * However, the data access range must be verified here in advance.
+	 */
+	if (buf->file) {
+		fpos = index << PAGE_SHIFT;
+		err = rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE);
+		if (err)
+			return ERR_PTR(err);
+	}
 
 	if (buf->page) {
 		folio = page_folio(buf->page);
-- 
2.43.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] erofs: verify metadata accesses for file-backed mounts
  2026-03-30  2:20 [PATCH] erofs: verify metadata accesses for file-backed mounts Gao Xiang
  2026-03-30  2:29 ` Gao Xiang
@ 2026-04-02  6:46 ` Chunhai Guo
  1 sibling, 0 replies; 3+ messages in thread
From: Chunhai Guo @ 2026-04-02  6:46 UTC (permalink / raw)
  To: Gao Xiang, linux-erofs; +Cc: LKML, Jan Kara, Christian Brauner, Amir Goldstein

On 3/30/2026 10:20 AM, Gao Xiang wrote:
> For file-backed mounts, metadata is fetched via the page cache of
> backing inodes to avoid double caching and redundant copy ops, which is
> currently used by Android APEXes, ComposeFS and containerd for example.
> However, rw_verify_area() was missing prior to metadata accesses.
>
> Similar to vfs_iocb_iter_read(), fix this by:
>   - Enabling fanotify pre-content hooks on metadata accesses;
>   - security_file_permission() for security modules.
>
> Verified that fanotify pre-content hooks now works correctly.
>
> Fixes: fb176750266a ("erofs: add file-backed mount support")
> Acked-by: Amir Goldstein <amir73il@gmail.com>
> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
> ---

Reviewed-by: Chunhai Guo <guochunhai@vivo.com>


Thanks,


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-02  6:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-03-30  2:20 [PATCH] erofs: verify metadata accesses for file-backed mounts Gao Xiang
2026-03-30  2:29 ` Gao Xiang
2026-04-02  6:46 ` Chunhai Guo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®