From nobody Wed Nov 27 00:44:07 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1703482300; cv=none; d=zohomail.com; s=zohoarc; b=TSTBq481ogCqXNu3/8oEVfYvbiddLf+K3BU7IZQmRc7iEqkR/8yRKwWRToCJT+BcJR4DHUJpDo1b3l4RzAQkWljlIfEm9ZadbcbUuCaTA4C0f/8x51iYcJ7T1/is8x4Nhi+MPgoWC/vqTfWpvWGzsyxhlXfOlHr+mQDtkfSjPZE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703482300; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=IPxH7gFNnh+/q7MXVJgutLRfldlr/zL58xbkQj7lR5Y=; b=A8Zijwsdddn0sLsYhUeaVcmAqL43wUsz/CiePMC8BK7BrOCIyZSl0PqMdza/hhtywZCqoAbDO557sggVcoclDiu2il5fIYXB1dfja5cF6mextVa5XrNdCDfNMzgJPsk6UGsVh1HOShmJSmYm8HrUE2gT15HR9hek5W8jE6+vi8s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1703482300435598.675978647813; Sun, 24 Dec 2023 21:31:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rHdX6-00055B-ME; Mon, 25 Dec 2023 00:29:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rHdX4-00054i-NA for qemu-devel@nongnu.org; Mon, 25 Dec 2023 00:29:42 -0500 Received: from mail-oi1-x22e.google.com ([2607:f8b0:4864:20::22e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rHdX3-0007IH-4f for qemu-devel@nongnu.org; Mon, 25 Dec 2023 00:29:42 -0500 Received: by mail-oi1-x22e.google.com with SMTP id 5614622812f47-3ba52d0f9feso2842108b6e.0 for ; Sun, 24 Dec 2023 21:27:40 -0800 (PST) Received: from localhost.localdomain ([118.114.58.28]) by smtp.gmail.com with ESMTPSA id f7-20020aa79d87000000b006d991505b4csm4555800pfq.76.2023.12.24.21.27.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 21:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1703482059; x=1704086859; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IPxH7gFNnh+/q7MXVJgutLRfldlr/zL58xbkQj7lR5Y=; b=dLkDzq0+oSiHASpX5dA6Rp/4Oiq204SyDXf1mYDURNUJc1j743oY+G+DfoloI2TEPf +VfgJVfr41Sr/3QU8yTDpHcI7YQv2rrAfSx5Hz9nfRgIsoVy/NIKTpSyR6GWRDPrhxy6 FTbvBM4JKbdFRy4QOoiNz+EOWzr4qGxf1gQYq2rqHspSEZOXrxlA8YjYez/kHzXOV/9l uF7EuydwhBN8pGIReXoe7QlBJpGnI534no7M+dD7uN3eP0nZnYr1Po84Ok0Vd+tR1V8Y Nlr8RTPxR83BHInZXtv+idddg5dwYb37Ks60qQsIBorKm56BSs3hnajXG6wBkp7UsUTm L/pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703482059; x=1704086859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IPxH7gFNnh+/q7MXVJgutLRfldlr/zL58xbkQj7lR5Y=; b=ZvzBXkQeeZdtPP2/HmAsiXO7J7d7iT9PDknE7POMpRpBheCkmtdHAhmarvT0nPOHBj I1yPEzQ4lmcHqZvRyx439RYJYbzMCbr716c9IRyWVqEHNnCcXmU2zb0D4tb0PphI+M7U 9V1+gtpLZVGhEMB7uBzzGqpwttE+NuuXF5NKdNnXFjgQ+3X7lVcVHD9i5UvUBg/pe9sq XfrsFuJ3KVu5Jp+Y76Tw9vBTfjq1bUmEYdhaJKex36lW73ySbAjeoTyB/x+R+OhLUnAG 5qEraU1Dmd/qS+KUEWVgYXqwopOeap0dxofpGj0F6PCjAfQ/OEtAqR1SqPF2yBTfd6jU G7MA== X-Gm-Message-State: AOJu0Yx7kRIGneTRJXh7usCSy79csozdv3fbJ/vhH+ZyvnguucGcQcSl L1KSHG26BZzwmCc8EU6MvXBJpErnnnOHz67igQmgxEzSA1jz7w== X-Google-Smtp-Source: AGHT+IH2tVs/BodH9ExVJOR5ky6B7cY2SPbouZZJKVuyfTBdAXOjtN2lphVWgs2v2S+SVIq6wq0unA== X-Received: by 2002:a05:6808:1395:b0:3ba:f4a:4310 with SMTP id c21-20020a056808139500b003ba0f4a4310mr5992389oiw.11.1703482059064; Sun, 24 Dec 2023 21:27:39 -0800 (PST) From: Hyman Huang To: qemu-devel Cc: Kevin Wolf , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Hanna Reitz , Eric Blake , Markus Armbruster , Hyman Huang Subject: [v3 05/10] crypto: Mark the payload_offset_sector invalid for detached LUKS header Date: Mon, 25 Dec 2023 13:26:55 +0800 Message-Id: <02d08ca67a4ec88cee61446d6b330c2945b5588f.1703481380.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.39.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=2607:f8b0:4864:20::22e; envelope-from=yong.huang@smartx.com; helo=mail-oi1-x22e.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @smartx-com.20230601.gappssmtp.com) X-ZM-MESSAGEID: 1703482301959100004 Content-Type: text/plain; charset="utf-8" Set the payload_offset_sector to a value that is nearly never reached in order to mark it as invalid and indicate that 0 should be the offset of the read/write operation on the 'file' protocol blockdev node. Signed-off-by: Hyman Huang --- crypto/block-luks.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/crypto/block-luks.c b/crypto/block-luks.c index fb01ec38bb..48443ffcae 100644 --- a/crypto/block-luks.c +++ b/crypto/block-luks.c @@ -34,6 +34,8 @@ =20 #include "qemu/bitmap.h" =20 +#define INVALID_SECTOR_OFFSET UINT32_MAX + /* * Reference for the LUKS format implemented here is * @@ -136,6 +138,13 @@ struct QCryptoBlockLUKS { }; =20 =20 +static inline uint32_t +qcrypto_block_luks_payload_offset(uint32_t sector) +{ + return sector =3D=3D INVALID_SECTOR_OFFSET ? 0 : + sector * QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; +} + static int qcrypto_block_luks_cipher_name_lookup(const char *name, QCryptoCipherMode mode, uint32_t key_bytes, @@ -1255,8 +1264,8 @@ qcrypto_block_luks_open(QCryptoBlock *block, } =20 block->sector_size =3D QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; - block->payload_offset =3D luks->header.payload_offset_sector * - block->sector_size; + block->payload_offset =3D + qcrypto_block_luks_payload_offset(luks->header.payload_offset_sect= or); =20 return 0; =20 @@ -1529,16 +1538,28 @@ qcrypto_block_luks_create(QCryptoBlock *block, slot->stripes =3D QCRYPTO_BLOCK_LUKS_STRIPES; } =20 - /* The total size of the LUKS headers is the partition header + key - * slot headers, rounded up to the nearest sector, combined with - * the size of each master key material region, also rounded up - * to the nearest sector */ - luks->header.payload_offset_sector =3D header_sectors + - QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS * split_key_sectors; + if (block->detached_header) { + /* + * Set the payload_offset_sector to a value that is nearly never + * reached in order to mark it as invalid and indicate that 0 shou= ld + * be the offset of the read/write operation on the 'file' protocol + * blockdev node. Here the UINT32_MAX is choosed + */ + luks->header.payload_offset_sector =3D INVALID_SECTOR_OFFSET; + } else { + /* + * The total size of the LUKS headers is the partition header + key + * slot headers, rounded up to the nearest sector, combined with + * the size of each master key material region, also rounded up + * to the nearest sector + */ + luks->header.payload_offset_sector =3D header_sectors + + QCRYPTO_BLOCK_LUKS_NUM_KEY_SLOTS * split_key_sectors; + } =20 block->sector_size =3D QCRYPTO_BLOCK_LUKS_SECTOR_SIZE; - block->payload_offset =3D luks->header.payload_offset_sector * - block->sector_size; + block->payload_offset =3D + qcrypto_block_luks_payload_offset(luks->header.payload_offset_sect= or); =20 /* Reserve header space to match payload offset */ initfunc(block, block->payload_offset, opaque, &local_err); --=20 2.39.1