From nobody Sat Nov 23 22:23:02 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=1730754838; cv=none; d=zohomail.com; s=zohoarc; b=IPFIAWWZ37Ye0o1Plcy+ocEuBJLWl3YZCGKpnB55XUS4cz+pUzB8u5eniWvmfwFdYdE7Hi1UEy58dZmjJyP56j3uo29C0P1BEeNHTA4ma52mIWSRFyKr+H71NcqaH+r1OJdsulXEOffmwQbfB0wI7DOzdnIWmS3KB0igvatCDUg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1730754838; 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=z8mjCAYRXCtl4i5x731E2QWqLSQ+blqkHsX/35ib1TE=; b=H/3/Wa8xL4qageSXxSeNQrwvuAaEyJ5bQEYh/Oi8uzI4GuorJf6BHdzd919hsPOEWrh4JZLw/Pkymq8PQfJpzGUVXBtkTNAbf8wD8meZPXBxiIeZIzTW2wzP0u4Vekjpo5EnXDmzHe8Mpanss3sp8L7v7IYyY2tsc4130xjsrag= 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 1730754838071220.10105149999856; Mon, 4 Nov 2024 13:13:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t84KA-000140-Hl; Mon, 04 Nov 2024 16:09:22 -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 1t84K8-0000wQ-J2 for qemu-devel@nongnu.org; Mon, 04 Nov 2024 16:09:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1t84K7-0005X1-2F for qemu-devel@nongnu.org; Mon, 04 Nov 2024 16:09:20 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-192-FY0PbRVZNRSO4HWPtcHqQQ-1; Mon, 04 Nov 2024 16:09:16 -0500 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4315e8e9b1cso27297275e9.1 for ; Mon, 04 Nov 2024 13:09:16 -0800 (PST) Received: from redhat.com ([2.52.14.134]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4327d5ac002sm164216815e9.5.2024.11.04.13.09.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Nov 2024 13:09:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1730754557; 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=z8mjCAYRXCtl4i5x731E2QWqLSQ+blqkHsX/35ib1TE=; b=A34QkXLyj7k8va6cXHfioEKBG9kcAsT8pFIo1xBeUhu8wXiqSt2rHGjs0ThOzn5T43yeLq 4Oa9jn4lnOtw9kWHihF5BoJZy46o2CHKwE7cvMwyKNBcb8fjUHsyaxTCcRAf07rF/OI0RU g6UOO/J7WALAMM0k77nc929c8ykXD+c= X-MC-Unique: FY0PbRVZNRSO4HWPtcHqQQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730754555; x=1731359355; 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=z8mjCAYRXCtl4i5x731E2QWqLSQ+blqkHsX/35ib1TE=; b=BEcKQDYusjtFS+EXwXjSv2kHqo9hZLU5kIOyMjU6k79aXB/aYsU3TEX6U96JyTXk+2 //nYeL0f4y271gFw1Gus8xsvKhGnm8MrO9vmzTCTHUUJYMcUgjuLUpbiAbHU170iMvFS Yd6JjJYtjXCKVrkvFvvEtQkwGYopXArQyf+71PlVK0rrpUp6W8dTg9twE0Oz/d4FBDnA Io8uCtKwTvR5C1Ak0YMhl8w6IztbxfFkevS1oBSFqWMkJiRvsocOG7nA8frjpaIwkJkL ThazhJ40jZZZEtTZ2J42dQuCDXoVc+Ip2SjZutJBeCLf8Om1Wohj4PFe4srGHrr9vPB/ xHMA== X-Gm-Message-State: AOJu0YxV66czLlIK6bzYRHLbsEQFDUWKk49VfWGhttvbol7lTWbyJ3SK IPAktqFG7rZYgzro5vz8VXmvb4yWfp2TO26N/XIe4heyHiqbQe7IFawcTOgJ28GNwfn8bL8ci2C BMDoqM+1T6ewZ7Bgecyync+GY1I4c5Y+ck90WKCp5tEbxd22X1JOvm2PF7PCxL2/lA1M5ZnLae+ 1Cnr64IeO8n/UynXM7w7FjkGOmsQGbbQ== X-Received: by 2002:a05:600c:1382:b0:431:5475:3cd1 with SMTP id 5b1f17b1804b1-4327dacc373mr122768585e9.17.1730754554797; Mon, 04 Nov 2024 13:09:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IE9OxVsWEUkkxztFDINuwekKPZehgtJpRIpJYkMWxO6+XhnNGH3YGJU36vfpcI+EJq92UN0+g== X-Received: by 2002:a05:600c:1382:b0:431:5475:3cd1 with SMTP id 5b1f17b1804b1-4327dacc373mr122768395e9.17.1730754554404; Mon, 04 Nov 2024 13:09:14 -0800 (PST) Date: Mon, 4 Nov 2024 16:09:10 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Jonathan Cameron , Esifiel , Fan Ni Subject: [PULL 56/65] hw/cxl: Ensure there is enough data to read the input header in cmd_get_physical_port_state() Message-ID: <721c99aefcdb311bd41d20678d3935fd11454641.1730754238.git.mst@redhat.com> 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.133.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_H3=0.001, RCVD_IN_MSPIKE_WL=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: 1730754838887116600 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Jonathan Cameron If len_in is smaller than the header length then the accessing the number of ports will result in an out of bounds access. Add a check to avoid this. Reported-by: Esifiel Signed-off-by: Jonathan Cameron Message-Id: <20241101133917.27634-11-Jonathan.Cameron@huawei.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/cxl/cxl-mailbox-utils.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hw/cxl/cxl-mailbox-utils.c b/hw/cxl/cxl-mailbox-utils.c index f4a436e172..2d4d62c454 100644 --- a/hw/cxl/cxl-mailbox-utils.c +++ b/hw/cxl/cxl-mailbox-utils.c @@ -530,6 +530,9 @@ static CXLRetCode cmd_get_physical_port_state(const str= uct cxl_cmd *cmd, in =3D (struct cxl_fmapi_get_phys_port_state_req_pl *)payload_in; out =3D (struct cxl_fmapi_get_phys_port_state_resp_pl *)payload_out; =20 + if (len_in < sizeof(*in)) { + return CXL_MBOX_INVALID_PAYLOAD_LENGTH; + } /* Check if what was requested can fit */ if (sizeof(*out) + sizeof(*out->ports) * in->num_ports > cci->payload_= max) { return CXL_MBOX_INVALID_INPUT; --=20 MST