From nobody Sat Nov 23 23:48:45 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1730754572; cv=none; d=zohomail.com; s=zohoarc; b=Y//yyVKpwBcdSmCYu/yBmR4yW34X34iCGhOusl9DARWXwIvPH/tVxeIfIJjG1EMgnfTXL62l4yPsw7V23Lg5BpWYoS+7Og/ynW0f6rVr892KoZOmNSxIms+qC5/XyAGehgHoUQX9J84seP8mLxiYrOCAgKQg4SZbheCV1n1/S4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730754572; h=Content-Type:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=+Qw3Qe8wV0ZOH6ROfQpES8yW2OtudwZHXLHI9Pq75U4=; b=ivvZEaNwWxEFyklRBeCnjAEs/X8/MEoRxW2mZWZpzPw8lhqtNJwkkGdv4u1HoyxcK+b1QnILlDKL/F6DZxifohdGPDG6a/F4dwl33jCdvRmGMN7OHQ89G7uOObxxavl5VEIt/0wQvdRzvD8kCsC1xWWAbOKzYqkr68ZC3YqZW3s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17307545728621015.6753463750397; Mon, 4 Nov 2024 13:09:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t84K3-0000Is-C1; Mon, 04 Nov 2024 16:09:15 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t84K0-0008Sz-Ql for qemu-devel@nongnu.org; Mon, 04 Nov 2024 16:09:13 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t84Jz-0005WO-7w for qemu-devel@nongnu.org; Mon, 04 Nov 2024 16:09:12 -0500 Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-177-lyK73HrcNHmClx3GtGYq0A-1; Mon, 04 Nov 2024 16:09:09 -0500 Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-37d4cf04bcfso2340520f8f.2 for ; Mon, 04 Nov 2024 13:09:09 -0800 (PST) Received: from redhat.com ([2.52.14.134]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381c10e7392sm14121373f8f.55.2024.11.04.13.09.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:09:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730754550; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=+Qw3Qe8wV0ZOH6ROfQpES8yW2OtudwZHXLHI9Pq75U4=; b=cjW3YhJo4eMYJc8dhjFEeSxnYITevv6zkIid2w++6xNDT7t3VC1cOZdJpv2pV/RDJh3LFQ S4pHJ+f7FHFz3Xt0Q2oRxJ1IjDXHtv4k0PsYh2Ju1p9uTvXyAEGaH5fdS63BVYYYausly8 +LGYwglQ6ouLntTmpqUtJwTrUZGV4F8= X-MC-Unique: lyK73HrcNHmClx3GtGYq0A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730754547; x=1731359347; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=+Qw3Qe8wV0ZOH6ROfQpES8yW2OtudwZHXLHI9Pq75U4=; b=iibHN5/cfwrUMU6mnczy6VWdOXmDApVDOkOqOwxKm0A54q22tFpbmgOYK5tW5ozitA TBzidQklelrZmvaQr84sXSUnI/l8jF52jon7MutHI3U/qpKf23FM5CfY2SmQ/BiMKjzl zBjdZF825jr3em0HOxzbM5zhkei4FtDmlH/pQlqFJ4ZmCv3AGaTM92KxcpAjs1uM2rxq 14RJOGA0Opp11ZmGucCCK52P8AXBFRb+9cLDMcG5HeRUREPFZnyQHJLUdj5RSU2wBs6S 8+6smxJ2GPdHukaXuAehGd6BHaiX1me+jOEo/8Xt838b3H6woViyqv6fHaCMYHu0px5Y OjOg== X-Gm-Message-State: AOJu0YwxM7gACGtTvPtDSifDJDGDNud5cXr37ELSBG3t3VX5ga0aoJZ9 k68NjbQRzqZOBQJWqTZUd28gK9uIxG6VpFbTtb/UY9UwtKXeAt/yH3ES5tvbyWB3U0Ec0/v4mN7 CcqKM9xLU0nZH2jFVus9OCkSbmeb7izam9vmAPMh2C5WXHS1nTPH2C/fWtPwr2gapPDKY9yI3Fb FkMCUiNGtLaZ1KVKbcDfAzutP2Isr8YQ== X-Received: by 2002:a5d:6c63:0:b0:37d:3973:cb8d with SMTP id ffacd0b85a97d-381c7a5e9d5mr10879861f8f.24.1730754547277; Mon, 04 Nov 2024 13:09:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IEo6Rpo8Gsz0VvSJGu4BEwEmEsgBRwuTYZz22CLisHkg0ZRK6VwkjSrwpkk48lweqKCbpSQ2g== X-Received: by 2002:a5d:6c63:0:b0:37d:3973:cb8d with SMTP id ffacd0b85a97d-381c7a5e9d5mr10879838f8f.24.1730754546785; Mon, 04 Nov 2024 13:09:06 -0800 (PST) Date: Mon, 4 Nov 2024 16:09:03 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Esifiel , Fan Ni Subject: [PULL 54/65] hw/cxl: Check that writes do not go beyond end of target attributes Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -23 X-Spam_score: -2.4 X-Spam_bar: -- X-Spam_report: (-2.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.34, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1730754573685116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jonathan Cameron In cmd_features_set_feature() the an offset + data size schemed is used to allow for large features. Ensure this does not write beyond the end fo the buffers used to accumulate the full feature attribute set. Reported-by: Esifiel Signed-off-by: Jonathan Cameron Message-Id: <20241101133917.27634-9-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/cxl/cxl-mailbox-utils.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index a40d81219c..078782e8b9 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -1292,6 +1292,11 @@ static CXLRetCode cmd_features_set_feature(const str= uct cxl_cmd *cmd, =20 ps_set_feature =3D (void *)payload_in; ps_write_attrs =3D &ps_set_feature->feat_data; + + if ((uint32_t)hdr->offset + bytes_to_copy > + sizeof(ct3d->patrol_scrub_wr_attrs)) { + return CXL_MBOX_INVALID_PAYLOAD_LENGTH; + } memcpy((uint8_t *)&ct3d->patrol_scrub_wr_attrs + hdr->offset, ps_write_attrs, bytes_to_copy); @@ -1314,6 +1319,11 @@ static CXLRetCode cmd_features_set_feature(const str= uct cxl_cmd *cmd, =20 ecs_set_feature =3D (void *)payload_in; ecs_write_attrs =3D ecs_set_feature->feat_data; + + if ((uint32_t)hdr->offset + bytes_to_copy > + sizeof(ct3d->ecs_wr_attrs)) { + return CXL_MBOX_INVALID_PAYLOAD_LENGTH; + } memcpy((uint8_t *)&ct3d->ecs_wr_attrs + hdr->offset, ecs_write_attrs, bytes_to_copy); --=20 MST