From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A041D5448A8 for ; Tue, 8 Sep 2026 13:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788874004; cv=none; b=P9HF9rzR11I3Q5JVHKJ0GLkZ7EXJdv0ZuAaD4/YL43LZQMMNKhk+EJtWfqNObz8GBnSADAddQkfIpx0JHWHuV925K8MppHwAR6s2mrDVjJr34KCGVjVFuzX5tPxHA0bMLb+4NiiSFOiRg452ExK6r8C6jRKgvVp475qWSUn1U30= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788874004; c=relaxed/simple; bh=GlT1F6AnEeOtxYba1bH7mWMfB7x1Du/8fEsuy97PXxc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nODB+Sg0Cm565w1WIEsp/MASJjFqmreMw6H9p1xIx/waiPl9DAtiM3z/SCJoEt7vyyt+gNznfBQVEhmOAyuL5mWZbv+pgeKgOJVKtNkakiY1g3MwLfSAUgckDJ0KheM6SOBPd6uqhgSjWCgE8yc8WJ2QWylNtAMvQZVFu7AxP2o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=amODu+1O; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="amODu+1O" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7DD3C1F00A3D; Tue, 8 Sep 2026 13:26:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1788873990; bh=pcR7REBbouoXGiBC3T3w+NZkQLkOUOW7Lowfln4Y48Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=amODu+1OjY1eAQY2VGEy2U4y9ldxtueV6ufqJavax6/N1vq/W8TVE0cq7FYyqA4Nm tankYekZmMnI/uxS84QW5KRsr8QmCiUr8r2+OVJw19mgbLsSrUNMi2wIkhl+k4rTqE tk+OFm6xYrxiDqGn7+OmhUjAYEI+RDUdYJuyFdMFY+4YbNCqzCIBxIPzm5jVZgVsXL muXh9BoqkVTxyiFe3+1ia/G2kFrE2G0404dkIYTLB3cBDjYKWPzojdko1tAYWT5bdf HeE6P/pG5ZjncdR5AfIQUPmBLnhsco9jMyuY5WuKKhrqx1TexzG6GD3l1Q3iZMYZ94 LtqYrgDeg40Vw== From: Sasha Levin To: stable@vger.kernel.org Cc: Bryam Vargas , Ming-Hung Tsai , Mikulas Patocka , Sasha Levin Subject: [PATCH 5.10.y] dm array: validate array block headers on read Date: Tue, 8 Sep 2026 09:26:27 -0400 Message-ID: <20260908132627.2302699-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026090304-edging-moonrise-e655@gregkh> References: <2026090304-edging-moonrise-e655@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Bryam Vargas [ Upstream commit 2965787723084835b18dfe993cd450ebf5bd4540 ] array_block_check() validates blocknr and csum and nothing else, while node_check(), next to it, has bounded the structural fields since both were written. dm_array_cursor_next() takes its loop bound from the on-disk nr_entries and element_at() is unguarded pointer arithmetic, so a count larger than the block holds keeps the cursor in one block while the index grows past it and the read walks off the dm-bufio buffer -- dm_cache_load_mappings() drives it once per cache block at activation. Check the header against itself: reject a zero value_size, require max_entries to equal calc_max_entries() for that value_size and block size, and require nr_entries to fit. Equality rather than an upper bound, since a count below the real capacity trips BUG_ON() in fill_ablock() and trim_ablock(). Metadata dm-array writes satisfies all three. Fixes: 6513c29f44f2 ("dm persistent data: add transactional array") Suggested-by: Ming-Hung Tsai Cc: stable@vger.kernel.org Signed-off-by: Bryam Vargas Reviewed-by: Ming-Hung Tsai Signed-off-by: Mikulas Patocka [ retained Linux 6.6’s non-const validator callback signature due to the missing constification commit. ] Signed-off-by: Sasha Levin --- drivers/md/persistent-data/dm-array.c | 37 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/drivers/md/persistent-data/dm-array.c b/drivers/md/persistent-data/dm-array.c index 4d434d89eadde..e0cb991c8a635 100644 --- a/drivers/md/persistent-data/dm-array.c +++ b/drivers/md/persistent-data/dm-array.c @@ -37,6 +37,14 @@ struct array_block { */ #define CSUM_XOR 595846735 +/* + * Each array block can hold this many values. + */ +static uint32_t calc_max_entries(size_t value_size, size_t size_of_block) +{ + return (size_of_block - sizeof(struct array_block)) / value_size; +} + static void array_block_prepare_for_write(struct dm_block_validator *v, struct dm_block *b, size_t size_of_block) @@ -54,6 +62,7 @@ static int array_block_check(struct dm_block_validator *v, size_t size_of_block) { struct array_block *bh_le = dm_block_data(b); + uint32_t nr_entries, max_entries, value_size; __le32 csum_disk; if (dm_block_location(b) != le64_to_cpu(bh_le->blocknr)) { @@ -73,6 +82,26 @@ static int array_block_check(struct dm_block_validator *v, return -EILSEQ; } + nr_entries = le32_to_cpu(bh_le->nr_entries); + max_entries = le32_to_cpu(bh_le->max_entries); + value_size = le32_to_cpu(bh_le->value_size); + + if (!value_size) { + DMERR_LIMIT("%s failed: value_size is zero", __func__); + return -EILSEQ; + } + + if (max_entries != calc_max_entries(value_size, size_of_block)) { + DMERR_LIMIT("%s failed: max_entries %u invalid for value_size %u", + __func__, max_entries, value_size); + return -EILSEQ; + } + + if (nr_entries > max_entries) { + DMERR_LIMIT("%s failed: too many entries", __func__); + return -EILSEQ; + } + return 0; } @@ -138,14 +167,6 @@ static void dec_ablock_entries(struct dm_array_info *info, struct array_block *a on_entries(info, ab, vt->dec); } -/* - * Each array block can hold this many values. - */ -static uint32_t calc_max_entries(size_t value_size, size_t size_of_block) -{ - return (size_of_block - sizeof(struct array_block)) / value_size; -} - /* * Allocate a new array block. The caller will need to unlock block. */ -- 2.53.0