Skip to content

Commit dd093fb

Browse files
tlendackybp3tk0v
authored andcommitted
virt/sev-guest: Return -EIO if certificate buffer is not large enough
Commit 47894e0 ("virt/sev-guest: Prevent IV reuse in the SNP guest driver") changed the behavior associated with the return value when the caller does not supply a large enough certificate buffer. Prior to the commit a value of -EIO was returned. Now, 0 is returned. This breaks the established ABI with the user. Change the code to detect the buffer size error and return -EIO. Fixes: 47894e0 ("virt/sev-guest: Prevent IV reuse in the SNP guest driver") Reported-by: Larry Dewey <[email protected]> Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Tested-by: Larry Dewey <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/2afbcae6daf13f7ad5a4296692e0a0fe1bc1e4ee.1677083979.git.thomas.lendacky@amd.com
1 parent e02b50c commit dd093fb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

drivers/virt/coco/sev-guest/sev-guest.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,26 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in
377377
snp_dev->input.data_npages = certs_npages;
378378
}
379379

380+
/*
381+
* Increment the message sequence number. There is no harm in doing
382+
* this now because decryption uses the value stored in the response
383+
* structure and any failure will wipe the VMPCK, preventing further
384+
* use anyway.
385+
*/
386+
snp_inc_msg_seqno(snp_dev);
387+
380388
if (fw_err)
381389
*fw_err = err;
382390

391+
/*
392+
* If an extended guest request was issued and the supplied certificate
393+
* buffer was not large enough, a standard guest request was issued to
394+
* prevent IV reuse. If the standard request was successful, return -EIO
395+
* back to the caller as would have originally been returned.
396+
*/
397+
if (!rc && err == SNP_GUEST_REQ_INVALID_LEN)
398+
return -EIO;
399+
383400
if (rc) {
384401
dev_alert(snp_dev->dev,
385402
"Detected error from ASP request. rc: %d, fw_err: %llu\n",
@@ -395,9 +412,6 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in
395412
goto disable_vmpck;
396413
}
397414

398-
/* Increment to new message sequence after payload decryption was successful. */
399-
snp_inc_msg_seqno(snp_dev);
400-
401415
return 0;
402416

403417
disable_vmpck:

0 commit comments

Comments
 (0)