lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8834a0d5-12dd-4dd6-bb03-2f66616db9ee@amd.com>
Date: Sat, 27 Jan 2024 09:24:14 +0530
From: "Nikunj A. Dadhania" <nikunj@....com>
To: Borislav Petkov <bp@...en8.de>
Cc: linux-kernel@...r.kernel.org, thomas.lendacky@....com, x86@...nel.org,
 kvm@...r.kernel.org, mingo@...hat.com, tglx@...utronix.de,
 dave.hansen@...ux.intel.com, dionnaglaze@...gle.com, pgonda@...gle.com,
 seanjc@...gle.com, pbonzini@...hat.com
Subject: Re: [PATCH v7 01/16] virt: sev-guest: Use AES GCM crypto library

On 1/25/2024 4:06 PM, Borislav Petkov wrote:
> On Wed, Dec 20, 2023 at 08:43:43PM +0530, Nikunj A Dadhania wrote:
>> @@ -307,11 +197,16 @@ static int verify_and_dec_payload(struct snp_guest_dev *snp_dev, void *payload,
>>  	 * If the message size is greater than our buffer length then return
>>  	 * an error.
>>  	 */
>> -	if (unlikely((resp_hdr->msg_sz + crypto->a_len) > sz))
>> +	if (unlikely((resp_hdr->msg_sz + ctx->authsize) > sz))
>>  		return -EBADMSG;
>>  
>>  	/* Decrypt the payload */
>> -	return dec_payload(snp_dev, resp, payload, resp_hdr->msg_sz + crypto->a_len);
>> +	memcpy(iv, &resp_hdr->msg_seqno, sizeof(resp_hdr->msg_seqno));
> 
> sizeof(iv) != sizeof(resp_hdr->msg_seqno) and it fits now.
> 
> However, for protection against future bugs, this should be:
> 
> 	memcpy(iv, &resp_hdr->msg_seqno, min(sizeof(iv), sizeof(resp_hdr->msg_seqno)));

Sure, will change.

> 
>> +	if (!aesgcm_decrypt(ctx, payload, resp->payload, resp_hdr->msg_sz,
>> +			    &resp_hdr->algo, AAD_LEN, iv, resp_hdr->authtag))
>> +		return -EBADMSG;
>> +
>> +	return 0;
>>  }
>>  
>>  static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8 type,
>> @@ -319,6 +214,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8
>>  {
>>  	struct snp_guest_msg *req = &snp_dev->secret_request;
>>  	struct snp_guest_msg_hdr *hdr = &req->hdr;
>> +	struct aesgcm_ctx *ctx = snp_dev->ctx;
>> +	u8 iv[GCM_AES_IV_SIZE] = {};
>>  
>>  	memset(req, 0, sizeof(*req));
>>  
>> @@ -338,7 +235,14 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8
>>  	dev_dbg(snp_dev->dev, "request [seqno %lld type %d version %d sz %d]\n",
>>  		hdr->msg_seqno, hdr->msg_type, hdr->msg_version, hdr->msg_sz);
>>  
>> -	return __enc_payload(snp_dev, req, payload, sz);
>> +	if (WARN_ON((sz + ctx->authsize) > sizeof(req->payload)))
>> +		return -EBADMSG;
>> +
>> +	memcpy(iv, &hdr->msg_seqno, sizeof(hdr->msg_seqno));
> 
> Ditto.

Sure.

> 
>> +	aesgcm_encrypt(ctx, req->payload, payload, sz, &hdr->algo, AAD_LEN,
>> +		       iv, hdr->authtag);
>> +
>> +	return 0;
> 

Thanks,
Nikunj


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ