From nobody Thu Feb 12 01:45:57 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1493C7EE21 for ; Sun, 30 Apr 2023 12:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229632AbjD3MOe (ORCPT ); Sun, 30 Apr 2023 08:14:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231702AbjD3MOC (ORCPT ); Sun, 30 Apr 2023 08:14:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65ACA3AA5; Sun, 30 Apr 2023 05:13:42 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D227B61326; Sun, 30 Apr 2023 12:13:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DF3F3C433D2; Sun, 30 Apr 2023 12:13:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1682856821; bh=aFs3qgdrR15h+SxW8RuFS3808pVzsn0pZquaSH7HA8o=; h=From:To:Cc:Subject:Date:From; b=nGFu1ZEsjON82A3mw6bL+ubWHtjno7kUEh9AU8heMpxKDpYNlhh1Q5yqPLOIN7JRf SeGuQGvNwn5/shtsDsQqn5xD+YNOrYkHdd3mXVs6rp3j6+PJY1h/REGK6uG4ITFMZg QKElVIa9gK/zOUw1Kij2fulLZ2+9OpoF2AUJqN+V9fhzGUa2GA1frn3E7HUB8mvH6j NlwXo8baCm1IIMKOAdtiGwIcfKoCDrrynBbaD95hccIfa1YBCYlDb4isywPaYhj/Ow zNLMcsM5yOFGy0/hVMqAc/UsPGNmPtF4hJzoKtA4EDpWwpWJ5uBLMH1RuJexpHeRz5 kOlah1Pi2ZfHw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Tetsuo Handa , syzbot , syzbot , Viacheslav Dubeyko , Christian Brauner , Sasha Levin , willy@infradead.org, dchinner@redhat.com, akpm@linux-foundation.org, jlayton@kernel.org, gargaditya08@live.com, linux-fsdevel@vger.kernel.org Subject: [PATCH AUTOSEL 5.4] fs: hfsplus: remove WARN_ON() from hfsplus_cat_{read,write}_inode() Date: Sun, 30 Apr 2023 08:13:36 -0400 Message-Id: <20230430121338.3197865-1-sashal@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Tetsuo Handa [ Upstream commit 81b21c0f0138ff5a499eafc3eb0578ad2a99622c ] syzbot is hitting WARN_ON() in hfsplus_cat_{read,write}_inode(), for crafted filesystem image can contain bogus length. There conditions are not kernel bugs that can justify kernel to panic. Reported-by: syzbot Link: https://syzkaller.appspot.com/bug?extid=3De2787430e752a92b8750 Reported-by: syzbot Link: https://syzkaller.appspot.com/bug?extid=3D4913dca2ea6e4d43f3f1 Signed-off-by: Tetsuo Handa Reviewed-by: Viacheslav Dubeyko Message-Id: <15308173-5252-d6a3-ae3b-e96d46cb6f41@I-love.SAKURA.ne.jp> Signed-off-by: Christian Brauner Signed-off-by: Sasha Levin --- fs/hfsplus/inode.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/fs/hfsplus/inode.c b/fs/hfsplus/inode.c index 76501d905099b..15c14a6a9f7fe 100644 --- a/fs/hfsplus/inode.c +++ b/fs/hfsplus/inode.c @@ -497,7 +497,11 @@ int hfsplus_cat_read_inode(struct inode *inode, struct= hfs_find_data *fd) if (type =3D=3D HFSPLUS_FOLDER) { struct hfsplus_cat_folder *folder =3D &entry.folder; =20 - WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_folder)); + if (fd->entrylength < sizeof(struct hfsplus_cat_folder)) { + pr_err("bad catalog folder entry\n"); + res =3D -EIO; + goto out; + } hfs_bnode_read(fd->bnode, &entry, fd->entryoffset, sizeof(struct hfsplus_cat_folder)); hfsplus_get_perms(inode, &folder->permissions, 1); @@ -517,7 +521,11 @@ int hfsplus_cat_read_inode(struct inode *inode, struct= hfs_find_data *fd) } else if (type =3D=3D HFSPLUS_FILE) { struct hfsplus_cat_file *file =3D &entry.file; =20 - WARN_ON(fd->entrylength < sizeof(struct hfsplus_cat_file)); + if (fd->entrylength < sizeof(struct hfsplus_cat_file)) { + pr_err("bad catalog file entry\n"); + res =3D -EIO; + goto out; + } hfs_bnode_read(fd->bnode, &entry, fd->entryoffset, sizeof(struct hfsplus_cat_file)); =20 @@ -548,6 +556,7 @@ int hfsplus_cat_read_inode(struct inode *inode, struct = hfs_find_data *fd) pr_err("bad catalog entry used to create inode\n"); res =3D -EIO; } +out: return res; } =20 @@ -556,6 +565,7 @@ int hfsplus_cat_write_inode(struct inode *inode) struct inode *main_inode =3D inode; struct hfs_find_data fd; hfsplus_cat_entry entry; + int res =3D 0; =20 if (HFSPLUS_IS_RSRC(inode)) main_inode =3D HFSPLUS_I(inode)->rsrc_inode; @@ -574,7 +584,11 @@ int hfsplus_cat_write_inode(struct inode *inode) if (S_ISDIR(main_inode->i_mode)) { struct hfsplus_cat_folder *folder =3D &entry.folder; =20 - WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_folder)); + if (fd.entrylength < sizeof(struct hfsplus_cat_folder)) { + pr_err("bad catalog folder entry\n"); + res =3D -EIO; + goto out; + } hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, sizeof(struct hfsplus_cat_folder)); /* simple node checks? */ @@ -599,7 +613,11 @@ int hfsplus_cat_write_inode(struct inode *inode) } else { struct hfsplus_cat_file *file =3D &entry.file; =20 - WARN_ON(fd.entrylength < sizeof(struct hfsplus_cat_file)); + if (fd.entrylength < sizeof(struct hfsplus_cat_file)) { + pr_err("bad catalog file entry\n"); + res =3D -EIO; + goto out; + } hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, sizeof(struct hfsplus_cat_file)); hfsplus_inode_write_fork(inode, &file->data_fork); @@ -620,5 +638,5 @@ int hfsplus_cat_write_inode(struct inode *inode) set_bit(HFSPLUS_I_CAT_DIRTY, &HFSPLUS_I(inode)->flags); out: hfs_find_exit(&fd); - return 0; + return res; } --=20 2.39.2