From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: Zeng Heng <zengheng4@huawei.com>
Cc: <linux-kernel@vger.kernel.org>, <ntfs3@lists.linux.dev>,
<xiexiuqi@huawei.com>, <liwei391@huawei.com>
Subject: Re: [PATCH] fs/ntfs3: Fix slab-out-of-bounds read in hdr_delete_de()
Date: Fri, 30 Dec 2022 11:17:13 +0400 [thread overview]
Message-ID: <db403920-d3ef-8fc6-959f-46edd314a989@paragon-software.com> (raw)
In-Reply-To: <20221212013134.2133231-1-zengheng4@huawei.com>
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 <zengheng4@huawei.com>
> ---
> 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!
prev parent reply other threads:[~2022-12-30 7:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-12 1:31 Zeng Heng
2022-12-30 7:17 ` Konstantin Komarov [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=db403920-d3ef-8fc6-959f-46edd314a989@paragon-software.com \
--to=almaz.alexandrovich@paragon-software.com \
--cc=linux-kernel@vger.kernel.org \
--cc=liwei391@huawei.com \
--cc=ntfs3@lists.linux.dev \
--cc=xiexiuqi@huawei.com \
--cc=zengheng4@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®