Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp6888654rwl; Thu, 29 Dec 2022 23:29:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXu+xSISCMcm4/EA0IZbbmwjtS0dbS6+hf+e7/KsqJUwW2rBNAEeWvs5lIYMV2maxz/hCUz5 X-Received: by 2002:a17:906:cd1a:b0:801:d0bc:f616 with SMTP id oz26-20020a170906cd1a00b00801d0bcf616mr36609560ejb.62.1672385385933; Thu, 29 Dec 2022 23:29:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672385385; cv=none; d=google.com; s=arc-20160816; b=oXlwfBujV9I5Czbzp9cDgguZYhaksV2WpVwuDqpvNGTRhu3ItyLMrfwTw85mg4KnnW paV71+W0XQNgeIeYfh5E6kBhmXiYSUVBp47TLBFU10/kGDqGhsP2j/V2ROJfCBdpexvh IZKrtiQ8kZ+GHy7W6SOfIXzj6pPHxersBm50QMPzn4fnHwYhjYlyWNAdueBR3vG1zOMW 6CtB2dBRcu34ubXyXE+UJg3dfvml5lA4yuWCqhsw954Eh8i89JYWAuZUvwNdxdhvuLsD iVsadWsEni/aHyog7yJOhCT1TOEBSRW1EsXljoINT1iY9O+UrpJuUZX43L4MG/KJGcdV LVBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=Nc/tI0OEKN91jndqGsVsCKucExM7cJrY6OW6bUqxtNU=; b=rlBniJVjq2uQazF9KoZFj9/5xxYP20H3B81jFMtspMxvZuSaWUSp07X4iAnx3PFJVe LAcCGCVuu6sLgDm13B5TpbI6bsaKm4aVY5wIfl175QidXblo3EzAJh+rwLwW/tcIhhcQ tQHsg7JB4Dj7ZqRjBNzYx0Wpj52BAS727EdUIMVee0vD423+aTP4hhSLl9xaF+N2eaBD YoAviD9eP63ncDhgV2u3dlLzIqV2M/yP3wqBhEgiYIRMZE7s3i7NkaAmZRi4D3BPoOkl rrbbDv8WrTWGhTaf67Z9r1kG5de1okLIB2fgd6JqCndXPYDnBav1QVK5MnOggi6AfvEB ORag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=QD4YJCeL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hr25-20020a1709073f9900b0083fc624aedesi17403006ejc.231.2022.12.29.23.29.31; Thu, 29 Dec 2022 23:29: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; dkim=pass header.i=@paragon-software.com header.s=mail header.b=QD4YJCeL; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234572AbiL3HRa (ORCPT + 64 others); Fri, 30 Dec 2022 02:17:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234596AbiL3HRS (ORCPT ); Fri, 30 Dec 2022 02:17:18 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84ECD16585 for ; Thu, 29 Dec 2022 23:17:16 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 1E6D0439; Fri, 30 Dec 2022 07:13:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1672384422; bh=Nc/tI0OEKN91jndqGsVsCKucExM7cJrY6OW6bUqxtNU=; h=Date:Subject:To:CC:References:From:In-Reply-To; b=QD4YJCeLGtlfT5I4lQMzLy84Jfvc6IL9gwrLnab+VvqWbHosu/SiRDBmdn/IrkmlH B3mrHziIh7fX/GIrAjn5dXMtiyXDS4WXdrSXKhypg3wWteATYERlom71VA2m5KcWNr f/ltdxvdxUPoHU3j15XEcp5uYQYCNX4sN9MGyhrU= Received: from [192.168.211.146] (192.168.211.146) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Fri, 30 Dec 2022 10:17:14 +0300 Message-ID: Date: Fri, 30 Dec 2022 11:17:13 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH] fs/ntfs3: Fix slab-out-of-bounds read in hdr_delete_de() Content-Language: en-US To: Zeng Heng CC: , , , References: <20221212013134.2133231-1-zengheng4@huawei.com> From: Konstantin Komarov In-Reply-To: <20221212013134.2133231-1-zengheng4@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [192.168.211.146] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,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 On 12.12.2022 05:31, Zeng Heng wrote: > 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 */ Thanks for patch, applied!