All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fan Ni <nifan.cxl@gmail.com>
To: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: "Michael S . Tsirkin" <mst@redhat.com>,
	linux-cxl@vger.kernel.org,
	Peter Maydell <peter.maydell@linaro.org>,
	shiju.jose@huwei.com, qemu-devel@nongnu.org, linuxarm@huawei.com
Subject: Re: [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature()
Date: Mon, 11 Nov 2024 14:37:35 -0800	[thread overview]
Message-ID: <ZzKHL9msnqMSv8WE@fan> (raw)
In-Reply-To: <20241108175814.1248278-1-Jonathan.Cameron@huawei.com>

On Fri, Nov 08, 2024 at 05:58:14PM +0000, Jonathan Cameron wrote:
> Zero length data for features doesn't make any sense so exclude that case
> early. This fixes the undefined behavior reported by coverity for a zero
> length memcpy().
> 
> Resolves CID 1564900 and 1564901
> 
> Reported-by: Peter Maydell <peter.maydell@linaro.org>
> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> ---
>  hw/cxl/cxl-mailbox-utils.c | 4 ++++
>  1 file changed, 4 insertions(+)

Reviewed-by: Fan Ni <fan.ni@samsung.com>

> 
> diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c
> index 2d4d62c454..ce9aa18364 100644
> --- a/hw/cxl/cxl-mailbox-utils.c
> +++ b/hw/cxl/cxl-mailbox-utils.c
> @@ -1288,6 +1288,10 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,
>      set_feat_info->data_offset = hdr->offset;
>      bytes_to_copy = len_in - sizeof(CXLSetFeatureInHeader);
>  
> +    if (bytes_to_copy == 0) {
> +        return CXL_MBOX_INVALID_PAYLOAD_LENGTH;
> +    }
> +
>      if (qemu_uuid_is_equal(&hdr->uuid, &patrol_scrub_uuid)) {
>          if (hdr->version != CXL_MEMDEV_PS_SET_FEATURE_VERSION) {
>              return CXL_MBOX_UNSUPPORTED;

-- 
Fan Ni

  reply	other threads:[~2024-11-11 22:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-08 17:58 [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature() Jonathan Cameron
2024-11-08 17:58 ` Jonathan Cameron via
2024-11-11 22:37 ` Fan Ni [this message]
2024-11-12  9:11 ` Shiju Jose

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=ZzKHL9msnqMSv8WE@fan \
    --to=nifan.cxl@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=mst@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=shiju.jose@huwei.com \
    /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.