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=1796385609; b=0tdpAoxImkMMAZi1DQvjepVNVBq6fVWdWaBE8PROSkrOmRcl3e5I1hrD1h60IKhOjKlg +PCaZZw3hh99TELLHoGKD64E4OurcmO4BW9pF5Wkh+UBIulomH6Y4v8wjvoNhh0Jvx9yf vTOBShYU1vcudMo4M6Zf+izLHxxLzuwSedjfUZ4wEx34WD22CvDGodK6jGfkafc55fh0I blvAL6Z5vuqfoV0IHvqBHZTqcE8K0/zXJ3zo1D0tMvA5TgoGxbDcNI1T4hrTeRQBPsU+/ XL3nbEj5waDKzPNJ/o63myBCUk4CtlfnBllEHBG9PEJLHnHkC7Mylj8PJ0HSF1eE+tw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796385609; 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=ItVceLubrX5SYxFJurQiWCScSy71tuvz4H/6NdlGaKk=; b=IUzZS4yCJAbKrpSltuZb1GJUqDHeOngOCBZfTeQDcAE6RhEufk/J8IYW89dD8ZyrCMyh 7YSsERkJ3ofnZfBGJ3LgH8YQE9pmd/RqMZmR8qsJcbupc+96g41oV1efrg2MhvmXmKGfy cZMqtfSst1GQtQRjX6Y2xzBe/iRJRNtJcVDWOZmmPLDiklLLljyZ6OKPmMVtNWHbY1D+0 +gsgEIUjha0lhM4yjpSe73dnC8Of1uH6qpixybkoO74HW4z/TtEgJcXMXuik/TysiLFhL 9N8UJDnsJz94VkFsfn9A45n03bt9BUJvWy6JMbnZZQbmE9iTN0K23RcQIlVJiY+2PDw== 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=VGvXsUQ2; 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 89CD2606A32F; Fri, 4 Dec 2026 12:00:09 +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=VGvXsUQ2 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 029551F000CE; Fri, 4 Dec 2026 12:00:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796385609; bh=ItVceLubrX5SYxFJurQiWCScSy71tuvz4H/6NdlGaKk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VGvXsUQ2Go2605iunPPmghddq4qAUlY5ss25N+JpqVyRqt0+SJvVBiJYlEjk6M8QO BgPe6CQnS8kK871+0zi8qYQKjlq60WgVlWeiSLNos32euj3AxB0/2NIOAYe14EMjGC zlp4IxLNxrK0A4enMffhFCISiuitw8mdJwSTJnKY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sinan Polat , Mikulas Patocka Subject: [PATCH 6.6 0618/1167] dm-integrity: dont recalculate with HMAC because of a dirty bitmap Date: Fri, 4 Dec 2026 19:00:45 +0900 Message-ID: <20261204100718.166040234@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: Sinan Polat commit 875a7161fe1574205293c36f7bbd0815023e48a1 upstream. Commit 5c02406428d5 ("dm integrity: conditionally disable "recalculate" feature") refuses a superblock with SB_FLAG_RECALCULATING if a keyed hash is used without "legacy_recalculate". Otherwise someone who can write to the device, but does not know the key, could modify data and have the kernel compute valid tags for it. dm_integrity_resume() can still start the same recalculation in J or D mode: if SB_FLAG_DIRTY_BITMAP is set and the bitmap is not clear, or log2_blocks_per_bitmap_bit does not match, it sets SB_FLAG_RECALCULATING and recalc_sector = 0. The superblock is not authenticated unless fix_hmac and journal_mac are both used, so the flag can be set offline. Resume also runs on the first activation. Apply the constructor's policy there. If recalculation is not allowed, log an error and keep the existing tags, so modified blocks fail verification. This also avoids queueing recalc_work on a NULL recalc_wq when internal_hash is not used. Fixes: 5c02406428d5 ("dm integrity: conditionally disable "recalculate" feature") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Sinan Polat Signed-off-by: Mikulas Patocka Signed-off-by: Greg Kroah-Hartman --- drivers/md/dm-integrity.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) --- a/drivers/md/dm-integrity.c +++ b/drivers/md/dm-integrity.c @@ -3279,6 +3279,24 @@ static bool superblock_changed(struct dm memcmp(ic->sb->salt, ic->sb_copy->salt, SALT_SIZE) != 0; } +/* + * The superblock is authenticated only if fix_hmac and journal_mac are used, + * so SB_FLAG_DIRTY_BITMAP may have been set by someone who doesn't know the + * key. Apply the policy that the constructor applies to SB_FLAG_RECALCULATING. + */ +static bool dm_integrity_may_recalc_dirty_bitmap(struct dm_integrity_c *ic) +{ + if (!ic->internal_hash) { + DMERR("Dirty bitmap found, but internal_hash is not used"); + return false; + } + if (dm_integrity_disable_recalculate(ic)) { + DMERR("Dirty bitmap found, but HMAC recalculation requires \"legacy_recalculate\""); + return false; + } + return true; +} + static void dm_integrity_resume(struct dm_target *ti) { struct dm_integrity_c *ic = ti->private; @@ -3368,8 +3386,10 @@ static void dm_integrity_resume(struct d if (!(ic->sb->log2_blocks_per_bitmap_bit == ic->log2_blocks_per_bitmap_bit && block_bitmap_op(ic, ic->journal, 0, ic->provided_data_sectors, BITMAP_OP_TEST_ALL_CLEAR)) || ic->reset_recalculate_flag) { - ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); - ic->sb->recalc_sector = cpu_to_le64(0); + if (dm_integrity_may_recalc_dirty_bitmap(ic)) { + ic->sb->flags |= cpu_to_le32(SB_FLAG_RECALCULATING); + ic->sb->recalc_sector = cpu_to_le64(0); + } } init_journal(ic, 0, ic->journal_sections, 0); replay_journal(ic);