From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796386079; b=QFndHtyx4fAJmvYBd6sPF4tnoAjWr5Yk9gXAvjVehqqyMc16cNHWdzkKuduK3OqbvsfZ I9WDBJiJv6Rhh8Lsdy6sKy/WyVJQbvKt2GAb/uNLrKkHlPZgY72AmkziVZYWHywYyubJW wBkZTMPI2/VeMbw5VycPngyAOgvDezclcqIbtYMZhkVat5lXtG88mQlxqqeWjynKR1S+W 68CKQ97YX8UHmk1M3ou9ZDpfSUO0d8n5LoIHzBsDIT6YyaGnvmc9py9wUkMODyLzPnOHt iTjEV+HomW7vk/SkfwRavsDKWKV3DzRB7g7wHxYUu/v44dwTO9sUH97sJln7y27V/Yg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796386079; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=DVX82TxHSQZmz4MstLjfJNpXBYfe/T48GR6AC861oJM=; b=jNI0B2yCaGEFSAQA7f+T4L5Amoli/SautilPK9yuSGsXF2h0HsJ4aQnVHmU2ln6cUq8L OypwoDl5TxO3cyDSoXpV0YmPPoTERqsnRMWfXU0ZO2/c33XWA2WM4qPOrhzZLf/0jrQXi t+foOtMcR21bKZQ1wJZQkcauHqq2m6wQSEBeElC1+K3gEEr98yyCoPQhqcuGRoXgYmnF9 HhW0cfxk1+bLCLilRLcU5xGHfHodW0Uhc5V1r8H+QvhhMroSd3/fcwb4QDRyS6ja/Zopi Nt/S7dD0jvJN9RnJvaLMv/KW8sRrM2NnNrazpsD/xSE8L/G6jCxlwPJzA+G8i7KpzVA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mS5u+Xya; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F13C606A322; Fri, 4 Dec 2026 12:07:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=mS5u+Xya Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19DE11F000C2; Fri, 4 Dec 2026 12:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796386079; bh=DVX82TxHSQZmz4MstLjfJNpXBYfe/T48GR6AC861oJM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=mS5u+XyaKxo9pCtzQmMFKJAt3zz3x2x9uj4+paodwJhPw90EL++HpZ9pEradBm7Ys eivFekJlsnf05HcJ/jGuacpkcY7Ri3eZLjwbPGTjTmU8W2pVUW3SzL2Bt5ubdzwBF9 G6mKpzBFGvTqN8dgcfcMkIXbXtMSSenXrArDJ5O4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+1288484b13bf6af3620d@syzkaller.appspotmail.com, wuyuehong , Mikulas Patocka , Sasha Levin Subject: [PATCH 6.6 0819/1167] dm snapshot: fix discard_granularity unit in snapshot_io_hints Date: Fri, 4 Dec 2026 19:04:06 +0900 Message-ID: <20261204100723.457250555@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: wuyuehong [ Upstream commit d7216d7be2bbfdf3312695b6e41a4fc7c5e22902 ] snapshot_io_hints() copies the snapshot store's chunk_size, which is in 512-byte sectors, into queue_limits.discard_granularity, which, like all other members of struct queue_limits, is in bytes. For snapshots with a chunk size smaller than 512 sectors, e.g. the 16 KiB (32-sector) chunks created by the syzkaller reproducer, the resulting granularity is smaller than a single sector. When dm_calculate_queue_limits() then stacks the target limits into the table limits: blk_stack_limits(limits, &ti_limits, 0) queue_limit_discard_alignment() truncates that granularity to zero sectors and sector_div() divides by zero: Oops: divide error: 0000 [#1] SMP KASAN NOPTI RIP: 0010:queue_limit_discard_alignment block/blk-settings.c:645 [inline] RIP: 0010:blk_stack_limits+0x1105/0x2d00 block/blk-settings.c:916 Call Trace: dm_calculate_queue_limits+0x70c/0x1510 drivers/md/dm-table.c:1823 dm_setup_md_queue+0x199/0x4f0 drivers/md/dm.c:2618 table_load+0x4fd/0x8a0 drivers/md/dm-ioctl.c:1661 The divide fault itself only became reachable when commit e924da7d6622 ("block: Drop granularity check in queue_limit_discard_alignment()") removed the check for a sub-sector granularity in v6.13. Kernels before that returned a zero discard alignment instead of faulting, but they still advertised a granularity 512 times too small. Use the same chunk_size << SECTOR_SHIFT conversion that io_overlaps_chunk() already applies to turn chunk_size into bytes. Fixes: 2e6023850e17 ("dm snapshot: add optional discard support features") Reported-by: syzbot+1288484b13bf6af3620d@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=1288484b13bf6af3620d Cc: stable@vger.kernel.org Signed-off-by: wuyuehong Signed-off-by: Mikulas Patocka [ sashal: adjusted context: kept the old max_discard_sectors line in place of upstream's max_hw_discard_sectors, since that rename is absent here; the discard_granularity change itself is identical. ] Signed-off-by: Sasha Levin --- drivers/md/dm-snap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c index b2a0460affa68..31bceeeeab857 100644 --- a/drivers/md/dm-snap.c +++ b/drivers/md/dm-snap.c @@ -2424,7 +2424,7 @@ static void snapshot_io_hints(struct dm_target *ti, struct queue_limits *limits) snap = snap_src; /* All discards are split on chunk_size boundary */ - limits->discard_granularity = snap->store->chunk_size; + limits->discard_granularity = snap->store->chunk_size << SECTOR_SHIFT; limits->max_discard_sectors = snap->store->chunk_size; up_read(&_origins_lock); -- 2.53.0