mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] erofs: fix incorrect symlink detection in fast symlink
@ 2024-09-09  2:28 Gao Xiang
  2024-09-09  2:37 ` Gao Xiang
  2024-09-09  3:19 ` [PATCH v2] " Gao Xiang
  0 siblings, 2 replies; 13+ messages in thread
From: Gao Xiang @ 2024-09-09  2:28 UTC (permalink / raw)
  To: linux-erofs; +Cc: LKML, Gao Xiang, Colin Walters

Fast symlink can be used if the on-disk symlink data is stored
in the same block as the on-disk inode, so we don’t need to trigger
another I/O for symlink data.  However, correctly fs correction could be
reported _incorrectly_ if inode xattrs are too large.

In fact, these should be valid images although they cannot be handled as
fast symlinks.

Many thanks to Colin for reporting this!

Reported-by: Colin Walters <walters@verbum.org>
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/inode.c | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 5f6439a63af7..79a29841ae1c 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -178,12 +178,13 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
 			      unsigned int m_pofs)
 {
 	struct erofs_inode *vi = EROFS_I(inode);
-	unsigned int bsz = i_blocksize(inode);
+	loff_t off;
 	char *lnk;
 
-	/* if it cannot be handled with fast symlink scheme */
-	if (vi->datalayout != EROFS_INODE_FLAT_INLINE ||
-	    inode->i_size >= bsz || inode->i_size < 0) {
+	/* check if it cannot be handled with fast symlink scheme */
+	if (vi->datalayout != EROFS_INODE_FLAT_INLINE || inode->i_size < 0 ||
+	    check_add_overflow(m_pofs + vi->xattr_isize, inode->i_size, &off) ||
+	    off > i_blocksize(inode)) {
 		inode->i_op = &erofs_symlink_iops;
 		return 0;
 	}
@@ -192,16 +193,6 @@ static int erofs_fill_symlink(struct inode *inode, void *kaddr,
 	if (!lnk)
 		return -ENOMEM;
 
-	m_pofs += vi->xattr_isize;
-	/* inline symlink data shouldn't cross block boundary */
-	if (m_pofs + inode->i_size > bsz) {
-		kfree(lnk);
-		erofs_err(inode->i_sb,
-			  "inline data cross block boundary @ nid %llu",
-			  vi->nid);
-		DBG_BUGON(1);
-		return -EFSCORRUPTED;
-	}
 	memcpy(lnk, kaddr + m_pofs, inode->i_size);
 	lnk[inode->i_size] = '\0';
 
-- 
2.43.5


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

end of thread, other threads:[~2024-09-11  2:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-09-09  2:28 [PATCH] erofs: fix incorrect symlink detection in fast symlink Gao Xiang
2024-09-09  2:37 ` Gao Xiang
2024-09-09  3:19 ` [PATCH v2] " Gao Xiang
2024-09-09 12:48   ` Colin Walters
2024-09-09 13:21     ` Gao Xiang
2024-09-09 13:58       ` Colin Walters
2024-09-09 14:14         ` Gao Xiang
2024-09-09 14:46           ` Colin Walters
2024-09-09 15:40             ` Gao Xiang
2024-09-10  0:12               ` Colin Walters
2024-09-10  2:18                 ` Gao Xiang
2024-09-10 20:51                   ` Colin Walters
2024-09-11  2:27                     ` Gao Xiang

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®