From nobody Wed Nov 27 00:33:25 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=1701880847; cv=none; d=zohomail.com; s=zohoarc; b=Z8yTT9M9okS6kURliCS1Mbia4jHqtnsm8j4re9RGCfgs+lxkwJW/rvyWegfqCwd/0t0BMyR2khDCwZnd1t+SZfcZbB4CKSZo520heXwr5H190VajidvD8bHKYYF0y4Fc+PpAIcK1zUzxdwkrIekOohvqRUT1lhbmqL9o6kLR1JI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701880847; 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=Lzq/6uBa8Sn9homJ2UmZstCzNIMtGnzp/+bkC0HtRY4=; b=i4MBDOYEpBOQOJC1QIpuA226ScPCCSstojRS9rNdqCioMFDVRMVwRwLD8WPuf6otegRxj0Zw+SjJC9sBLUOh207/dFjM2YWx+AV0YaxIik7SqxY8eMvlfU1LO1ESBSM6Q0/yYb16MfzVL0GqWca3Ubde43WMF65yc8jkrDBePUo= 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 1701880847473155.4378110864144; Wed, 6 Dec 2023 08:40:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rAuwO-0006yt-CJ; Wed, 06 Dec 2023 11:40:04 -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 1rAuwM-0006yc-F5 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:02 -0500 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rAuwK-0003mY-MF for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:02 -0500 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1cf7a8ab047so31966325ad.1 for ; Wed, 06 Dec 2023 08:38:00 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m14-20020a170902bb8e00b001d04d730687sm42570pls.103.2023.12.06.08.37.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701880679; x=1702485479; 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=Lzq/6uBa8Sn9homJ2UmZstCzNIMtGnzp/+bkC0HtRY4=; b=ox3mo8XzQDun9wqMkp03kN3eENdQf52mi5f2FaMNcUq6zgQtCHen00jPCa/p9+EePO y0ySaiGaA9RBld2eZvbruROGdU0L5w+MRS1B0duzNNwzXlKRmIzZqAw98qjT3uWv6+qS NKNbohLkHWV0kwuvxMN76h2D//haMk+GnL7DkiQIPqI5qxnYnZjYWpofb3e051XAgGqI hcorcLXgyK2b1UZOrajw7YL5jN2Qzwxmjdr1bcNteN59/TpWddOwCnYaOCY0cHsaHby1 KujlqGDF5CsSuG/Vgau+NS+qA/Id+OsomrsOqqjbREoO3yVdt/2jWofuL3iSkJddkox7 iLNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880679; x=1702485479; 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=Lzq/6uBa8Sn9homJ2UmZstCzNIMtGnzp/+bkC0HtRY4=; b=ifzrmBqA4M6n0G4wfPX4OWSFsuK+uouq76bmvAxk6JhD6g+RbmX9Gt/jryCwAC+hQ2 2CigjNmvswdOHvJyiy2H05G5g5x30baWmoHNpcu0JTfVFeWeM4gZQ3FQPhPg/TFA42L8 hXmU/xOlXG/QSE+PgsxWvPl6Le2gmKRzpeOEStc51ycTKiMhhtBmnMBU3cpmhwCHzR9p 4QdfsTXC5lXXW2szrB0jYwsdruhrAL69WkjKEmhx0eYFZQ7oirmv5gFH/0grvjCSr+Rp mQYUCs9g2Qqq8rEdVHbC9Po3UKXFVJhllsEisDqBs9J/FE9+nrmcrDIK/ymy/HQPiy0d gVbg== X-Gm-Message-State: AOJu0YxnVe9qRGXzIsElneM3iRY2RdJvTqHKaNXqGZ/sItQOR1ujIMPc Jn47WBIAZ/D8j/R4ZUb3C/63Uh+lm8oIKk9yzlQw2QTr X-Google-Smtp-Source: AGHT+IHjYLGSi99NOQjQ64UIfwsdbpbcLEnr0ycFXtwodoGRurjmDFBC0dYb8R1g6qREqDojoi60XQ== X-Received: by 2002:a17:902:ef91:b0:1d0:6ffd:8372 with SMTP id iz17-20020a170902ef9100b001d06ffd8372mr729405plb.125.1701880678545; Wed, 06 Dec 2023 08:37:58 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [v2 1/4] crypto: Introduce option and structure for detached LUKS header Date: Thu, 7 Dec 2023 00:37:42 +0800 Message-Id: <5b99f60c7317092a563d7ca3fb4b414197015eb2.1701879996.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::632; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x632.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: 1701880848106100001 Content-Type: text/plain; charset="utf-8" Add the "header" option for the LUKS format. This field would be used to identify the blockdev's position where a detachable LUKS header is stored. In addition, introduce header field in struct BlockCrypto Signed-off-by: Hyman Huang Reviewed-by: Daniel P. Berrang=C3=A9 --- block/crypto.c | 1 + qapi/block-core.json | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/block/crypto.c b/block/crypto.c index 921933a5e5..f82b13d32b 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -39,6 +39,7 @@ typedef struct BlockCrypto BlockCrypto; struct BlockCrypto { QCryptoBlock *block; bool updating_keys; + BdrvChild *header; /* Reference to the detached LUKS header */ }; =20 =20 diff --git a/qapi/block-core.json b/qapi/block-core.json index ca390c5700..10be08d08f 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3352,11 +3352,15 @@ # decryption key (since 2.6). Mandatory except when doing a # metadata-only probe of the image. # +# @header: optional reference to the location of a blockdev +# storing a detached LUKS header. (since 9.0) +# # Since: 2.9 ## { 'struct': 'BlockdevOptionsLUKS', 'base': 'BlockdevOptionsGenericFormat', - 'data': { '*key-secret': 'str' } } + 'data': { '*key-secret': 'str', + '*header': 'BlockdevRef'} } =20 ## # @BlockdevOptionsGenericCOWFormat: --=20 2.39.1 From nobody Wed Nov 27 00:33:25 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=1701880871; cv=none; d=zohomail.com; s=zohoarc; b=MvojlncEVla3kdwReI3BVtxdm7sCWGcY2A1Vk1yrXrYr4xKjWb0WeI0d5Gp8wOkUhE3wL1GRZRtG7a421rjTZmvRg7fn1s97XjfWXPOcfK3RiH/R1JLr74qPFTz7a6D93HYUy/Mcr506wZ6QFMpbg755pr36hSsVFwuCJsO/YM8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701880871; 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=ME+BuRtXMyZoePaH7F1ht47MskX6EGo+OV1KpUXdVVY=; b=nUwIGUoedBKczAQIJ1zhlIyISTrHCBUPw0qyuZWFlRIsAQ7iOzQRCdX2v0P83WNbnR7/YgSm9CvhGkJqCeFn+E18FCzP5XN4zs2YJXIKI2Dp+gGn3qdeGXWHKqIyJhw9xiwpUOYKG04ZVXwn0u9kODmQvKrFBSk4NiVe6MgReuQ= 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 1701880871879561.1509481797275; Wed, 6 Dec 2023 08:41:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rAuwR-0006zm-3S; Wed, 06 Dec 2023 11:40:07 -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 1rAuwP-0006zV-Ps for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:05 -0500 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rAuwO-0003mm-A9 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:05 -0500 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1d045097b4cso35026425ad.0 for ; Wed, 06 Dec 2023 08:38:03 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m14-20020a170902bb8e00b001d04d730687sm42570pls.103.2023.12.06.08.37.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701880683; x=1702485483; 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=ME+BuRtXMyZoePaH7F1ht47MskX6EGo+OV1KpUXdVVY=; b=QEYTVyI9SRJ8Dw0YchCHVYykXFKyDWrnw3DgBOEmY4ypkfPPgbw0U/E2MT4OW5XcxY TsDWx+XNAHHBIeOBIXpkMYY9k1xGkYym9Vs1qA1tw4vdSmwf3QjIiOTZrRj0uvXmULue 8z/or7DS8TMOXKy7VO+SAHTvkyWjKSdrs342zhUFINWqTJlcOiuA8QtSkl0q6YLr1l+4 ofXo7nWOQcJSCExCaswAFr6VWxUbHZL+TJa9Q2jT+ObpwNNiIFVakATiq+GMY8cMR2oR xyPvaVdAKU/zZ8YWGn5PexBH/nc2jmFumej3RHLFcgigbn952lo7YDmpr+mChubC4ct7 szAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880683; x=1702485483; 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=ME+BuRtXMyZoePaH7F1ht47MskX6EGo+OV1KpUXdVVY=; b=MIv03xx2OAY8933HIGeA8EA+TLZE5FWCUVdUa+tpimsjyQzRueeU/LcGZyThbQtnzs H+KMHiZtG3R7ihoF9aCFoxe+DI3A2U7JB2T01SsA6kczBPdT4yGJqZs8VuZc+le9ePmt z5ryMiDLKrNBUnPqBCHK47TpXSC/fw1W8Y9hb8ukyFKUvjjYA0kjQ3jYVuheJze/JvVo rWu0JLzdz+6SHPiyAId6FB+G8Wr554T1CBMOL/csMcdG2kMKH5J9tXdr8tEobIz2awdW trrgNu0oZkb37iLJUePaFoml/eSvZsMlHSRUf4FYLnZmcVr98oNoPK0GULpoPutqi66L ZmoA== X-Gm-Message-State: AOJu0Yyslckvlm+6I6rsJpWuPKJKchvWFj+ilHXRTSzIu7yOhegR/Y30 WxhYf217hIZmi9/zu5vBwkpJO+w8bMF3QzFw42ra1pqj X-Google-Smtp-Source: AGHT+IHMpFR9P/twlo67hGfP/nzWKiLqHvGB1PLDWY/gq6iJIgB0srQIvgOsGN5xpRMDIZ99zeDl6w== X-Received: by 2002:a17:902:7604:b0:1cf:747e:89c6 with SMTP id k4-20020a170902760400b001cf747e89c6mr885872pll.26.1701880682367; Wed, 06 Dec 2023 08:38:02 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [v2 2/4] crypto: Introduce payload offset set function Date: Thu, 7 Dec 2023 00:37:43 +0800 Message-Id: <7130b0b19c38bc4e92071198af54a56f8ba3597c.1701879996.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::62c; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62c.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: 1701880872598100005 Content-Type: text/plain; charset="utf-8" Signed-off-by: Hyman Huang Reviewed-by: Daniel P. Berrang=C3=A9 --- crypto/block.c | 4 ++++ include/crypto/block.h | 1 + 2 files changed, 5 insertions(+) diff --git a/crypto/block.c b/crypto/block.c index 7bb4b74a37..3dcf22a69f 100644 --- a/crypto/block.c +++ b/crypto/block.c @@ -319,6 +319,10 @@ QCryptoHashAlgorithm qcrypto_block_get_kdf_hash(QCrypt= oBlock *block) return block->kdfhash; } =20 +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset) +{ + block->payload_offset =3D offset; +} =20 uint64_t qcrypto_block_get_payload_offset(QCryptoBlock *block) { diff --git a/include/crypto/block.h b/include/crypto/block.h index 4f63a37872..b47a90c529 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -312,4 +312,5 @@ void qcrypto_block_free(QCryptoBlock *block); =20 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) =20 +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset= ); #endif /* QCRYPTO_BLOCK_H */ --=20 2.39.1 From nobody Wed Nov 27 00:33:25 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=1701880836; cv=none; d=zohomail.com; s=zohoarc; b=PhZoip1CFj/QFvHw250yJ13JytDbnM5wYkKmz2H3lr5guDnzRBx8Mx71QHP4akqfVEMZOPbcoxM+kweIZjsrtvdBmHIi6o5JSp919W54jZ0WedoqTGCtjjEq0wAevDgfiq5GNV+h2ZBqd5JIp0TO6ToTq0H8UDfLebrxDvEp2lU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701880836; 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=e2TeQm179WJYabh6QIsHuX0i02sIiWoRD0LrOlPmpos=; b=SHf1eWVeOT3/JZCeCxPHpuKuPSD1P72+IOPBbkWSmlZQigSL3ZapvzbG8uu5klOKvLtJYYu1/N6+zCOZPs7x8f+trb8Cmjq8WwilKMxes7M46W2dFFLqBSqFgSSEP8ccOrfzfYofBwILCBH8AjT/5RFbGnpApKtizBLfRC4BB/E= 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 1701880836800520.2056317552417; Wed, 6 Dec 2023 08:40:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rAuwi-000740-AJ; Wed, 06 Dec 2023 11:40:24 -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 1rAuwW-00070I-N8 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:14 -0500 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rAuwS-0003oY-R1 for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:12 -0500 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1d0a7b72203so31270205ad.2 for ; Wed, 06 Dec 2023 08:38:08 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m14-20020a170902bb8e00b001d04d730687sm42570pls.103.2023.12.06.08.38.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:38:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701880687; x=1702485487; 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=e2TeQm179WJYabh6QIsHuX0i02sIiWoRD0LrOlPmpos=; b=G+QNJgcAo/XLnLtuPFTgMzXb8kd8V+cYq6nv8dWOeG1oXB2LFGJcvI5EnkCnIxd64O rT7Gb9/q18qHXp8IjDi/GsID+FAyCsLyIGeQuTLeXGo072BMWK0rLMANdGGtcfPureNo TtG/lrztcUjBWf989oHV1yaYlHcNFpRshgAJpmCnQS8TcbCacRWnrwUJO+/hieg0MpFT D3i6nerjyW3cPOMnTmfPXhZn4pg8Zbu5yaAHHZa14BNAvhsEno/GhEheSrIlAHy5qnGi lL3F6zhLqFMr00Dw0Oz5eFFao0wrUFTP0X55qiD6bo2/F/eMdbuGZ7TjgDEJr2s4cMSc EexA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880687; x=1702485487; 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=e2TeQm179WJYabh6QIsHuX0i02sIiWoRD0LrOlPmpos=; b=GUcSlNJ/f5sBFzGxnvH2jEMbjbBoo02b9DnvAqJG/fQEdAcNa+2QENDp2+ZCn+48JF 1/oNdIOVFr1ZiVKiUyh93j9DEnS42GK7BDYpDBz7ko6AUXR4I9anJMUQTQxrPob0aPVG Ak1odVgtxU/Ok/dq5cWh4bVZZqyzJHHoKgKLNSsY1Gzf8GhB5O2ofJ9KH9XhmszlTqym 5Fvltlp0mVw9zz9b+mxEtcMcljO6OmAV8Hq+oXlFBNqM4ePJl7+4i2Y/uBJW0+qt2gI2 Xe89PtOAcN876SxpsV71OBKBeuWgvPiTpqtC0kZvR2Mr2JF4Z7bfyUQmtCFHUguuZUUr KJjw== X-Gm-Message-State: AOJu0Ywj+EmNryy3qYc3FPFBtw84mPIDkIghSlEEozU/W2Whd0lpdAax y73TVB3M6voP5S7BYOcY/PBR5XDWgN+f4TesPlpN5nL3 X-Google-Smtp-Source: AGHT+IHoEKtpi/q+qffwIGy4ZAt0Z7829OqDaOTFNctp5zoGm/roNr8yFDAFTpj+tmtwMAltuFcyDg== X-Received: by 2002:a17:903:32d0:b0:1c9:cc88:502c with SMTP id i16-20020a17090332d000b001c9cc88502cmr1381760plr.69.1701880686716; Wed, 06 Dec 2023 08:38:06 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [v2 3/4] crypto: Support generic LUKS encryption Date: Thu, 7 Dec 2023 00:37:44 +0800 Message-Id: <910801f303da1601051479d3b7e5c2c6b4e01eb7.1701879996.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::630; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x630.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: 1701880838008100003 Content-Type: text/plain; charset="utf-8" By enhancing the LUKS driver, it is possible to enable the detachable LUKS header and, as a result, achieve general encryption for any disk format that QEMU has supported. Take the qcow2 as an example, the usage of the generic LUKS encryption as follows: 1. add a protocol blockdev node of data disk $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-storage", "driver":"file", > "filename":"/path/to/test_disk.qcow2"}}' 2. add a protocol blockdev node of LUKS header as above. $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-2-storage", "driver":"file", > "filename": "/path/to/cipher.gluks" }}' 3. add the secret for decrypting the cipher stored in LUKS header above $ virsh qemu-monitor-command vm '{"execute":"object-add", > "arguments":{"qom-type":"secret", "id": > "libvirt-2-storage-secret0", "data":"abc123"}}' 4. add the qcow2-drived blockdev format node $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-format", "driver":"qcow2", > "file":"libvirt-1-storage"}}' 5. add the luks-drived blockdev to link the qcow2 disk with LUKS header by specifying the field "header" $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-2-format", "driver":"luks", > "file":"libvirt-1-format", "header":"libvirt-2-storage", > "key-secret":"libvirt-2-format-secret0"}}' 6. add the virtio-blk device finally $ virsh qemu-monitor-command vm '{"execute":"device_add", > "arguments": {"num-queues":"1", "driver":"virtio-blk-pci", > "drive": "libvirt-2-format", "id":"virtio-disk2"}}' The generic LUKS encryption method of starting a virtual machine (VM) is somewhat similar to hot-plug in that both maintaining the same json command while the starting VM changes the "blockdev-add/device_add" parameters to "blockdev/device". Signed-off-by: Hyman Huang --- block/crypto.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/block/crypto.c b/block/crypto.c index f82b13d32b..7d70349463 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -40,6 +40,7 @@ struct BlockCrypto { QCryptoBlock *block; bool updating_keys; BdrvChild *header; /* Reference to the detached LUKS header */ + bool detached_mode; /* If true, LUKS plays a detached header role */ }; =20 =20 @@ -64,12 +65,16 @@ static int block_crypto_read_func(QCryptoBlock *block, Error **errp) { BlockDriverState *bs =3D opaque; + BlockCrypto *crypto =3D bs->opaque; ssize_t ret; =20 GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 - ret =3D bdrv_pread(bs->file, offset, buflen, buf, 0); + if (crypto->detached_mode) + ret =3D bdrv_pread(crypto->header, offset, buflen, buf, 0); + else + ret =3D bdrv_pread(bs->file, offset, buflen, buf, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read encryption header"); return ret; @@ -269,6 +274,8 @@ static int block_crypto_open_generic(QCryptoBlockFormat= format, QCryptoBlockOpenOptions *open_opts =3D NULL; unsigned int cflags =3D 0; QDict *cryptoopts =3D NULL; + const char *header_bdref =3D + qdict_get_try_str(options, "header"); =20 GLOBAL_STATE_CODE(); =20 @@ -277,6 +284,16 @@ static int block_crypto_open_generic(QCryptoBlockForma= t format, return ret; } =20 + if (header_bdref) { + crypto->detached_mode =3D true; + crypto->header =3D bdrv_open_child(NULL, options, "header", bs, + &child_of_bds, BDRV_CHILD_METADAT= A, + false, errp); + if (!crypto->header) { + return -EINVAL; + } + } + GRAPH_RDLOCK_GUARD_MAINLOOP(); =20 bs->supported_write_flags =3D BDRV_REQ_FUA & @@ -312,6 +329,14 @@ static int block_crypto_open_generic(QCryptoBlockForma= t format, goto cleanup; } =20 + if (crypto->detached_mode) { + /* + * Set payload offset to zero as the file bdref has no LUKS + * header under detached mode. + */ + qcrypto_block_set_payload_offset(crypto->block, 0); + } + bs->encrypted =3D true; =20 ret =3D 0; @@ -903,6 +928,17 @@ block_crypto_child_perms(BlockDriverState *bs, BdrvChi= ld *c, =20 BlockCrypto *crypto =3D bs->opaque; =20 + if (role =3D=3D (role & BDRV_CHILD_METADATA)) { + /* Assign read permission only */ + perm |=3D BLK_PERM_CONSISTENT_READ; + /* Share all permissions */ + shared |=3D BLK_PERM_ALL; + + *nperm =3D perm; + *nshared =3D shared; + return; + } + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nsh= ared); =20 /* --=20 2.39.1 From nobody Wed Nov 27 00:33:25 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=1701880849; cv=none; d=zohomail.com; s=zohoarc; b=mfwikh9QqSEJPb7uL3xXaWSUxLIZgeE8hToZHDb71g2p9TV3WfHpxJt4fu4lknCxjpbPC6dD0iL8Pui8rt5fmsj/DoETOF3bThkWcLXDZV9YLhGILoEBXonE1yVTEirZid0mzokpKw9ACRoX5OuN00xmryLKNNWwK92Uv1nI3Bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1701880849; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=D8kref6vpHlOksHSTP0Ua3IKoXe7Hv/RYEF0iJsG27VF2sDI8bwvGdimFqCgqPPgxm2nPtbg0QAp4dLuDuqwRd3WBLPiGvB2fsw/m7xEswMh5/gImt9I4CeHr6ZeMLhpAzUL3bQxNg9wSvH5we9s01octI/SlNuVCMG07BVvHbU= 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 1701880849854622.5672086488394; Wed, 6 Dec 2023 08:40:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rAuwz-0007DE-BM; Wed, 06 Dec 2023 11:40:45 -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 1rAuwb-00073Q-FN for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:18 -0500 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rAuwW-0003oq-Db for qemu-devel@nongnu.org; Wed, 06 Dec 2023 11:40:15 -0500 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1d04c097e34so137845ad.0 for ; Wed, 06 Dec 2023 08:38:11 -0800 (PST) Received: from localhost.localdomain ([125.71.95.66]) by smtp.gmail.com with ESMTPSA id m14-20020a170902bb8e00b001d04d730687sm42570pls.103.2023.12.06.08.38.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 08:38:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1701880691; x=1702485491; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=NK+BzmYla6ksZeyMBHdP4k25UTJOgsAIFaMJPg6yDYRQzz1AO3a6NAzUESX/KkyqUV Hz0Of38/KKtUsHMj39YKV5U7OhAgvg/4RGfykfn0YdmuSkDG+ocQsVkmScJoUenQ+gZX el+MLLl+VwGtXA1laH9BEnPIqjVv9pSicBbzti9fZNTjm8CxA08vVvBZ4IMTH+LeBQIR dwHXiFw8ZRnBjt9iZhwUxCZ4L2JPnK4XLDMAStCxKTTsaWEOaZEPiNoCNdxKYCRNgyQ9 icBJPNkaqow+6K71RJyEi1iGxrmSOIerkWxftB5y5VR6VHjZHqnoxAxAigBtxbyzBuYQ /p2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701880691; x=1702485491; 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=qhMhC1dRCAzfDuzYgcsG+53k26v66QjFrETHi98zfg4=; b=HUmOjOtyNL9favrfo/1wx3RE89yaDeZ2wp1XlVi8k9ccRhNqICaaL3xN6JRdoMeIkI 1EZ1OKR++06SpoXty4hVKbw3aMwlCBiSvYiH/nn5aAqibRpZdUOHW/FgnSgR0bVAGeLa tM16lO/SBjYBmv1b4ld9OAlsrnalQmr1w/sJDAERKc/GYO7O6bFcXDD+TwXo6M4ouLw8 HxGeqwQfoM0XY1aRyKIqQ1cHbpMq7PFejG6v+X6/HWPK/G0lD5mu94C0UEvjQQ5uQ5CA aG4lYzIygn2zVEi4wml86fe7TsUZDckeZaXqvMjFSVpgO5Sy7ly/SjJQf/mUTWsmMHsY rKXw== X-Gm-Message-State: AOJu0Yz604vUhXM6gfqvxT/DZcwZtt938hKXAcvf5aSS8A/6smB3jKgB rsbhG06On7+v25cHMotAGC8OtQdigPwKufS9/OKN1bEn X-Google-Smtp-Source: AGHT+IEXyGEuBvgs5pBKRgZaStL31ffR79X1CEOuNwkByP/zqRwAhbS7l/A9QjyOEjY5EdXcfjmN8A== X-Received: by 2002:a17:902:ff01:b0:1cf:fc91:e4d0 with SMTP id f1-20020a170902ff0100b001cffc91e4d0mr4275488plj.16.1701880690497; Wed, 06 Dec 2023 08:38:10 -0800 (PST) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= , Eric Blake , Markus Armbruster , yong.huang@smartx.com Subject: [v2 4/4] block: Support detached LUKS header creation for blockdev-create Date: Thu, 7 Dec 2023 00:37:45 +0800 Message-Id: <5ca4a43ea0795d9fb6ea3649eead10017df69b1c.1701879996.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::62b; envelope-from=yong.huang@smartx.com; helo=mail-pl1-x62b.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: 1701880850203100005 Content-Type: text/plain; charset="utf-8" Provide the "detached-mode" option for detached LUKS header formatting. To format the LUKS header on the pre-creating disk, example as follows: 1. add a protocol blockdev node of LUKS header $ virsh qemu-monitor-command vm '{"execute":"blockdev-add", > "arguments":{"node-name":"libvirt-1-storage", "driver":"file", > "filename":"/path/to/cipher.gluks" }}' 2. add the secret for encrypting the cipher stored in LUKS header above $ virsh qemu-monitor-command vm '{"execute":"object-add", > "arguments":{"qom-type": "secret", "id": > "libvirt-1-storage-secret0", "data": "abc123"}}' 3. format the disk node $ virsh qemu-monitor-command vm '{"execute":"blockdev-create", > "arguments":{"job-id":"job0", "options":{"driver":"luks", > "size":0, "file":"libvirt-1-storage", "detached-mode":true, > "cipher-alg":"aes-256", > "key-secret":"libvirt-3-storage-encryption-secret0"}}}' Signed-off-by: Hyman Huang --- block/crypto.c | 8 +++++++- qapi/block-core.json | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/block/crypto.c b/block/crypto.c index 7d70349463..e77c49bd0c 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -667,10 +667,12 @@ block_crypto_co_create_luks(BlockdevCreateOptions *cr= eate_options, Error **errp) BlockDriverState *bs =3D NULL; QCryptoBlockCreateOptions create_opts; PreallocMode preallocation =3D PREALLOC_MODE_OFF; + int64_t size; int ret; =20 assert(create_options->driver =3D=3D BLOCKDEV_DRIVER_LUKS); luks_opts =3D &create_options->u.luks; + size =3D luks_opts->size; =20 bs =3D bdrv_co_open_blockdev_ref(luks_opts->file, errp); if (bs =3D=3D NULL) { @@ -686,7 +688,11 @@ block_crypto_co_create_luks(BlockdevCreateOptions *cre= ate_options, Error **errp) preallocation =3D luks_opts->preallocation; } =20 - ret =3D block_crypto_co_create_generic(bs, luks_opts->size, &create_op= ts, + if (luks_opts->detached_mode) { + size =3D 0; + } + + ret =3D block_crypto_co_create_generic(bs, size, &create_opts, preallocation, errp); if (ret < 0) { goto fail; diff --git a/qapi/block-core.json b/qapi/block-core.json index 10be08d08f..1e7a7e1b05 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -4952,13 +4952,16 @@ # @preallocation: Preallocation mode for the new image (since: 4.2) # (default: off; allowed values: off, metadata, falloc, full) # +# @detached-mode: create a detached LUKS header. (since 9.0) +# # Since: 2.12 ## { 'struct': 'BlockdevCreateOptionsLUKS', 'base': 'QCryptoBlockCreateOptionsLUKS', 'data': { 'file': 'BlockdevRef', 'size': 'size', - '*preallocation': 'PreallocMode' } } + '*preallocation': 'PreallocMode', + '*detached-mode': 'bool'}} =20 ## # @BlockdevCreateOptionsNfs: --=20 2.39.1