public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 5.15.y] erofs: fix incorrect symlink detection in fast symlink
@ 2024-12-18  7:34 Gao Xiang
  2024-12-18 12:34 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Gao Xiang @ 2024-12-18  7:34 UTC (permalink / raw)
  To: stable, gregkh; +Cc: allison.karlitskaya, linux-erofs, Gao Xiang, Colin Walters

commit 9ed50b8231e37b1ae863f5dec8153b98d9f389b4 upstream.

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, currently 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>
Reported-by: https://honggfuzz.dev/
Link: https://lore.kernel.org/r/bb2dd430-7de0-47da-ae5b-82ab2dd4d945@app.fastmail.com
Fixes: 431339ba9042 ("staging: erofs: add inode operations")
[ Note that it's a runtime misbehavior instead of a security issue. ]
Link: https://lore.kernel.org/r/20240909031911.1174718-1-hsiangkao@linux.alibaba.com
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
---
 fs/erofs/inode.c | 20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 638bb70d0d65..c68258ae70d3 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -219,11 +219,14 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
 			      unsigned int m_pofs)
 {
 	struct erofs_inode *vi = EROFS_I(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 >= PAGE_SIZE || inode->i_size < 0) {
+	m_pofs += vi->xattr_isize;
+	/* 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, inode->i_size, &off) ||
+	    off > i_blocksize(inode)) {
 		inode->i_op = &erofs_symlink_iops;
 		return 0;
 	}
@@ -232,17 +235,6 @@ static int erofs_fill_symlink(struct inode *inode, void *data,
 	if (!lnk)
 		return -ENOMEM;
 
-	m_pofs += vi->xattr_isize;
-	/* inline symlink data shouldn't cross page boundary as well */
-	if (m_pofs + inode->i_size > PAGE_SIZE) {
-		kfree(lnk);
-		erofs_err(inode->i_sb,
-			  "inline data cross block boundary @ nid %llu",
-			  vi->nid);
-		DBG_BUGON(1);
-		return -EFSCORRUPTED;
-	}
-
 	memcpy(lnk, data + m_pofs, inode->i_size);
 	lnk[inode->i_size] = '\0';
 
-- 
2.43.5


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

* Re: [PATCH 5.15.y] erofs: fix incorrect symlink detection in fast symlink
  2024-12-18  7:34 [PATCH 5.15.y] erofs: fix incorrect symlink detection in fast symlink Gao Xiang
@ 2024-12-18 12:34 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2024-12-18 12:34 UTC (permalink / raw)
  To: stable; +Cc: Gao Xiang, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

The upstream commit SHA1 provided is correct: 9ed50b8231e37b1ae863f5dec8153b98d9f389b4


Status in newer kernel trees:
6.12.y | Present (exact SHA1)
6.6.y | Present (different SHA1: 0c9b52bfee0e)
6.1.y | Present (different SHA1: ec134c1855c8)
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  9ed50b8231e3 ! 1:  80df2f17dee8 erofs: fix incorrect symlink detection in fast symlink
    @@ Metadata
      ## Commit message ##
         erofs: fix incorrect symlink detection in fast symlink
     
    +    commit 9ed50b8231e37b1ae863f5dec8153b98d9f389b4 upstream.
    +
         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, currently fs correction could be
    @@ Commit message
         Link: https://lore.kernel.org/r/bb2dd430-7de0-47da-ae5b-82ab2dd4d945@app.fastmail.com
         Fixes: 431339ba9042 ("staging: erofs: add inode operations")
         [ Note that it's a runtime misbehavior instead of a security issue. ]
    -    Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
         Link: https://lore.kernel.org/r/20240909031911.1174718-1-hsiangkao@linux.alibaba.com
    +    Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
     
      ## fs/erofs/inode.c ##
    -@@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *kaddr,
    +@@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *data,
      			      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) {
    +-	    inode->i_size >= PAGE_SIZE || inode->i_size < 0) {
     +	m_pofs += vi->xattr_isize;
     +	/* check if it cannot be handled with fast symlink scheme */
     +	if (vi->datalayout != EROFS_INODE_FLAT_INLINE || inode->i_size < 0 ||
    @@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *kaddr
      		inode->i_op = &erofs_symlink_iops;
      		return 0;
      	}
    -@@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *kaddr,
    +@@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *data,
      	if (!lnk)
      		return -ENOMEM;
      
     -	m_pofs += vi->xattr_isize;
    --	/* inline symlink data shouldn't cross block boundary */
    --	if (m_pofs + inode->i_size > bsz) {
    +-	/* inline symlink data shouldn't cross page boundary as well */
    +-	if (m_pofs + inode->i_size > PAGE_SIZE) {
     -		kfree(lnk);
     -		erofs_err(inode->i_sb,
     -			  "inline data cross block boundary @ nid %llu",
    @@ fs/erofs/inode.c: static int erofs_fill_symlink(struct inode *inode, void *kaddr
     -		DBG_BUGON(1);
     -		return -EFSCORRUPTED;
     -	}
    - 	memcpy(lnk, kaddr + m_pofs, inode->i_size);
    +-
    + 	memcpy(lnk, data + m_pofs, inode->i_size);
      	lnk[inode->i_size] = '\0';
      
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.15.y       |  Success    |  Success   |

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

end of thread, other threads:[~2024-12-18 12:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18  7:34 [PATCH 5.15.y] erofs: fix incorrect symlink detection in fast symlink Gao Xiang
2024-12-18 12:34 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox