Skip to content

Commit ab84eee

Browse files
henryZeaalexandrovich
authored andcommitted
fs/ntfs3: Fix slab-out-of-bounds read in hdr_delete_de()
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: 82cae26 ("fs/ntfs3: Add initialization of super block") Reported-by: syzbot+9c2811fd56591639ff5f@syzkaller.appspotmail.com Signed-off-by: Zeng Heng <zengheng4@huawei.com> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 98bea25 commit ab84eee

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

fs/ntfs3/fslog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2575,7 +2575,7 @@ static int read_next_log_rec(struct ntfs_log *log, struct lcb *lcb, u64 *lsn)
25752575
return find_log_rec(log, *lsn, lcb);
25762576
}
25772577

2578-
static inline bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes)
2578+
bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes)
25792579
{
25802580
__le16 mask;
25812581
u32 min_de, de_off, used, total;

fs/ntfs3/index.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,10 @@ static inline struct NTFS_DE *hdr_delete_de(struct INDEX_HDR *hdr,
848848
u32 off = PtrOffset(hdr, re);
849849
int bytes = used - (off + esize);
850850

851+
/* check INDEX_HDR valid before using INDEX_HDR */
852+
if (!check_index_header(hdr, le32_to_cpu(hdr->total)))
853+
return NULL;
854+
851855
if (off >= used || esize < sizeof(struct NTFS_DE) ||
852856
bytes < sizeof(struct NTFS_DE))
853857
return NULL;

fs/ntfs3/ntfs_fs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni,
581581
bool ni_is_dirty(struct inode *inode);
582582

583583
/* Globals from fslog.c */
584+
bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes);
584585
int log_replay(struct ntfs_inode *ni, bool *initialized);
585586

586587
/* Globals from fsntfs.c */

0 commit comments

Comments
 (0)