This is a note to let you know that I've just added the patch titled

    erofs: fix incorrect symlink detection in fast symlink

to the 6.1-stable tree which can be found at:
    
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     erofs-fix-incorrect-symlink-detection-in-fast-symlink.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <sta...@vger.kernel.org> know about it.


>From hsiang...@linux.alibaba.com Tue Oct  8 08:57:32 2024
From: Gao Xiang <hsiang...@linux.alibaba.com>
Date: Tue,  8 Oct 2024 14:57:08 +0800
Subject: erofs: fix incorrect symlink detection in fast symlink
To: sta...@vger.kernel.org, Greg Kroah-Hartman <gre...@linuxfoundation.org>
Cc: linux-erofs@lists.ozlabs.org, LKML <linux-ker...@vger.kernel.org>
Message-ID: <20241008065708.727659-5-hsiang...@linux.alibaba.com>

From: Gao Xiang <hsiang...@linux.alibaba.com>

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 <walt...@verbum.org>
Reported-by: https://honggfuzz.dev/
Link: 
https://lore.kernel.org/r/bb2dd430-7de0-47da-ae5b-82ab2dd4d...@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 <hsiang...@linux.alibaba.com>
Link: 
https://lore.kernel.org/r/20240909031911.1174718-1-hsiang...@linux.alibaba.com
Signed-off-by: Greg Kroah-Hartman <gre...@linuxfoundation.org>
---
 fs/erofs/inode.c |   20 ++++++--------------
 1 file changed, 6 insertions(+), 14 deletions(-)

--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -212,12 +212,14 @@ static int erofs_fill_symlink(struct ino
                              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) {
+       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;
        }
@@ -226,16 +228,6 @@ static int erofs_fill_symlink(struct ino
        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';
 


Patches currently in stable-queue which might be from 
hsiang...@linux.alibaba.com are

queue-6.1/erofs-set-block-size-to-the-on-disk-block-size.patch
queue-6.1/erofs-avoid-hardcoded-blocksize-for-subpage-block-support.patch
queue-6.1/erofs-fix-incorrect-symlink-detection-in-fast-symlink.patch
queue-6.1/erofs-get-rid-of-z_erofs_do_map_blocks-forward-declaration.patch
queue-6.1/erofs-get-rid-of-erofs_inode_datablocks.patch

Reply via email to