All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peter Fang" <peter.fang@intel.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size
Date: Wed, 29 Jul 2026 12:58:28 +0000	[thread overview]
Message-ID: <20260729125829.52EA71F00A3E@smtp.kernel.org> (raw)
In-Reply-To: <20260729122939.1340412-4-peter.fang@intel.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] `wait_for_quote_completion` timeout logic is inverted due to an off-by-one error in the loop condition.
--

--- Patch [3]: [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size ---
commit 0a36558aa4f35238ff748cfc6efbe53e1e0e02ea
Author: Peter Fang <peter.fang@intel.com>

virt: tdx-guest: Use a variable to store the Quote buffer size

This commit replaces the fixed GET_QUOTE_BUF_SIZE constant with a dynamic 
variable to prepare for future dynamic Quote buffer sizes. All users of 
the buffer size have been updated to read from this new variable.

> diff --git a/drivers/virt/coco/tdx-guest/tdx-guest.c b/drivers/virt/coco/tdx-guest/tdx-guest.c
> index f47c5429d002e..3d3f79ab45af0 100644
> --- a/drivers/virt/coco/tdx-guest/tdx-guest.c
> +++ b/drivers/virt/coco/tdx-guest/tdx-guest.c
[ ... ]
> @@ -285,7 +284,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)
>  	if (desc->inblob_len != TDX_REPORTDATA_LEN)
>  		return -EINVAL;
>  
> -	memset(quote_data, 0, GET_QUOTE_BUF_SIZE);
> +	memset(quote_data, 0, quote_data_len);
>  
>  	/* Update Quote buffer header */
>  	quote_buf->version = GET_QUOTE_CMD_VER;
> @@ -296,7 +295,7 @@ static int tdx_report_new_locked(struct tsm_report *report, void *data)
>  	if (ret)
>  		return ret;
>  
> -	err = tdx_hcall_get_quote(quote_data, GET_QUOTE_BUF_SIZE);
> +	err = tdx_hcall_get_quote(quote_data, quote_data_len);
>  	if (err) {
>  		pr_err("GetQuote hypercall failed, status:%llx\n", err);
>  		return -EIO;
>  	}

[Severity: High]
This is a pre-existing issue, but while reviewing this code I noticed a 
logic flaw in wait_for_quote_completion() which is called immediately after 
this hypercall.

drivers/virt/coco/tdx-guest/tdx-guest.c:wait_for_quote_completion() {
    ...
    while (quote_buf->status == GET_QUOTE_IN_FLIGHT && i++ < timeout) {
        if (msleep_interruptible(MSEC_PER_SEC))
            return -EINTR;
    }

    return (i == timeout) ? -ETIMEDOUT : 0;
}

Does this timeout condition return the correct value?

Due to the post-increment in i++ < timeout, if the loop actually times out,
i becomes timeout + 1. This causes i == timeout to evaluate to false and
incorrectly return 0 (success).

Conversely, if the quote succeeds exactly on the last iteration,
short-circuiting leaves i == timeout true, which would incorrectly return
-ETIMEDOUT and cause a valid quote to be rejected.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260729122939.1340412-1-peter.fang@intel.com?part=3

  reply	other threads:[~2026-07-29 12:58 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29 12:29 [PATCH v3 0/4] tdx-guest: Make Quote buffer size dynamic Peter Fang
2026-07-29 12:29 ` [PATCH v3 1/4] x86/tdx: Add helper to query maximum TD Quote size Peter Fang
2026-07-29 12:29 ` [PATCH v3 2/4] virt: tdx-guest: Calculate the Quote buffer size safely Peter Fang
2026-07-29 18:29   ` Kuppuswamy Sathyanarayanan
2026-07-29 12:29 ` [PATCH v3 3/4] virt: tdx-guest: Use a variable to store the Quote buffer size Peter Fang
2026-07-29 12:58   ` sashiko-bot [this message]
2026-07-29 18:47   ` Kuppuswamy Sathyanarayanan
2026-07-29 12:29 ` [PATCH v3 4/4] virt: tdx-guest: Allocate Quote buffer dynamically Peter Fang
2026-07-29 12:55   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260729125829.52EA71F00A3E@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=peter.fang@intel.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.