From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
patches@lists.linux.dev, Ming-Hung Tsai <mtsai@redhat.com>,
Mikulas Patocka <mpatocka@redhat.com>,
Joe Thornber <thornber@redhat.com>
Subject: [PATCH 4.19 21/52] dm cache: fix out-of-bounds access to the dirty bitset when resizing
Date: Fri, 15 Nov 2024 07:37:34 +0100 [thread overview]
Message-ID: <20241115063723.621903114@linuxfoundation.org> (raw)
In-Reply-To: <20241115063722.845867306@linuxfoundation.org>
4.19-stable review patch. If anyone has any objections, please let me know.
------------------
From: Ming-Hung Tsai <mtsai@redhat.com>
commit 792227719725497ce10a8039803bec13f89f8910 upstream.
dm-cache checks the dirty bits of the cache blocks to be dropped when
shrinking the fast device, but an index bug in bitset iteration causes
out-of-bounds access.
Reproduce steps:
1. create a cache device of 1024 cache blocks (128 bytes dirty bitset)
dmsetup create cmeta --table "0 8192 linear /dev/sdc 0"
dmsetup create cdata --table "0 131072 linear /dev/sdc 8192"
dmsetup create corig --table "0 524288 linear /dev/sdc 262144"
dd if=/dev/zero of=/dev/mapper/cmeta bs=4k count=1 oflag=direct
dmsetup create cache --table "0 524288 cache /dev/mapper/cmeta \
/dev/mapper/cdata /dev/mapper/corig 128 2 metadata2 writethrough smq 0"
2. shrink the fast device to 512 cache blocks, triggering out-of-bounds
access to the dirty bitset (offset 0x80)
dmsetup suspend cache
dmsetup reload cdata --table "0 65536 linear /dev/sdc 8192"
dmsetup resume cdata
dmsetup resume cache
KASAN reports:
BUG: KASAN: vmalloc-out-of-bounds in cache_preresume+0x269/0x7b0
Read of size 8 at addr ffffc900000f3080 by task dmsetup/131
(...snip...)
The buggy address belongs to the virtual mapping at
[ffffc900000f3000, ffffc900000f5000) created by:
cache_ctr+0x176a/0x35f0
(...snip...)
Memory state around the buggy address:
ffffc900000f2f80: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
ffffc900000f3000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
>ffffc900000f3080: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
^
ffffc900000f3100: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
ffffc900000f3180: f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8 f8
Fix by making the index post-incremented.
Signed-off-by: Ming-Hung Tsai <mtsai@redhat.com>
Fixes: f494a9c6b1b6 ("dm cache: cache shrinking support")
Cc: stable@vger.kernel.org
Signed-off-by: Mikulas Patocka <mpatocka@redhat.com>
Acked-by: Joe Thornber <thornber@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/md/dm-cache-target.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -3002,13 +3002,13 @@ static bool can_resize(struct cache *cac
* We can't drop a dirty block when shrinking the cache.
*/
while (from_cblock(new_size) < from_cblock(cache->cache_size)) {
- new_size = to_cblock(from_cblock(new_size) + 1);
if (is_dirty(cache, new_size)) {
DMERR("%s: unable to shrink cache; cache block %llu is dirty",
cache_device_name(cache),
(unsigned long long) from_cblock(new_size));
return false;
}
+ new_size = to_cblock(from_cblock(new_size) + 1);
}
return true;
next prev parent reply other threads:[~2024-11-15 6:40 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-15 6:37 [PATCH 4.19 00/52] 4.19.324-rc1 review Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 01/52] arm64: dts: rockchip: Fix rt5651 compatible value on rk3399-sapphire-excavator Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 02/52] ARM: dts: rockchip: fix rk3036 acodec node Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 03/52] ARM: dts: rockchip: drop grf reference from rk3036 hdmi Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 04/52] ARM: dts: rockchip: Fix the realtek audio codec on rk3036-kylin Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 05/52] HID: core: zero-initialize the report buffer Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 06/52] security/keys: fix slab-out-of-bounds in key_task_permission Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 07/52] sctp: properly validate chunk size in sctp_sf_ootb() Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 08/52] can: c_can: fix {rx,tx}_errors statistics Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 09/52] net: hns3: fix kernel crash when uninstalling driver Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 10/52] media: stb0899_algo: initialize cfr before using it Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 11/52] media: dvbdev: prevent the risk of out of memory access Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 12/52] media: dvb_frontend: dont play tricks with underflow values Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 13/52] media: adv7604: prevent underflow condition when reporting colorspace Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 14/52] ALSA: firewire-lib: fix return value on fail in amdtp_tscm_init() Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 15/52] media: s5p-jpeg: prevent buffer overflows Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 16/52] media: cx24116: prevent overflows on SNR calculus Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 17/52] media: v4l2-tpg: prevent the risk of a division by zero Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 18/52] drm/amdgpu: add missing size check in amdgpu_debugfs_gprwave_read() Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 19/52] drm/amdgpu: prevent NULL pointer dereference if ATIF is not supported Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 20/52] dm cache: correct the number of origin blocks to match the target length Greg Kroah-Hartman
2024-11-15 6:37 ` Greg Kroah-Hartman [this message]
2024-11-15 6:37 ` [PATCH 4.19 22/52] dm cache: optimize dirty bit checking with find_next_bit when resizing Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 23/52] dm cache: fix potential out-of-bounds access on the first resume Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 24/52] dm-unstriped: cast an operand to sector_t to prevent potential uint32_t overflow Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 25/52] nfs: Fix KMSAN warning in decode_getfattr_attrs() Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 26/52] btrfs: reinitialize delayed ref list after deleting it from the list Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 27/52] bonding (gcc13): synchronize bond_{a,t}lb_xmit() types Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 28/52] net: bridge: xmit: make sure we have at least eth header len bytes Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 29/52] media: uvcvideo: Skip parsing frames of type UVC_VS_UNDEFINED in uvc_parse_format Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 30/52] fs/proc: fix compile warning about variable vmcore_mmap_ops Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 31/52] usb: musb: sunxi: Fix accessing an released usb phy Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 32/52] USB: serial: io_edgeport: fix use after free in debug printk Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 33/52] USB: serial: qcserial: add support for Sierra Wireless EM86xx Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 34/52] USB: serial: option: add Fibocom FG132 0x0112 composition Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 35/52] USB: serial: option: add Quectel RG650V Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 36/52] irqchip/gic-v3: Force propagation of the active state with a read-back Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 37/52] ocfs2: remove entry once instead of null-ptr-dereference in ocfs2_xa_remove() Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 38/52] ALSA: pcm: Return 0 when size < start_threshold in capture Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 39/52] ALSA: usb-audio: Add custom mixer status quirks for RME CC devices Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 40/52] ALSA: usb-audio: Support jack detection on Dell dock Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 41/52] ALSA: usb-audio: Add quirks for Dell WD19 dock Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 42/52] hv_sock: Initializing vsk->trans to NULL to prevent a dangling pointer Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 43/52] vsock/virtio: Initialization of the dangling pointer occurring in vsk->trans Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 44/52] ALSA: usb-audio: Add endianness annotations Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 45/52] 9p: Avoid creating multiple slab caches with the same name Greg Kroah-Hartman
2024-11-15 6:37 ` [PATCH 4.19 46/52] HID: multitouch: Add quirk for HONOR MagicBook Art 14 touchpad Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 47/52] bpf: use kvzmalloc to allocate BPF verifier environment Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 48/52] sound: Make CONFIG_SND depend on INDIRECT_IOMEM instead of UML Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 49/52] powerpc/powernv: Free name on error in opal_event_init() Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 50/52] fs: Fix uninitialized value issue in from_kuid and from_kgid Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 51/52] net: usb: qmi_wwan: add Fibocom FG132 0x0112 composition Greg Kroah-Hartman
2024-11-15 6:38 ` [PATCH 4.19 52/52] 9p: fix slab cache name creation for real Greg Kroah-Hartman
2024-11-15 16:00 ` [PATCH 4.19 00/52] 4.19.324-rc1 review Harshit Mogalapalli
2024-11-15 17:55 ` Jon Hunter
2024-11-16 12:54 ` Naresh Kamboju
2024-11-16 21:18 ` Shuah Khan
2024-11-17 13:25 ` Pavel Machek
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=20241115063723.621903114@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=mpatocka@redhat.com \
--cc=mtsai@redhat.com \
--cc=patches@lists.linux.dev \
--cc=stable@vger.kernel.org \
--cc=thornber@redhat.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