]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
squashfs: verify inode mode when loading from disk
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Wed, 13 Aug 2025 07:17:43 +0000 (16:17 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 14 Sep 2025 00:32:46 +0000 (17:32 -0700)
The inode mode loaded from corrupted disk might by error contain the file
type bits.  Since the file type bits are set by squashfs_read_inode()
using bitwise OR, the file type bits must not be set by
squashfs_new_inode() from squashfs_read_inode(); otherwise, an invalid
file type bits later confuses may_open().

Link: https://lkml.kernel.org/r/f63d8d11-2254-4fc3-9292-9a43a93b374e@I-love.SAKURA.ne.jp
Reported-by: syzbot <syzbot+895c23f6917da440ed0d@syzkaller.appspotmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=895c23f6917da440ed0d
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Reviewed-by: Phillip Lougher <phillip@squashfs.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
fs/squashfs/inode.c

index d5918eba27e3711f62d7b4b8a1d7972f22ac6ca5..dee8fa01693077606c8444325b0aface4f635d72 100644 (file)
@@ -68,6 +68,10 @@ static int squashfs_new_inode(struct super_block *sb, struct inode *inode,
        inode->i_mode = le16_to_cpu(sqsh_ino->mode);
        inode->i_size = 0;
 
+       /* File type must not be set at this moment, for it will later be set by the caller. */
+       if (inode->i_mode & S_IFMT)
+               err = -EIO;
+
        return err;
 }