From: Gao Xiang <hsiangkao@linux.alibaba.com>
To: linux-erofs@lists.ozalbs.org
Cc: LKML <linux-kernel@vger.kernel.org>,
Gao Xiang <hsiangkao@linux.alibaba.com>,
Carlos Llamas <cmllamas@google.com>,
Sandeep Dhavale <dhavale@google.com>,
Tatsuyuki Ishi <ishitatsuyuki@google.com>
Subject: [PATCH v2] erofs: use the opener's credential when verifying metadata accesses
Date: Thu, 7 May 2026 12:28:45 +0800 [thread overview]
Message-ID: <20260507042845.1318782-1-hsiangkao@linux.alibaba.com> (raw)
In-Reply-To: <20260505155615.2719500-1-hsiangkao@linux.alibaba.com>
Similar to commit 905eeb2b7c33 ("erofs: impersonate the opener's
credentials when accessing backing file"), rw_verify_area() needs
the same too.
Fixes: 307210c262a2 ("erofs: verify metadata accesses for file-backed mounts")
Cc: Carlos Llamas <cmllamas@google.com>
Cc: Sandeep Dhavale <dhavale@google.com>
Cc: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
v2:
- apply sashiko's suggestion
https://sashiko.dev/#/patchset/20260505155615.2719500-1-hsiangkao%40linux.alibaba.com
fs/erofs/data.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index 44da21c9d777..d6f6035fd714 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -29,6 +29,7 @@ void erofs_put_metabuf(struct erofs_buf *buf)
void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
{
pgoff_t index = (buf->off + offset) >> PAGE_SHIFT;
+ const struct cred *old_cred = NULL;
struct folio *folio = NULL;
loff_t fpos;
int err;
@@ -40,9 +41,12 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
*/
if (buf->file) {
fpos = (loff_t)index << PAGE_SHIFT;
+ old_cred = override_creds(buf->file->f_cred);
err = rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE);
- if (err < 0)
+ if (err < 0) {
+ revert_creds(old_cred);
return ERR_PTR(err);
+ }
}
if (buf->page) {
@@ -53,6 +57,8 @@ void *erofs_bread(struct erofs_buf *buf, erofs_off_t offset, bool need_kmap)
if (!folio || !folio_contains(folio, index)) {
erofs_put_metabuf(buf);
folio = read_mapping_folio(buf->mapping, index, buf->file);
+ if (old_cred)
+ revert_creds(old_cred);
if (IS_ERR(folio))
return folio;
}
--
2.43.5
next prev parent reply other threads:[~2026-05-07 4:28 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-05 15:56 [PATCH] erofs: use the opener's credential when verifing metadata accesses Gao Xiang
2026-05-05 20:15 ` Carlos Llamas
2026-05-07 4:28 ` Gao Xiang [this message]
2026-05-08 8:20 ` Christoph Hellwig
2026-05-08 8:25 ` Tatsuyuki Ishi
[not found] ` <CABqzrSOaCMPD_QrSq_y_6bXLC3ecm3FZsE_ACrdNbTHG8baMCw@mail.gmail.com>
2026-05-08 8:39 ` Gao Xiang
2026-05-08 8:51 ` Christoph Hellwig
2026-05-08 9:10 ` Gao Xiang
2026-05-11 6:18 ` Christoph Hellwig
2026-05-11 6:52 ` Gao Xiang
2026-05-11 13:51 ` Christian Brauner
2026-05-11 14:42 ` Gao Xiang
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=20260507042845.1318782-1-hsiangkao@linux.alibaba.com \
--to=hsiangkao@linux.alibaba.com \
--cc=cmllamas@google.com \
--cc=dhavale@google.com \
--cc=ishitatsuyuki@google.com \
--cc=linux-erofs@lists.ozalbs.org \
--cc=linux-kernel@vger.kernel.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