{"id":2224133,"url":"http://patchwork.ozlabs.org/api/patches/2224133/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260416200702.2374709-3-git@aaronesau.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260416200702.2374709-3-git@aaronesau.com>","list_archive_url":null,"date":"2026-04-16T20:07:02","name":"[2/2] hw/cxl: add missing bounds checks in Set Feature for PPR and sparing","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"13e9f6ad71386eabd2fe4520c78bc2febc61c979","submitter":{"id":93010,"url":"http://patchwork.ozlabs.org/api/people/93010/?format=json","name":"Aaron Esau","email":"aaron1esau@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260416200702.2374709-3-git@aaronesau.com/mbox/","series":[{"id":500210,"url":"http://patchwork.ozlabs.org/api/series/500210/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500210","date":"2026-04-16T20:07:00","name":"hw/cxl: Fix two OOB access bugs in CXL mailbox commands","version":1,"mbox":"http://patchwork.ozlabs.org/series/500210/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224133/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224133/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=oDpgxx9x;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxXwr4Xbbz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 08:38:36 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wDVLa-0007nc-W5; Thu, 16 Apr 2026 18:38:07 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <aaron1esau@gmail.com>)\n id 1wDSzq-00022x-6T\n for qemu-devel@nongnu.org; Thu, 16 Apr 2026 16:07:30 -0400","from mail-ot1-x329.google.com ([2607:f8b0:4864:20::329])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <aaron1esau@gmail.com>)\n id 1wDSzo-0000IL-7Q\n for qemu-devel@nongnu.org; Thu, 16 Apr 2026 16:07:29 -0400","by mail-ot1-x329.google.com with SMTP id\n 46e09a7af769-7dbcb45153cso1095689a34.3\n for <qemu-devel@nongnu.org>; Thu, 16 Apr 2026 13:07:27 -0700 (PDT)","from localhost ([136.49.184.116]) by smtp.gmail.com with ESMTPSA id\n 46e09a7af769-7dc90a5ef51sm633330a34.9.2026.04.16.13.07.26\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Thu, 16 Apr 2026 13:07:26 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1776370047; x=1776974847; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=p1WMxWJyeutL6cak8qb7wJqgMiroiOZ8xYTt72hdlKY=;\n b=oDpgxx9xZtVGiuxketHDxRymZbivvO37kZ+V08ms2IIhigr8FBTjLEw0B2nIBrb1Tc\n W9rz67KQ20E0f55Of6eCvkJC9FAn2yUaTtm51FBCJeJaP96ZnNoBvhyX9nqQRx75ptsK\n 0Q1PbUubHjbCtXBNRyB8lGtvKIuFILlIF0xsGGk2R+CY317Q79IKHPApNwFpujXzxV21\n DsH+WR1tzRydQfLnyH+XQhyy/p4Z7vmMsXaWq5MGxwGY4fLTqiAjXsQFZsMuvCxozvvI\n 4bzlt+of+eqDdPQ7rcRED3fTApVn2tK5+acatY8kSh55B7RP7mhdtUh5Ejn8q49Si9nP\n 8pDg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776370047; x=1776974847;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=p1WMxWJyeutL6cak8qb7wJqgMiroiOZ8xYTt72hdlKY=;\n b=cBcH2S/YKDEWgtWplVgYKN9ZfKlLcAJEV+Q3dQr3/Fs/1MrORdQZ17ObSVwEG6RCcB\n 46zpEu5Wg1TYlFtB4M7UZQZJJfKx97go3Rf74zeZfeykXP7omgyhJ2PDKY+7HbaBgrmt\n nQKXGp1nD7mZrmbb41cAuE6x+Lqho2DENgn0M54xFvOWWZthH2csBco9qZwgjxvzWwZg\n ESxnWW52pLGlcE0zou7Bh+jc6uCsLqE4Y1LLMnEcZwVVbuVTIMVNqt2w2pJ6rjc1w3YK\n j89oTCZhBCBkO7NoGE7uSyHJy4zBn+dzc+UAVuj9/GHBH8eHe3cNkqs52aEh9ffDcqck\n wM4w==","X-Gm-Message-State":"AOJu0YxudmCcReIm9TuLk98tOvWXTWlNesbxm7UXnGCfRFWpe88Qat2E\n ktOArds9MlXh3C/LslI1tb9fjmK6yh+Z8NULGotNPnwhr5u9OHFYu15Z+rABOaog","X-Gm-Gg":"AeBDievAnOWwE4JFR1mVQZ5ctpZIwilSS9kq8cPWHAf92jCnYzrSxsd6inGRZOmY0cj\n fQgrDYq38OHVV9iaWMLf/1HRkbOlNgoFnQYHdh3nM65Rm/h7j7v91qV2JsaIFj8KrKlJVGRfe5k\n WUy7chtyobKgBcsTpSIluNCr0TlQ5bpObhNyeEiY742MsfHA1xj5AGrmxhrX+iJ1i+AZD82nWc4\n Vsw3NrZ+Zo2ajHwA4n3+fRciwShIuQXzJ53yxAbvoN31RXvoL3d2FnNdoSyIFszIYkBX906boV9\n lyIkf+FnUuNaCQlcrawnNm7BR7Q17AcWaIQCjmymEx08iWUxQvB5G03/njpTbTN3jNgeucqAcam\n 4T9VNAH+l68lOpdrDBeMGCsZGuttbg6SaAtqw/Z5pi/DqXvqqHFirGdo7YXZg3j3QEEzzjJvvb1\n WmO7GSZBwt1bJxcQhJuEEyWqSh+DSqv5JdcH1aGW6eFhbvx3KGH+/m7yziDw4UZxEoQo3lk0H7s\n V6812JpXcmlJRc/w7FUgrZWECqaXNCbfpo=","X-Received":"by 2002:a05:6830:411d:b0:7d7:e695:93b8 with SMTP id\n 46e09a7af769-7dc926d2605mr324081a34.5.1776370046849;\n Thu, 16 Apr 2026 13:07:26 -0700 (PDT)","From":"Aaron Esau <aaron1esau@gmail.com>","X-Google-Original-From":"Aaron Esau <git@aaronesau.com>","To":"qemu-devel@nongnu.org","Cc":"Jonathan.Cameron@huawei.com, jic23@kernel.org, berrange@redhat.com,\n Aaron Esau <aaron1esau@gmail.com>, qemu-stable@nongnu.org","Subject":"[PATCH 2/2] hw/cxl: add missing bounds checks in Set Feature for PPR\n and sparing","Date":"Thu, 16 Apr 2026 15:07:02 -0500","Message-ID":"<20260416200702.2374709-3-git@aaronesau.com>","X-Mailer":"git-send-email 2.53.0","In-Reply-To":"<20260416200702.2374709-1-git@aaronesau.com>","References":"<20260416200702.2374709-1-git@aaronesau.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::329;\n envelope-from=aaron1esau@gmail.com; helo=mail-ot1-x329.google.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no","X-Spam_action":"no action","X-Mailman-Approved-At":"Thu, 16 Apr 2026 18:38:06 -0400","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"qemu development <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"From: Aaron Esau <aaron1esau@gmail.com>\n\ncmd_features_set_feature() is missing bounds validation on the offset and\ndata length for several feature UUIDs before their memcpy calls. The\npatrol_scrub and ecs cases correctly check:\n\n    if ((uint32_t)hdr->offset + bytes_to_copy >\n        sizeof(ct3d->..._wr_attrs))\n        return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n\nBut the soft_ppr, hard_ppr, cacheline_sparing, row_sparing,\nbank_sparing, and rank_sparing cases are missing this check. Since\nbytes_to_copy is derived from the full mailbox payload length (up to\n2048 bytes) and the write-attribute structs are only a few bytes each,\na guest can overflow into adjacent CXLType3Dev fields.\n\nAdd the same bounds check pattern to all six affected feature handlers.\n\nCc: qemu-stable@nongnu.org\nFixes: 5e5a86bab8 (\"hw/cxl: Add support for Maintenance command and Post Package Repair (PPR)\")\nFixes: da5cafdc4d (\"hw/cxl: Add emulation for memory sparing control feature\")\nReported-by: Aaron Esau <aaron1esau@gmail.com>\nSigned-off-by: Aaron Esau <aaron1esau@gmail.com>\n---\n hw/cxl/cxl-mailbox-utils.c | 30 ++++++++++++++++++++++++++++++\n 1 file changed, 30 insertions(+)","diff":"diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c\nindex 0adf1e72c8..5fabfcbbab 100644\n--- a/hw/cxl/cxl-mailbox-utils.c\n+++ b/hw/cxl/cxl-mailbox-utils.c\n@@ -1814,6 +1814,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->soft_ppr_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->soft_ppr_wr_attrs + hdr->offset,\n                sppr_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n@@ -1833,6 +1838,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->hard_ppr_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->hard_ppr_wr_attrs + hdr->offset,\n                hppr_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n@@ -1852,6 +1862,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->cacheline_sparing_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->cacheline_sparing_wr_attrs + hdr->offset,\n                mem_sparing_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n@@ -1870,6 +1885,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->row_sparing_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->row_sparing_wr_attrs + hdr->offset,\n                mem_sparing_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n@@ -1888,6 +1908,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->bank_sparing_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->bank_sparing_wr_attrs + hdr->offset,\n                mem_sparing_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n@@ -1906,6 +1931,11 @@ static CXLRetCode cmd_features_set_feature(const struct cxl_cmd *cmd,\n             return CXL_MBOX_UNSUPPORTED;\n         }\n \n+        if ((uint32_t)hdr->offset + bytes_to_copy >\n+            sizeof(ct3d->rank_sparing_wr_attrs)) {\n+            return CXL_MBOX_INVALID_PAYLOAD_LENGTH;\n+        }\n+\n         memcpy((uint8_t *)&ct3d->rank_sparing_wr_attrs + hdr->offset,\n                mem_sparing_write_attrs, bytes_to_copy);\n         set_feat_info->data_size += bytes_to_copy;\n","prefixes":["2/2"]}