Re: [PATCH v7 3/4] virt: sev-guest: Remove err in handle_guest_request
From: Peter Gonda
Date: Fri Nov 04 2022 - 17:47:52 EST
On Fri, Nov 4, 2022 at 2:16 PM Dionna Glaze <dionnaglaze@xxxxxxxxxx> wrote:
>
> The err variable may not be set in the call to snp_issue_guest_request,
> yet it is unconditionally written back to fw_err if fw_err is non-null.
> This is undefined behavior, and currently returns uninitialized kernel
> stack memory to user space.
>
> The fw_err argument is better to just pass through to
> snp_issue_guest_request, so we do that. Since the issue_request's
> signature has changed fw_err to exitinfo2, we change the argument name
> here.
>
> Cc: Tom Lendacky <Thomas.Lendacky@xxxxxxx>
> Cc: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> Cc: Joerg Roedel <jroedel@xxxxxxx>
> Cc: Peter Gonda <pgonda@xxxxxxxxxx>
> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
> Cc: Borislav Petkov <bp@xxxxxxx>
> Cc: Haowen Bai <baihaowen@xxxxxxxxx>
> Cc: Liam Merwick <liam.merwick@xxxxxxxxxx>
> Cc: Yang Yingliang <yangyingliang@xxxxxxxxxx>
>
> Fixes: fce96cf04430 ("virt: Add SEV-SNP guest driver")
> Signed-off-by: Dionna Glaze <dionnaglaze@xxxxxxxxxx>
> ---
> drivers/virt/coco/sev-guest/sev-guest.c | 14 +++++---------
> 1 file changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/virt/coco/sev-guest/sev-guest.c b/drivers/virt/coco/sev-guest/sev-guest.c
> index d08ff87c2dac..5ebf87651299 100644
> --- a/drivers/virt/coco/sev-guest/sev-guest.c
> +++ b/drivers/virt/coco/sev-guest/sev-guest.c
> @@ -322,9 +322,8 @@ static int enc_payload(struct snp_guest_dev *snp_dev, u64 seqno, int version, u8
>
> static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, int msg_ver,
> u8 type, void *req_buf, size_t req_sz, void *resp_buf,
> - u32 resp_sz, __u64 *fw_err)
> + u32 resp_sz, __u64 *exitinfo2)
I was off before, but handle_guest_request() is actually the function
Borislav suggested tweaking. Why don't we update
handle_guest_request() to take snp_guest_request_ioctl here since we
are already updating all the call sites in the next patch.