From patchwork Mon Dec 12 01:31:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zeng Heng X-Patchwork-Id: 32227 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1994021wrr; Sun, 11 Dec 2022 17:41:45 -0800 (PST) X-Google-Smtp-Source: AA0mqf7na4w/N90sA81wW2qi3N/a2ecToSGBAdjLTHQgU5XLpXwh8LdJLVksKyKfii+jWKVsDII1 X-Received: by 2002:a05:6a20:5484:b0:aa:3c1:50d with SMTP id i4-20020a056a20548400b000aa03c1050dmr23724610pzk.42.1670809305406; Sun, 11 Dec 2022 17:41:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670809305; cv=none; d=google.com; s=arc-20160816; b=E4UcELbZnl+lHG+esHYMm11fKcfLGQ9Zj/klRyy1lEahSXx0WA/H0bjRl1IgZ/S0tP uejYhhmICgh34vTbVsSAY0/1ak7hi1XmBtMQmSjmYetqpA/UyMyAN1x6ED7nBKUe2zN+ 6z1M5o7nNwMFzpLF/um8CdRnzYlcFNC2xWti07vidVOVBEw9VGrXlhwsN6SNuKYwpkSK YDeUQ3mwPqPnW0E/I2XAt2Y/F5uaZwap+Oe3jNUKMGNoDiz021dGwFBgN99tmJ5y7HNs r3H/8AmXLmW24UhtMhCRoP8V7VoSlFmn33BVykriuEkUU3bnmWgs5gdjmwCoZoymFM5G Rvww== 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=1ee3G8rVEcxPxxiuyKhApQhLuDFO5RY5dzASKiK/Q1E=; b=BLKt3Fz3lvXYLj8Go8d9O1A4Pb6RZlEy17HPU+fjUOd3AJ03PTQJnLZCnJNJsluZrq juDq5oTmlrRnTyvz7qCuWmvhPh6sPNM/SchDsYzyfg8gq/v74Qaf7sXBU43M0PubmXlF gpcimeBjSGK9qS7vNma7pe+5eGKXiSNYyvT2nuxlnfI4r57dszPV/TqlPlniNNa8S4KO 1dop37kwn//Jk/6CP8dtkdO5MG+u1V8VkwsaEZVxSH5axW6gi9DiWvOhxuLJL1s85qi9 ZQIOHc0amZweF2OqxK7HXsEtdrIHQO55QR6IG+WjQsnfx6FH/xsecP82IyeHcDuQm1Y1 oLpw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n24-20020a63a518000000b0047854cf6b6csi8952851pgf.513.2022.12.11.17.41.32; Sun, 11 Dec 2022 17:41:45 -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 S230442AbiLLBeP (ORCPT + 99 others); Sun, 11 Dec 2022 20:34:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229475AbiLLBeN (ORCPT ); Sun, 11 Dec 2022 20:34:13 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC124B1EB for ; Sun, 11 Dec 2022 17:34:11 -0800 (PST) Received: from kwepemi500024.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NVkfJ2Bq8zRpx0; Mon, 12 Dec 2022 09:33:12 +0800 (CST) Received: from huawei.com (10.175.103.91) by kwepemi500024.china.huawei.com (7.221.188.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Mon, 12 Dec 2022 09:34:09 +0800 From: Zeng Heng To: CC: , , , Subject: [PATCH] fs/ntfs3: Fix slab-out-of-bounds read in hdr_delete_de() Date: Mon, 12 Dec 2022 09:31:34 +0800 Message-ID: <20221212013134.2133231-1-zengheng4@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.103.91] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemi500024.china.huawei.com (7.221.188.100) 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751970538141767622?= X-GMAIL-MSGID: =?utf-8?q?1751970538141767622?= Here is a BUG report from syzbot: BUG: KASAN: slab-out-of-bounds in hdr_delete_de+0xe0/0x150 fs/ntfs3/index.c:806 Read of size 16842960 at addr ffff888079cc0600 by task syz-executor934/3631 Call Trace: memmove+0x25/0x60 mm/kasan/shadow.c:54 hdr_delete_de+0xe0/0x150 fs/ntfs3/index.c:806 indx_delete_entry+0x74f/0x3670 fs/ntfs3/index.c:2193 ni_remove_name+0x27a/0x980 fs/ntfs3/frecord.c:2910 ntfs_unlink_inode+0x3d4/0x720 fs/ntfs3/inode.c:1712 ntfs_rename+0x41a/0xcb0 fs/ntfs3/namei.c:276 Before using the meta-data in struct INDEX_HDR, we need to check index header valid or not. Otherwise, the corruptedi (or malicious) fs image can cause out-of-bounds access which could make kernel panic. Fixes: 82cae269cfa9 ("fs/ntfs3: Add initialization of super block") Reported-by: syzbot+9c2811fd56591639ff5f@syzkaller.appspotmail.com Signed-off-by: Zeng Heng --- fs/ntfs3/fslog.c | 2 +- fs/ntfs3/index.c | 4 ++++ fs/ntfs3/ntfs_fs.h | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index 0d611a6c5511..0de2bbb42721 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -2597,7 +2597,7 @@ static int read_next_log_rec(struct ntfs_log *log, struct lcb *lcb, u64 *lsn) return find_log_rec(log, *lsn, lcb); } -static inline bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes) +bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes) { __le16 mask; u32 min_de, de_off, used, total; diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 440328147e7e..6f5d8dd6659d 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -798,6 +798,10 @@ static inline struct NTFS_DE *hdr_delete_de(struct INDEX_HDR *hdr, u32 off = PtrOffset(hdr, re); int bytes = used - (off + esize); + /* check INDEX_HDR valid before using INDEX_HDR */ + if (!check_index_header(hdr, le32_to_cpu(hdr->total))) + return NULL; + if (off >= used || esize < sizeof(struct NTFS_DE) || bytes < sizeof(struct NTFS_DE)) return NULL; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 2c791222c4e2..c5c022fef4e0 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -574,6 +574,7 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni, bool ni_is_dirty(struct inode *inode); /* Globals from fslog.c */ +bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes); int log_replay(struct ntfs_inode *ni, bool *initialized); /* Globals from fsntfs.c */