Skip to content

Commit 905eeb2

Browse files
ishitatsuyukihsiangkao
authored andcommitted
erofs: impersonate the opener's credentials when accessing backing file
Previously, file operations on a file-backed mount used the current process' credentials to access the backing FD. Attempting to do so on Android lead to SELinux denials, as ACL rules on the backing file (e.g. /system/apex/foo.apex) is restricted to a small set of process. Arguably, this error is redundant and leaking implementation details, as access to files on a mount is already ACL'ed by path. Instead, override to use the opener's cred when accessing the backing file. This makes the behavior similar to a loop-backed mount, which uses kworker cred when accessing the backing file and does not cause SELinux denials. Signed-off-by: Tatsuyuki Ishi <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Hongbo Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 19272b3 commit 905eeb2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/erofs/fileio.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static void erofs_fileio_ki_complete(struct kiocb *iocb, long ret)
4747

4848
static void erofs_fileio_rq_submit(struct erofs_fileio_rq *rq)
4949
{
50+
const struct cred *old_cred;
5051
struct iov_iter iter;
5152
int ret;
5253

@@ -60,7 +61,9 @@ static void erofs_fileio_rq_submit(struct erofs_fileio_rq *rq)
6061
rq->iocb.ki_flags = IOCB_DIRECT;
6162
iov_iter_bvec(&iter, ITER_DEST, rq->bvecs, rq->bio.bi_vcnt,
6263
rq->bio.bi_iter.bi_size);
64+
old_cred = override_creds(rq->iocb.ki_filp->f_cred);
6365
ret = vfs_iocb_iter_read(rq->iocb.ki_filp, &rq->iocb, &iter);
66+
revert_creds(old_cred);
6467
if (ret != -EIOCBQUEUED)
6568
erofs_fileio_ki_complete(&rq->iocb, ret);
6669
}

0 commit comments

Comments
 (0)