From nobody Tue Feb 10 08:26:42 2026 Received: from dggsgout12.his.huawei.com (dggsgout12.his.huawei.com [45.249.212.56]) (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 A721D192B63 for ; Mon, 20 Jan 2025 08:18:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737361088; cv=none; b=cIcBoYsILkczoa9yNu6jZAayffEss1CPHdpMl+ndVnP2gflLZTV0Wk3xRoMN/YBgKpdWw+WutklMNvbSgQH9CsZ2Bz3Hhv7qct3k9ruPAOV0XSrsh7QfRyLR3L6YBWnVj6gcZbCumtiwkeGpa74PvbhWo84+55zxYywBdlWPRCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737361088; c=relaxed/simple; bh=Wb2icUldOX7Ghxcgm9Fn2vG8SIk7awgY/BOr/Ir2pCQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dE14VCUyg8osRAwfkxx5ZzRhy7/ha5YoYPAOh5vfE4mOy++IbUOG5If0bc6sRahUS+8EdsXnPQXk5bJnDDFllDeJ84sdMb8x/oUJVbuFHm8jIMXMKPdRjRhmNg1r6gWLf2OhGPyBJGwvfwOFiMEn7aGn67IgB3b/Jm+wHNXE/R0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4Yc39Y5dDJz4f3jY1 for ; Mon, 20 Jan 2025 16:17:37 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 56C0D1A0F78 for ; Mon, 20 Jan 2025 16:17:58 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.124.27]) by APP4 (Coremail) with SMTP id gCh0CgB321+kBo5n8sHjBQ--.22840S10; Mon, 20 Jan 2025 16:17:58 +0800 (CST) From: Hou Tao To: dm-devel@lists.linux.dev Cc: linux-kernel@vger.kernel.org, Alasdair Kergon , Mike Snitzer , Mikulas Patocka , Ignat Korchagin , houtao1@huawei.com Subject: [PATCH 6/6] dm-crypt: track tag_offset in convert_context Date: Mon, 20 Jan 2025 16:29:51 +0800 Message-Id: <20250120082951.1423804-7-houtao@huaweicloud.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20250120082951.1423804-1-houtao@huaweicloud.com> References: <20250120082951.1423804-1-houtao@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: gCh0CgB321+kBo5n8sHjBQ--.22840S10 X-Coremail-Antispam: 1UD129KBjvJXoWxur18GFyfGw18WF1fur18uFg_yoW5Zr4UpF Z8Ca1ayrZ5Jw1Y9a9rtFykCFyrt3s7GFy5Jr43Jwn8KryvvrykXay7A34jvF1UZFZakr13 XanYyFy3uwnrZa7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUB0b4IE77IF4wAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k2 6cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAV Cq3wA2048vs2IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0 rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x0267 AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E 14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7 xfMcIj6xIIjxv20xvE14v26r106r15McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Y z7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41lc7CjxVAaw2AFwI0_JF0_Jw1l42xK82IYc2Ij64 vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8G jcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2I x0cI8IcVAFwI0_JFI_Gr1lIxAIcVC0I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK 8VAvwI8IcIk0rVWUJVWUCwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I 0E14v26r4j6r4UJbIYCTnIWIevJa73UjIFyTuYvjxUrfOzUUUUU X-CM-SenderInfo: xkrx3t3r6k3tpzhluzxrxghudrp/ Content-Type: text/plain; charset="utf-8" From: Hou Tao dm-crypt uses tag_offset to index the integrity metadata for each crypt sector. When the initial crypt_convert() returns BLK_STS_DEV_RESOURCE, dm-crypt will try to continue the crypt/decrypt procedure in a kworker. However, it resets tag_offset as zero instead of using the tag_offset related with current sector. It may return unexpected data when using random IV or return unexpected integrity related error. Fix the problem by tracking tag_offset in per-IO convert_context. Therefore, when the crypt/decrypt procedure continues in a kworker, it could use the next tag_offset saved in convert_context. Fixes: 8abec36d1274 ("dm crypt: do not wait for backlogged crypto request c= ompletion in softirq") Signed-off-by: Hou Tao --- drivers/md/dm-crypt.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c index 8b15f57af36a9..f6973fd2925b3 100644 --- a/drivers/md/dm-crypt.c +++ b/drivers/md/dm-crypt.c @@ -59,6 +59,7 @@ struct convert_context { struct bio *bio_out; struct bvec_iter iter_out; atomic_t cc_pending; + unsigned int tag_offset; u64 cc_sector; union { struct skcipher_request *req; @@ -1256,6 +1257,7 @@ static void crypt_convert_init(struct crypt_config *c= c, if (bio_out) ctx->iter_out =3D bio_out->bi_iter; ctx->cc_sector =3D sector + cc->iv_offset; + ctx->tag_offset =3D 0; init_completion(&ctx->restart); } =20 @@ -1588,7 +1590,6 @@ static void crypt_free_req(struct crypt_config *cc, v= oid *req, struct bio *base_ static blk_status_t crypt_convert(struct crypt_config *cc, struct convert_context *ctx, bool atomic, bool reset_pending) { - unsigned int tag_offset =3D 0; unsigned int sector_step =3D cc->sector_size >> SECTOR_SHIFT; int r; =20 @@ -1611,9 +1612,9 @@ static blk_status_t crypt_convert(struct crypt_config= *cc, atomic_inc(&ctx->cc_pending); =20 if (crypt_integrity_aead(cc)) - r =3D crypt_convert_block_aead(cc, ctx, ctx->r.req_aead, tag_offset); + r =3D crypt_convert_block_aead(cc, ctx, ctx->r.req_aead, ctx->tag_offse= t); else - r =3D crypt_convert_block_skcipher(cc, ctx, ctx->r.req, tag_offset); + r =3D crypt_convert_block_skcipher(cc, ctx, ctx->r.req, ctx->tag_offset= ); =20 switch (r) { /* @@ -1633,8 +1634,8 @@ static blk_status_t crypt_convert(struct crypt_config= *cc, * exit and continue processing in a workqueue */ ctx->r.req =3D NULL; + ctx->tag_offset++; ctx->cc_sector +=3D sector_step; - tag_offset++; return BLK_STS_DEV_RESOURCE; } } else { @@ -1648,8 +1649,8 @@ static blk_status_t crypt_convert(struct crypt_config= *cc, */ case -EINPROGRESS: ctx->r.req =3D NULL; + ctx->tag_offset++; ctx->cc_sector +=3D sector_step; - tag_offset++; continue; /* * The request was already processed (synchronously). @@ -1657,7 +1658,7 @@ static blk_status_t crypt_convert(struct crypt_config= *cc, case 0: atomic_dec(&ctx->cc_pending); ctx->cc_sector +=3D sector_step; - tag_offset++; + ctx->tag_offset++; if (!atomic) cond_resched(); continue; --=20 2.29.2