Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1944953rwb; Tue, 29 Nov 2022 23:23:57 -0800 (PST) X-Google-Smtp-Source: AA0mqf6HUBioeD/fdP9h6BqQEztyZqTs3FzDiNlfFRdQuabRO73jfihWa6Gh5iAizh0UYPKwhNmf X-Received: by 2002:a05:6402:1f03:b0:468:7be6:55e7 with SMTP id b3-20020a0564021f0300b004687be655e7mr54673148edb.345.1669793037052; Tue, 29 Nov 2022 23:23:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669793037; cv=none; d=google.com; s=arc-20160816; b=qesQnotWkcTHx7xXdmmgtv9SLQOoCannExCJ51qzakF7RXIrM73S7s2l1k7Y34R1iX kQKY/qxhi8xMcNoiMFeeTgy9uefXOiWz+lJfHHS2twtP46RwFh9pPBck/uT8MwjGMxyr Qn/xd1W5Y9PPXuq5CcNuNVaHHOu8V6cuP/GR5cAuUGzHpWPpi97KkVMmArLhnFr4aFWq XExG9yYRhAwkNa1a29kd040qjTpDi5mnhOXY2eX5KfDuWms9JbLvzXE9XYLErMc87mc9 hCywLn/3KLJLpN2ISnxYkKVRr5hfqWVGFLU7RFqJ9zZjv1n6V+tci0t8MU4BgJSjD5jd j0gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=IupoQ1X7tw/FPyu3goUBMjZTD+cQMn1qHel39UbxxJQ=; b=FkMuhpv5qqni5oYaF/2fLqqN87zQfPN4ZhvBxVEJd4C/BZ2y+Z1/dU30bO+ENzrMol HP7zVjxFouUQRYKIJg0XkF1Bv9MLkMOkaWI/3TEyOoj8bXXclvxHS5qLZiQ4gB17itkD W+DYWzcE/6hjdy0yaR/LVZ7DhhdBplRnED90xyXFjfnsBCr8qIZl1m/WJ8NH0JNmN/i2 nEbMIqCqAY1GDwEjjmp897PYw+938fDQYeMIuRm2tDTZTp6F3ZtuAwpThlN4JP2ivN2e 0mVQ0hlW/x38ZxF+GBiGcw/Ynx/UmZdnRyuaDovyHjaYH8aGoN8qNu45UBWOCll2z5HE NTJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cy14-20020a0564021c8e00b00458e689f41fsi652159edb.415.2022.11.29.23.23.35; Tue, 29 Nov 2022 23:23:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233368AbiK3HAS (ORCPT + 85 others); Wed, 30 Nov 2022 02:00:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiK3HAQ (ORCPT ); Wed, 30 Nov 2022 02:00:16 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2E581F2D8; Tue, 29 Nov 2022 23:00:14 -0800 (PST) Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NMVSM3YNKzmWHf; Wed, 30 Nov 2022 14:59:31 +0800 (CST) Received: from kwepemm600020.china.huawei.com (7.193.23.147) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 30 Nov 2022 15:00:11 +0800 Received: from localhost.localdomain (10.175.112.125) by kwepemm600020.china.huawei.com (7.193.23.147) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 30 Nov 2022 15:00:10 +0800 From: Peng Zhang To: , , , , , CC: , , , , ZhangPeng , Subject: [PATCH] hfs: Fix OOB Read in __hfs_brec_find Date: Wed, 30 Nov 2022 06:59:59 +0000 Message-ID: <20221130065959.2168236-1-zhangpeng362@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600020.china.huawei.com (7.193.23.147) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: ZhangPeng Syzbot reported a OOB read bug: ================================================================== BUG: KASAN: slab-out-of-bounds in hfs_strcmp+0x117/0x190 fs/hfs/string.c:84 Read of size 1 at addr ffff88807eb62c4e by task kworker/u4:1/11 CPU: 1 PID: 11 Comm: kworker/u4:1 Not tainted 6.1.0-rc6-syzkaller-00308-g644e9524388a #0 Workqueue: writeback wb_workfn (flush-7:0) Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106 print_address_description+0x74/0x340 mm/kasan/report.c:284 print_report+0x107/0x1f0 mm/kasan/report.c:395 kasan_report+0xcd/0x100 mm/kasan/report.c:495 hfs_strcmp+0x117/0x190 fs/hfs/string.c:84 __hfs_brec_find+0x213/0x5c0 fs/hfs/bfind.c:75 hfs_brec_find+0x276/0x520 fs/hfs/bfind.c:138 hfs_write_inode+0x34c/0xb40 fs/hfs/inode.c:462 write_inode fs/fs-writeback.c:1440 [inline] If the input inode of hfs_write_inode() is incorrect: struct inode struct hfs_inode_info struct hfs_cat_key struct hfs_name u8 len # len is greater than HFS_NAMELEN(31) which is the maximum length of an HFS filename OOB read occurred: hfs_write_inode() hfs_brec_find() __hfs_brec_find() hfs_cat_keycmp() hfs_strcmp() # OOB read occurred due to len is too large Fix this by adding a Check on len in hfs_write_inode() before calling hfs_brec_find(). Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Reported-by: syzbot+e836ff7133ac02be825f@syzkaller.appspotmail.com Signed-off-by: ZhangPeng --- fs/hfs/inode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/hfs/inode.c b/fs/hfs/inode.c index c4526f16355d..a0746be3c1de 100644 --- a/fs/hfs/inode.c +++ b/fs/hfs/inode.c @@ -458,6 +458,8 @@ int hfs_write_inode(struct inode *inode, struct writeback_control *wbc) /* panic? */ return -EIO; + if (HFS_I(main_inode)->cat_key.CName.len > HFS_NAMELEN) + return -EIO; fd.search_key->cat = HFS_I(main_inode)->cat_key; if (hfs_brec_find(&fd)) /* panic? */ -- 2.25.1