From patchwork Wed Dec 6 16:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13482018 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 86729C4167B for ; Wed, 6 Dec 2023 16:40:47 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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é --- 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 */ }; 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'} } ## # @BlockdevOptionsGenericCOWFormat: From patchwork Wed Dec 6 16:37:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13482021 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98499C4167B for ; Wed, 6 Dec 2023 16:41:11 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Signed-off-by: Hyman Huang Reviewed-by: Daniel P. Berrangé --- 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(QCryptoBlock *block) return block->kdfhash; } +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset) +{ + block->payload_offset = offset; +} 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); G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoBlock, qcrypto_block_free) +void qcrypto_block_set_payload_offset(QCryptoBlock *block, uint64_t offset); #endif /* QCRYPTO_BLOCK_H */ From patchwork Wed Dec 6 16:37:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13482017 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9EDD3C4167B for ; Wed, 6 Dec 2023 16:40:36 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 */ }; @@ -64,12 +65,16 @@ static int block_crypto_read_func(QCryptoBlock *block, Error **errp) { BlockDriverState *bs = opaque; + BlockCrypto *crypto = bs->opaque; ssize_t ret; GLOBAL_STATE_CODE(); GRAPH_RDLOCK_GUARD_MAINLOOP(); - ret = bdrv_pread(bs->file, offset, buflen, buf, 0); + if (crypto->detached_mode) + ret = bdrv_pread(crypto->header, offset, buflen, buf, 0); + else + ret = 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 = NULL; unsigned int cflags = 0; QDict *cryptoopts = NULL; + const char *header_bdref = + qdict_get_try_str(options, "header"); GLOBAL_STATE_CODE(); @@ -277,6 +284,16 @@ static int block_crypto_open_generic(QCryptoBlockFormat format, return ret; } + if (header_bdref) { + crypto->detached_mode = true; + crypto->header = bdrv_open_child(NULL, options, "header", bs, + &child_of_bds, BDRV_CHILD_METADATA, + false, errp); + if (!crypto->header) { + return -EINVAL; + } + } + GRAPH_RDLOCK_GUARD_MAINLOOP(); bs->supported_write_flags = BDRV_REQ_FUA & @@ -312,6 +329,14 @@ static int block_crypto_open_generic(QCryptoBlockFormat format, goto cleanup; } + 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 = true; ret = 0; @@ -903,6 +928,17 @@ block_crypto_child_perms(BlockDriverState *bs, BdrvChild *c, BlockCrypto *crypto = bs->opaque; + if (role == (role & BDRV_CHILD_METADATA)) { + /* Assign read permission only */ + perm |= BLK_PERM_CONSISTENT_READ; + /* Share all permissions */ + shared |= BLK_PERM_ALL; + + *nperm = perm; + *nshared = shared; + return; + } + bdrv_default_perms(bs, c, role, reopen_queue, perm, shared, nperm, nshared); /* From patchwork Wed Dec 6 16:37:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yong Huang X-Patchwork-Id: 13482019 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD50AC4167B for ; Wed, 6 Dec 2023 16:40:49 +0000 (UTC) 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) 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) 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) From: Hyman Huang To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , =?utf-8?q?Daniel_P_=2E_Berrang=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 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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org 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 *create_options, Error **errp) BlockDriverState *bs = NULL; QCryptoBlockCreateOptions create_opts; PreallocMode preallocation = PREALLOC_MODE_OFF; + int64_t size; int ret; assert(create_options->driver == BLOCKDEV_DRIVER_LUKS); luks_opts = &create_options->u.luks; + size = luks_opts->size; bs = bdrv_co_open_blockdev_ref(luks_opts->file, errp); if (bs == NULL) { @@ -686,7 +688,11 @@ block_crypto_co_create_luks(BlockdevCreateOptions *create_options, Error **errp) preallocation = luks_opts->preallocation; } - ret = block_crypto_co_create_generic(bs, luks_opts->size, &create_opts, + if (luks_opts->detached_mode) { + size = 0; + } + + ret = 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'}} ## # @BlockdevCreateOptionsNfs: