Skip to content

Commit 307210c

Browse files
committed
erofs: verify metadata accesses for file-backed mounts
For file-backed mounts, metadata is fetched via the page cache of backing inodes to avoid double caching and redundant copy ops out of RO uptodate folios, which is used by Android APEXes, ComposeFS, containerd. 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: fb17675 ("erofs: add file-backed mount support") Acked-by: Amir Goldstein <amir73il@gmail.com> Reviewed-by: Chunhai Guo <guochunhai@vivo.com> Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
1 parent 6a01f54 commit 307210c

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

fs/erofs/data.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,20 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
3030
{
3131
pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
3232
struct folio *folio = NULL;
33+
loff_t fpos;
34+
int err;
35+
36+
/*
37+
* Metadata access for file-backed mounts reuses page cache of backing
38+
* fs inodes (only folio data will be needed) to prevent double caching.
39+
* However, the data access range must be verified here in advance.
40+
*/
41+
if (buf->file) {
42+
fpos = index << PAGE_SHIFT;
43+
err = rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE);
44+
if (err < 0)
45+
return ERR_PTR(err);
46+
}
3347

3448
if (buf->page) {
3549
folio = page_folio(buf->page);

0 commit comments

Comments
 (0)