From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev,
"chenxiaosong (A)" <chenxiaosong2@huawei.com>,
Dan Carpenter <dan.carpenter@oracle.com>,
Hawkins Jiawei <yin31149@gmail.com>,
syzbot+5f8dcabe4a3b2c51c607@syzkaller.appspotmail.com,
Anton Altaparmakov <anton@tuxera.com>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 4.14 87/88] ntfs: fix out-of-bounds read in ntfs_attr_find()
Date: Wed, 23 Nov 2022 09:51:24 +0100 [thread overview]
Message-ID: <20221123084551.711543734@linuxfoundation.org> (raw)
In-Reply-To: <20221123084548.535439312@linuxfoundation.org>
From: Hawkins Jiawei <yin31149@gmail.com>
commit 36a4d82dddbbd421d2b8e79e1cab68c8126d5075 upstream.
Kernel iterates over ATTR_RECORDs in mft record in ntfs_attr_find(). To
ensure access on these ATTR_RECORDs are within bounds, kernel will do some
checking during iteration.
The problem is that during checking whether ATTR_RECORD's name is within
bounds, kernel will dereferences the ATTR_RECORD name_offset field, before
checking this ATTR_RECORD strcture is within bounds. This problem may
result out-of-bounds read in ntfs_attr_find(), reported by Syzkaller:
==================================================================
BUG: KASAN: use-after-free in ntfs_attr_find+0xc02/0xce0 fs/ntfs/attrib.c:597
Read of size 2 at addr ffff88807e352009 by task syz-executor153/3607
[...]
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0xcd/0x134 lib/dump_stack.c:106
print_address_description mm/kasan/report.c:317 [inline]
print_report.cold+0x2ba/0x719 mm/kasan/report.c:433
kasan_report+0xb1/0x1e0 mm/kasan/report.c:495
ntfs_attr_find+0xc02/0xce0 fs/ntfs/attrib.c:597
ntfs_attr_lookup+0x1056/0x2070 fs/ntfs/attrib.c:1193
ntfs_read_inode_mount+0x89a/0x2580 fs/ntfs/inode.c:1845
ntfs_fill_super+0x1799/0x9320 fs/ntfs/super.c:2854
mount_bdev+0x34d/0x410 fs/super.c:1400
legacy_get_tree+0x105/0x220 fs/fs_context.c:610
vfs_get_tree+0x89/0x2f0 fs/super.c:1530
do_new_mount fs/namespace.c:3040 [inline]
path_mount+0x1326/0x1e20 fs/namespace.c:3370
do_mount fs/namespace.c:3383 [inline]
__do_sys_mount fs/namespace.c:3591 [inline]
__se_sys_mount fs/namespace.c:3568 [inline]
__x64_sys_mount+0x27f/0x300 fs/namespace.c:3568
do_syscall_x64 arch/x86/entry/common.c:50 [inline]
do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
entry_SYSCALL_64_after_hwframe+0x63/0xcd
[...]
</TASK>
The buggy address belongs to the physical page:
page:ffffea0001f8d400 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x7e350
head:ffffea0001f8d400 order:3 compound_mapcount:0 compound_pincount:0
flags: 0xfff00000010200(slab|head|node=0|zone=1|lastcpupid=0x7ff)
raw: 00fff00000010200 0000000000000000 dead000000000122 ffff888011842140
raw: 0000000000000000 0000000000040004 00000001ffffffff 0000000000000000
page dumped because: kasan: bad access detected
Memory state around the buggy address:
ffff88807e351f00: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
ffff88807e351f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
>ffff88807e352000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
^
ffff88807e352080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
ffff88807e352100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================
This patch solves it by moving the ATTR_RECORD strcture's bounds checking
earlier, then checking whether ATTR_RECORD's name is within bounds.
What's more, this patch also add some comments to improve its
maintainability.
Link: https://lkml.kernel.org/r/20220831160935.3409-3-yin31149@gmail.com
Link: https://lore.kernel.org/all/1636796c-c85e-7f47-e96f-e074fee3c7d3@huawei.com/
Link: https://groups.google.com/g/syzkaller-bugs/c/t_XdeKPGTR4/m/LECAuIGcBgAJ
Signed-off-by: chenxiaosong (A) <chenxiaosong2@huawei.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Hawkins Jiawei <yin31149@gmail.com>
Reported-by: syzbot+5f8dcabe4a3b2c51c607@syzkaller.appspotmail.com
Tested-by: syzbot+5f8dcabe4a3b2c51c607@syzkaller.appspotmail.com
Cc: Anton Altaparmakov <anton@tuxera.com>
Cc: syzkaller-bugs <syzkaller-bugs@googlegroups.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/ntfs/attrib.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -608,11 +608,23 @@ static int ntfs_attr_find(const ATTR_TYP
for (;; a = (ATTR_RECORD*)((u8*)a + le32_to_cpu(a->length))) {
u8 *mrec_end = (u8 *)ctx->mrec +
le32_to_cpu(ctx->mrec->bytes_allocated);
- u8 *name_end = (u8 *)a + le16_to_cpu(a->name_offset) +
- a->name_length * sizeof(ntfschar);
- if ((u8*)a < (u8*)ctx->mrec || (u8*)a > mrec_end ||
- name_end > mrec_end)
+ u8 *name_end;
+
+ /* check whether ATTR_RECORD wrap */
+ if ((u8 *)a < (u8 *)ctx->mrec)
break;
+
+ /* check whether Attribute Record Header is within bounds */
+ if ((u8 *)a > mrec_end ||
+ (u8 *)a + sizeof(ATTR_RECORD) > mrec_end)
+ break;
+
+ /* check whether ATTR_RECORD's name is within bounds */
+ name_end = (u8 *)a + le16_to_cpu(a->name_offset) +
+ a->name_length * sizeof(ntfschar);
+ if (name_end > mrec_end)
+ break;
+
ctx->attr = a;
if (unlikely(le32_to_cpu(a->type) > le32_to_cpu(type) ||
a->type == AT_END))
next prev parent reply other threads:[~2022-11-23 9:03 UTC|newest]
Thread overview: 93+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-23 8:49 [PATCH 4.14 00/88] 4.14.300-rc1 review Greg Kroah-Hartman
2022-11-23 8:49 ` [PATCH 4.14 01/88] HID: hyperv: fix possible memory leak in mousevsc_probe() Greg Kroah-Hartman
2022-11-23 8:49 ` [PATCH 4.14 02/88] net: gso: fix panic on frag_list with mixed head alloc types Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 03/88] bnxt_en: fix potentially incorrect return value for ndo_rx_flow_steer Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 04/88] net: fman: Unregister ethernet device on removal Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 05/88] capabilities: fix undefined behavior in bit shift for CAP_TO_MASK Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 06/88] net: lapbether: fix issue of dev reference count leakage in lapbeth_device_event() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 07/88] hamradio: fix issue of dev reference count leakage in bpq_device_event() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 08/88] drm/vc4: Fix missing platform_unregister_drivers() call in vc4_drm_register() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 09/88] ipv6: addrlabel: fix infoleak when sending struct ifaddrlblmsg to network Greg Kroah-Hartman
2022-11-23 8:58 ` syzbot
2022-11-23 8:50 ` [PATCH 4.14 10/88] tipc: fix the msg->req tlv len check in tipc_nl_compat_name_table_dump_header Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 11/88] dmaengine: mv_xor_v2: Fix a resource leak in mv_xor_v2_remove() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 12/88] drivers: net: xgene: disable napi when register irq failed in xgene_enet_open() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 13/88] net: cxgb3_main: disable napi when bind qsets failed in cxgb_up() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 14/88] ethernet: s2io: disable napi when start nic failed in s2io_card_up() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 15/88] net: mv643xx_eth: disable napi when init rxq or txq failed in mv643xx_eth_open() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 16/88] net: macvlan: fix memory leaks of macvlan_common_newlink Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 17/88] arm64: efi: Fix handling of misaligned runtime regions and drop warning Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 18/88] ALSA: hda: fix potential memleak in add_widget_node Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 19/88] ALSA: usb-audio: Add quirk entry for M-Audio Micro Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 20/88] nilfs2: fix deadlock in nilfs_count_free_blocks() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 21/88] drm/i915/dmabuf: fix sg_table handling in map_dma_buf Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 22/88] platform/x86: hp_wmi: Fix rfkill causing soft blocked wifi Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 23/88] btrfs: selftests: fix wrong error check in btrfs_free_dummy_root() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 24/88] udf: Fix a slab-out-of-bounds write bug in udf_find_entry() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 25/88] cert host tools: Stop complaining about deprecated OpenSSL functions Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 26/88] dmaengine: at_hdmac: Fix at_lli struct definition Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 27/88] dmaengine: at_hdmac: Dont start transactions at tx_submit level Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 28/88] dmaengine: at_hdmac: Fix completion of unissued descriptor in case of errors Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 29/88] dmaengine: at_hdmac: Dont allow CPU to reorder channel enable Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 30/88] dmaengine: at_hdmac: Fix impossible condition Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 31/88] dmaengine: at_hdmac: Check return code of dma_async_device_register Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 32/88] x86/cpu: Restore AMDs DE_CFG MSR after resume Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 33/88] selftests/futex: fix build for clang Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 34/88] rtc: cmos: fix build on non-ACPI platforms Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 35/88] drm/imx: imx-tve: Fix return type of imx_tve_connector_mode_valid Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 36/88] Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 37/88] ASoC: core: Fix use-after-free in snd_soc_exit() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 38/88] serial: 8250_omap: remove wait loop from Errata i202 workaround Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 39/88] serial: 8250: omap: Flush PM QOS work on remove Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 40/88] tty: n_gsm: fix sleep-in-atomic-context bug in gsm_control_send Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 41/88] ASoC: soc-utils: Remove __exit for snd_soc_util_exit() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 42/88] block: sed-opal: kmalloc the cmd/resp buffers Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 43/88] parport_pc: Avoid FIFO port location truncation Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 44/88] pinctrl: devicetree: fix null pointer dereferencing in pinctrl_dt_to_map Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 45/88] net: bgmac: Drop free_netdev() from bgmac_enet_remove() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 46/88] mISDN: fix possible memory leak in mISDN_dsp_element_register() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 47/88] mISDN: fix misuse of put_device() in mISDN_register_device() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 48/88] net: caif: fix double disconnect client in chnl_net_open() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 49/88] xen/pcpu: fix possible memory leak in register_pcpu() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 50/88] drbd: use after free in drbd_create_device() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 51/88] net/x25: Fix skb leak in x25_lapb_receive_frame() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 52/88] cifs: Fix wrong return value checking when GETFLAGS Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 53/88] ftrace: Fix the possible incorrect kernel message Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 54/88] ftrace: Optimize the allocation for mcount entries Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 55/88] ftrace: Fix null pointer dereference in ftrace_add_mod() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 56/88] ring_buffer: Do not deactivate non-existant pages Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 57/88] ALSA: usb-audio: Drop snd_BUG_ON() from snd_usbmidi_output_open() Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 58/88] USB: serial: option: add Sierra Wireless EM9191 Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 59/88] USB: serial: option: remove old LARA-R6 PID Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 60/88] USB: serial: option: add u-blox LARA-R6 00B modem Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 61/88] USB: serial: option: add u-blox LARA-L6 modem Greg Kroah-Hartman
2022-11-23 8:50 ` [PATCH 4.14 62/88] USB: serial: option: add Fibocom FM160 0x0111 composition Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 63/88] usb: add NO_LPM quirk for Realforce 87U Keyboard Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 64/88] usb: chipidea: fix deadlock in ci_otg_del_timer Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 65/88] iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 66/88] iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init() Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 67/88] iio: pressure: ms5611: changed hardcoded SPI speed to value limited Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 68/88] dm ioctl: fix misbehavior if list_versions races with module loading Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 69/88] serial: 8250: Fall back to non-DMA Rx if IIR_RDI occurs Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 70/88] serial: 8250_lpss: Configure DMA also w/o DMA filter Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 71/88] mmc: core: properly select voltage range without power cycle Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 72/88] mmc: sdhci-pci: Fix possible memory leak caused by missing pci_dev_put() Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 73/88] misc/vmw_vmci: fix an infoleak in vmci_host_do_receive_datagram() Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 74/88] nilfs2: fix use-after-free bug of ns_writer on remount Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 75/88] serial: 8250: Flush DMA Rx on RLSI Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 76/88] macvlan: enforce a consistent minimal mtu Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 77/88] tcp: cdg: allow tcp_cdg_release() to be called multiple times Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 78/88] kcm: avoid potential race in kcm_tx_work Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 79/88] bpf, test_run: Fix alignment problem in bpf_prog_test_run_skb() Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 80/88] kcm: close race conditions on sk_receive_queue Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 81/88] 9p: trans_fd/p9_conn_cancel: drop client lock earlier Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 82/88] gfs2: Check sb_bsize_shift after reading superblock Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 83/88] gfs2: Switch from strlcpy to strscpy Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 84/88] 9p/trans_fd: always use O_NONBLOCK read/write Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 85/88] mm: fs: initialize fsdata passed to write_begin/write_end interface Greg Kroah-Hartman
2022-11-23 8:51 ` [PATCH 4.14 86/88] ntfs: fix use-after-free in ntfs_attr_find() Greg Kroah-Hartman
2022-11-23 8:51 ` Greg Kroah-Hartman [this message]
2022-11-23 8:51 ` [PATCH 4.14 88/88] ntfs: check overflow when iterating ATTR_RECORDs Greg Kroah-Hartman
2022-11-23 15:25 ` [PATCH 4.14 00/88] 4.14.300-rc1 review Jon Hunter
2022-11-24 2:35 ` Guenter Roeck
2022-11-24 12:47 ` Naresh Kamboju
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=20221123084551.711543734@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=anton@tuxera.com \
--cc=chenxiaosong2@huawei.com \
--cc=dan.carpenter@oracle.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=syzbot+5f8dcabe4a3b2c51c607@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=yin31149@gmail.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;
as well as URLs for NNTP newsgroup(s).