Remove old AES-GCM library
Subsystems (3)
Eric Biggers
maintainercover Remove old AES-GCM library
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions
(https://lore.kernel.org/linux-crypto/[email protected]/).
The SEV code is the only user of the old API. Update it to use the new API instead. Then remove the old API.
This applies to libcrypto-next. If possible I'd like to take this through libcrypto-next for 7.3. Acks are appreciated.
Eric Biggers (3):
x86/sev: Use new AES-GCM library
x86/sev: Remove obsolete virtual address check
lib/crypto: aesgcm: Remove old AES-GCM library
arch/x86/Kconfig | 2 +- arch/x86/coco/sev/core.c | 53 +- arch/x86/include/asm/sev.h | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 7 +- include/crypto/gcm.h | 21 - lib/crypto/Kconfig | 6 - lib/crypto/Makefile | 3 - lib/crypto/aesgcm.c | 721 ------------------------ 8 files changed, 26 insertions(+), 789 deletions(-) delete mode 100644 lib/crypto/aesgcm.c
base-commit: e4f23159c8d09b6b15d47f2c95e0a3e7c62f52a2
Signature · 1 line
2.55.0
Eric Biggers
maintainerPATCH 1/3 x86/sev: Use new AES-GCM library
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions. The SEV code is the only user of the old AES-GCM library. Update it to use the new API instead.
Besides adjustments to the key struct name, function names, return value, and parameter order, the only notable changes are:
- Replace the direct accesses to the auth tag length field (which should be considered private until someone truly needs it) with the AUTHTAG_LEN constant which is already defined in <asm/sev.h>.
- Replace kfree() with kfree_sensitive() on lines being changed anyway.
--- arch/x86/Kconfig | 2 +- arch/x86/coco/sev/core.c | 44 ++++++++++++------------- arch/x86/include/asm/sev.h | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 7 ++-- 4 files changed, 26 insertions(+), 29 deletions(-)
arch/x86/Kconfig +1 -1
@@ -1495,7 +1495,7 @@ config AMD_MEM_ENCRYPT select ARCH_HAS_CC_PLATFORM select X86_MEM_ENCRYPT select UNACCEPTED_MEMORY - select CRYPTO_LIB_AESGCM + select CRYPTO_LIB_AES_GCM help Say yes to enable support for the encryption of system memory. This requires an AMD processor that supports Secure Memory
arch/x86/coco/sev/core.c +21 -23
106 lines not on this page · raw message
arch/x86/include/asm/sev.h +1 -1
@@ -314,7 +314,7 @@ struct snp_msg_desc {struct snp_secrets_page *secrets; -struct aesgcm_ctx *ctx; +struct aes_gcm_key *gcm_key;u32 *os_area_msg_seqno;u8 *vmpck;
drivers/virt/coco/sev-guest/sev-guest.c +3 -4
@@ -17,7 +17,6 @@#include <linux/set_memory.h> #include <linux/fs.h> #include <linux/tsm.h> -#include <crypto/gcm.h> #include <linux/psp-sev.h> #include <linux/sockptr.h> #include <linux/cleanup.h>
@@ -87,7 +86,7 @@ static int get_report(struct snp_guest_dev *snp_dev, struct snp_guest_request_io* response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len =sizeof (report_resp->data) + mdesc->ctx->authsize; + resp_len =sizeof (report_resp->data) +AUTHTAG_LEN ; report_resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT );if (!report_resp)return -ENOMEM ;
@@ -130,7 +129,7 @@ static int get_derived_key(struct snp_guest_dev *snp_dev, struct snp_guest_reque* response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len =sizeof (derived_key_resp->data) + mdesc->ctx->authsize; + resp_len =sizeof (derived_key_resp->data) +AUTHTAG_LEN ; derived_key_resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT );if (!derived_key_resp)return -ENOMEM ;
@@ -230,7 +229,7 @@ static int get_ext_report(struct snp_guest_dev *snp_dev, struct snp_guest_reques* response payload. Make sure that it has enough space to cover the * authtag. */ - resp_len =sizeof (report_resp->data) + mdesc->ctx->authsize; + resp_len =sizeof (report_resp->data) +AUTHTAG_LEN ; report_resp =kzalloc (resp_len,GFP_KERNEL_ACCOUNT );if (!report_resp) { ret = -ENOMEM ;
Signature · 1 line
2.55.0
Eric Biggers
maintainerPATCH 2/3 x86/sev: Remove obsolete virtual address check
In reply to Eric BiggersVirtual addresses used with the AES-GCM library don't have to be in the linear mapping. Remove the virt_addr_valid() checks from snp_send_guest_request(), which were a workaround left over from when this code used crypto_aead, which required scatterlists.
--- arch/x86/coco/sev/core.c | 9 --------- 1 file changed, 9 deletions(-)
arch/x86/coco/sev/core.c +0 -9
@@ -1867,15 +1867,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *requ64 seqno;int rc; -/* -* enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW. -* The offload's DMA SG list of data to encrypt has to be in linear mapping. -*/ -if (!virt_addr_valid (req->req_buf) || !virt_addr_valid (req->resp_buf)) { -pr_warn ("AES-GSM buffers must be in linear mapping" ); -return -EINVAL ; - } -guard (mutex)(&snp_cmd_mutex);/* Check if the VMPCK is not empty */
Signature · 1 line
2.55.0
Ard Biesheuvel
maintainerRe: [PATCH 2/3] x86/sev: Remove obsolete virtual address check
Quoted 10 lines · Eric Biggers
Virtual addresses used with the AES-GCM library don't have to be in the linear mapping. Remove the
virt_addr_valid()checks fromsnp_send_guest_request(), which were a workaround left over from when this code usedcrypto_aead, which required scatterlists.Signed-off-by Eric Biggers <[email protected]>--- arch/x86/coco/sev/core.c | 9 --------- 1 file changed, 9 deletions(-)
Quoted 23 lines
arch/x86/coco/sev/core.c +0
-9@@ -1867,15 +1867,6 @@ int snp_send_guest_request(struct snp_msg_desc *mdesc, struct snp_guest_req *requ64 seqno;int rc; -/* -* enc_payload() calls aesgcm_encrypt(), which can potentially offload to HW. -* The offload's DMA SG list of data to encrypt has to be in linear mapping. -*/ -if (!virt_addr_valid (req->req_buf) || !virt_addr_valid (req->resp_buf)) { -pr_warn ("AES-GSM buffers must be in linear mapping" ); -return -EINVAL ; - } -guard (mutex)(&snp_cmd_mutex);/* Check if the VMPCK is not empty */
Signature · 1 line
2.55.0
Eric Biggers
maintainerRe: [PATCH 2/3] x86/sev: Remove obsolete virtual address check
Quoted 8 lines · Ard Biesheuvel
Quoted 5 lines · Eric Biggers
Virtual addresses used with the AES-GCM library don't have to be in the linear mapping. Remove the
virt_addr_valid()checks fromsnp_send_guest_request(), which were a workaround left over from when this code usedcrypto_aead, which required scatterlists.
Quoted 8 lines
Quoted 5 lines
Signed-off-by Eric Biggers <[email protected]>--- arch/x86/coco/sev/core.c | 9 --------- 1 file changed, 9 deletions(-)
Thanks, I completely missed that. Looks like the usual issue where people were attached to workarounds even after the underlying problem was fixed. In the end, Alexey gave Reviewed-by and Tested-by on the exact same diff, just it never got applied. Alexey, would you mind if I add those tags to this patch too? Thanks!
- Eric
Eric Biggers
maintainerPATCH 3/3 lib/crypto: aesgcm: Remove old AES-GCM library
In reply to Eric BiggersThe old AES-GCM library code is no longer used, so remove it.
--- include/crypto/gcm.h | 21 -- lib/crypto/Kconfig | 6 - lib/crypto/Makefile | 3 - lib/crypto/aesgcm.c | 721 ------------------------------------------- 4 files changed, 751 deletions(-) delete mode 100644 lib/crypto/aesgcm.c
include/crypto/gcm.h +0 -21
@@ -3,9 +3,6 @@#include <linux/errno.h> -#include <crypto/aes.h> -#include <crypto/gf128hash.h> -#define GCM_AES_IV_SIZE 12#define GCM_RFC4106_IV_SIZE 8#define GCM_RFC4543_IV_SIZE 8
@@ -64,22 +61,4 @@ static inline int crypto_ipsec_check_assoclen(unsigned int assoclen) return 0; } -struct aesgcm_ctx { -struct ghash_key ghash_key; -struct aes_enckey aes_key; -unsigned int authsize; -}; - -int aesgcm_expandkey (struct aesgcm_ctx *ctx,const u8 *key, -unsigned int keysize,unsigned int authsize); - -void aesgcm_encrypt (const struct aesgcm_ctx *ctx,u8 *dst,const u8 *src, -int crypt_len,const u8 *assoc,int assoc_len, -const u8 iv[GCM_AES_IV_SIZE ],u8 *authtag); - -bool __must_check aesgcm_decrypt (const struct aesgcm_ctx *ctx,u8 *dst, -const u8 *src,int crypt_len,const u8 *assoc, -int assoc_len,const u8 iv[GCM_AES_IV_SIZE ], -const u8 *authtag); -#endif
lib/crypto/Kconfig +0 -6
@@ -75,12 +75,6 @@ config CRYPTO_LIB_AES_XTS help The AES-XTS library functions. -config CRYPTO_LIB_AESGCM - tristate - select CRYPTO_LIB_AES - select CRYPTO_LIB_GF128HASH - select CRYPTO_LIB_UTILS - config CRYPTO_LIB_ARC4 tristate
lib/crypto/Makefile +0 -3
@@ -63,9 +63,6 @@ clean-files += powerpc/aesp8-ppc.S obj-$(CONFIG_CRYPTO_LIB_AESCFB) += libaescfb.o libaescfb-y := aescfb.o -obj-$(CONFIG_CRYPTO_LIB_AESGCM) += libaesgcm.o -libaesgcm-y := aesgcm.o - obj-$(CONFIG_CRYPTO_LIB_ARC4) += libarc4.o libarc4-y := arc4.o
lib/crypto/aesgcm.c deleted +0 -721
721 lines not on this page · raw message
Signature · 1 line
2.55.0
Quoted 8 lines · Eric Biggers
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions
(https://lore.kernel.org/linux-crypto/[email protected]/).The SEV code is the only user of the old API. Update it to use the new API instead. Then remove the old API.
Quoted 8 lines
This applies to libcrypto-next. If possible I'd like to take this through libcrypto-next for 7.3. Acks are appreciated.
Eric Biggers (3):
x86/sev: Use new AES-GCM library
x86/sev: Remove obsolete virtual address check
lib/crypto: aesgcm: Remove old AES-GCM library
Quoted 15 lines
arch/x86/Kconfig | 2 +- arch/x86/coco/sev/core.c | 53 +- arch/x86/include/asm/sev.h | 2 +- drivers/virt/coco/sev-guest/sev-guest.c | 7 +- include/crypto/gcm.h | 21 - lib/crypto/Kconfig | 6 - lib/crypto/Makefile | 3 - lib/crypto/aesgcm.c | 721 ------------------------ 8 files changed, 26 insertions(+), 789 deletions(-) delete mode 100644 lib/crypto/aesgcm.cbase-commit:
e4f23159c8d09b6b15d47f2c95e0a3e7c62f52a2Signature · 1 line
2.55.0
Borislav Petkov
maintainerQuoted 10 lines · Eric Biggers
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions
(https://lore.kernel.org/linux-crypto/[email protected]/).The SEV code is the only user of the old API. Update it to use the new API instead. Then remove the old API.
This applies to libcrypto-next. If possible I'd like to take this through libcrypto-next for 7.3. Acks are appreciated.
Fine with me as long as the additionally added AMD folks can verify everything still works with their SNP guest setups.
Thx.
Signature · 4 lines
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquetteNikunj A. Dadhania
Tested-byQuoted 6 lines · Borislav Petkov
Quoted 5 lines · Eric Biggers
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions
(https://lore.kernel.org/linux-crypto/[email protected]/).
Quoted 8 lines
Quoted 5 lines
The SEV code is the only user of the old API. Update it to use the new API instead. Then remove the old API.
This applies to libcrypto-next. If possible I'd like to take this through libcrypto-next for 7.3. Acks are appreciated.
Fine with me as long as the additionally added AMD folks can verify everything still works with their SNP guest setups.
Tested with a SecureTSC-enabled SNP guest. SecureTSC guests rely on the SNP guest messaging API which uses AES-GCM library, so this exercises the new library code through that path. No issues found.
Quoted 10 lines · Eric Biggers
The old AES-GCM library code is being replaced as part of an overhaul that is adding support for all the common AES encryption modes with consistent conventions
(https://lore.kernel.org/linux-crypto/[email protected]/).The SEV code is the only user of the old API. Update it to use the new API instead. Then remove the old API.
This applies to libcrypto-next. If possible I'd like to take this through libcrypto-next for 7.3. Acks are appreciated.
Applied to https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git/log/?h=libcrypto-next
- Eric