Linux CXL
 help / color / mirror / Atom feed
* [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature()
@ 2024-11-08 17:58 Jonathan Cameron
  2024-11-11 22:37 ` Fan Ni
  2024-11-12  9:11 ` Shiju Jose
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Cameron @ 2024-11-08 17:58 UTC (permalink / raw)
  To: Michael S . Tsirkin, Fan Ni, linux-cxl, Peter Maydell, shiju.jose,
	qemu-devel
  Cc: linuxarm

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(+)

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;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature()
  2024-11-08 17:58 [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature() Jonathan Cameron
@ 2024-11-11 22:37 ` Fan Ni
  2024-11-12  9:11 ` Shiju Jose
  1 sibling, 0 replies; 3+ messages in thread
From: Fan Ni @ 2024-11-11 22:37 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael S . Tsirkin, linux-cxl, Peter Maydell, shiju.jose,
	qemu-devel, linuxarm

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature()
  2024-11-08 17:58 [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature() Jonathan Cameron
  2024-11-11 22:37 ` Fan Ni
@ 2024-11-12  9:11 ` Shiju Jose
  1 sibling, 0 replies; 3+ messages in thread
From: Shiju Jose @ 2024-11-12  9:11 UTC (permalink / raw)
  To: Jonathan Cameron, Michael S . Tsirkin, Fan Ni,
	linux-cxl@vger.kernel.org, Peter Maydell, shiju.jose@huwei.com
  Cc: Linuxarm

>-----Original Message-----
>From: qemu-devel-bounces+shiju.jose=huawei.com@nongnu.org <qemu-devel-
>bounces+shiju.jose=huawei.com@nongnu.org> On Behalf Of Jonathan Cameron
>via
>Sent: 08 November 2024 17:58
>To: Michael S . Tsirkin <mst@redhat.com>; Fan Ni <fan.ni@samsung.com>;
>linux-cxl@vger.kernel.org; Peter Maydell <peter.maydell@linaro.org>;
>shiju.jose@huwei.com; qemu-devel@nongnu.org
>Cc: Linuxarm <linuxarm@huawei.com>
>Subject: [PATCH qemu] hw/cxl: Check for zero length features in
>cmd_features_set_feature()
>
>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(+)
>
Tested-by: Shiju Jose <shiju.jose@huawei.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;
>--
>2.43.0
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-12  9:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-08 17:58 [PATCH qemu] hw/cxl: Check for zero length features in cmd_features_set_feature() Jonathan Cameron
2024-11-11 22:37 ` Fan Ni
2024-11-12  9:11 ` Shiju Jose

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox