From nobody Thu Apr 2 07:43:46 2026 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDD6039183F for ; Mon, 30 Mar 2026 02:29:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.99 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774837781; cv=none; b=HizHQtph/k9ryDr+Kz7KwRjLH1xEoSb5VVbRoqQvkxBhrdSgJnr9WQD5TxHQPqIqVF+Q6Fph4gwQXKgeVoKLgC4qNWIKgFxA7kx0RdRsczoKkkcNz0PvJMY1JjChKTxzndF38ev9zFjc1PlR0oWzbePPLKfVai3MTCVSA8Rn0EI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774837781; c=relaxed/simple; bh=VTJ3uDaErC2OaXVRins96jDw0tSYZ5LKSLkQtWWowMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jUONPKyNa1yF+1hY1EoQ4/6AgSTV4fMq+cuhIwCj0Emr3yxjxhIaExbvXBFtSD9bhGgX9yMSG58IOAGE3nn8/cGryjusk/0OTsZ6x5i96HZmNgryhQTK88jfbr9Jzg2ptY8P5VTSR8oBfccPhgNYGVcN9/V3Q9+yrek73A04R+I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=ZbZrvlpH; arc=none smtp.client-ip=115.124.30.99 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="ZbZrvlpH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1774837771; h=From:To:Subject:Date:Message-ID:MIME-Version; bh=eM3VHdhgVCPvtEOZPzd8s7fdzrhoiHKP5ui9y0tHke0=; b=ZbZrvlpHbTS5pFeV1gYhuaRD8kTfcxNgUR6QFbUO0QP4NnpvKr2wXTRsSarWaUl96wY3J7JxPOK+66aKGPluUaAj0o48xMaKfJD01FOV9gP/nRF7fJ69Ysi1X3Hsgd3XH6Fc7AutUV7gygdZpsLbvWikOahBzjva9nvtz0ZHUgQ= X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R241e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045098064;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0X.tyjed_1774837770; Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0X.tyjed_1774837770 cluster:ay36) by smtp.aliyun-inc.com; Mon, 30 Mar 2026 10:29:30 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Jan Kara , Christian Brauner , Yifan Zhao , Gao Xiang , Amir Goldstein Subject: [PATCH] erofs: verify metadata accesses for file-backed mounts Date: Mon, 30 Mar 2026 10:29:29 +0800 Message-ID: <20260330022929.2119716-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20260330022031.2107239-1-hsiangkao@linux.alibaba.com> References: <20260330022031.2107239-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Gao Xiang --- 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 off= set, bool need_kmap) { pgoff_t index =3D (buf->off + offset) >> PAGE_SHIFT; struct folio *folio =3D 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 =3D index << PAGE_SHIFT; + err =3D rw_verify_area(READ, buf->file, &fpos, PAGE_SIZE); + if (err) + return ERR_PTR(err); + } =20 if (buf->page) { folio =3D page_folio(buf->page); --=20 2.43.5