From nobody Sat Jul 25 02:34:26 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E78593BCD0D for ; Mon, 20 Jul 2026 13:44:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784555100; cv=none; b=BwXeER1ATxRHi4WFSj00nFuWlA+WsFDEuLY/0pBqmy0Y4Ul9G42rZkA8tJB51A/2P+Nxy0RcltmxwR9ZN33ywguj3XxpBqpGcTmxP5DokKBnb0MuNdB6wp4OPJE6qIogLIof01Yh2dpaxs2CydHCSURJCzoIopC+Ccr7QRjtdn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784555100; c=relaxed/simple; bh=SpXvCRsLS26PMst73oG6Sh2eYmkKAEv4+NoYGhVhDTw=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=h4NYZ7c3QKMxjawuby/GVE6CWrlLZUUI9eveT6oUUGbk6DwFzO9U0OLlRz/AtRp/1n25It63k5V8S4uf9L83qjzTfJ89wLCTmErUyBTYfyNtD83t7AKGYy2GqiRYzaKJvc2PlVkJy0vQXIgg+o8zbgaSTq/QwCJNefKyr3s5TRs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c36+cW3l; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c36+cW3l" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-493b966dd74so42807315e9.3 for ; Mon, 20 Jul 2026 06:44:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784555095; x=1785159895; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=TZl1SyHTfE2VJ6SL46lxQ8jIIKDocPqnasYj5shzWDs=; b=c36+cW3lVvZ+aad0ymFUqU7jKYa6UgHu8orrjQUTozHjQCzXDYqjJRHdY/xp18t1he awm9c470jvkFZvClxUTDH0QK3BvzbQlB0W/L0YFmQidJPTjqVKDtnp0ka/tNW6dil4gd X4nematGC5WaukXtF2I6P2FzbU+9QJcbCe1b5oqNbcekOqFNX4gYoIoEHH1mhDC1NY38 ON6d7PYIaohgqJtWeBSy/FAxG+fHRS2RSPbeYZYJMnll+iSLTbMuyPGtLLWnvI/o0NS9 4k3ysqsLjfIf6tm011vfXHtB+BkzWx9uT000nKeYfDFqWSPzZ12ElfCSrDSVPZEKTpa1 /0yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784555095; x=1785159895; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=TZl1SyHTfE2VJ6SL46lxQ8jIIKDocPqnasYj5shzWDs=; b=R78LH/37G0qPEjDa3O/NUQABEwxTeUWBT3TMP1mO5YRMWpcIgj5JtWl/02o1pZO2GH oLvnYabxjLgal37EpuM92KkAATi+dI80YLkvkxXWJWrWdtcFZCRP+GEoCFEJo34AnqVR 7XZsPdsFuuos5+sywtT2BaVGxNjcO+KaaWLqPnZ/y3fP6uvutdToI5Uux2qO9npjVcg0 x2EOaF8bT7FA3azLoTRhFpoGI4TYRXNVME2IOpGv9XffJrI3ULp3hWLQdFcjaZMjARSv UakGvMBCzTkcJ8W4ZUmnRhlWjfMtdTw3wCrUsUD/8HRgwM4gCAI5z/tqfkiNR4TmqZXH jx1Q== X-Forwarded-Encrypted: i=1; AHgh+RqOKRA0rX/xntE2zaYEchWziqZQgRt1WsBBHHlui7hgc4HLUhxv9QMRyNHnPlbcQsH3A6Cme+jaU2twwEc=@vger.kernel.org X-Gm-Message-State: AOJu0YxGLxHx/4pDsF9UZzBwgkEA+cfotTWnRkwtGv96k1t+R0fqnSKv tb3WsXgs57Yo1B1lHWtbU+99tEEW7X0ScCF1pQxnYn5zHbDJzNWE/8Z16GXBjg== X-Gm-Gg: AfdE7ckWv/aIoABrJJglsWyHU/fs11QS2cDXQq740GraVw0u3rK3zZFWWZBvrCqrz/l pCZxaBKauTzVI5AhZiQzKc6ZXR6rXsLKWDb6GCSlRK65J1VKXjNBT4pqrm+U90d7wBuhI3Tu4JQ Sr6hiR43z+s9EfW6660Ab1Rc6puBxcal73rZ7z1LI5jKVgQxBVlbq9nOKmzo1OD6QH1Et9VqIwj 8bA2f17JhTGySqxAZjtPVtDMQE/FojPbIKu8sNzmXD350jaPaL/QDOZlcVM0LvV0vdiV90Bgn+u obQTKLuh19uSfVTwPaYV0OLUbeCPVjpU0wEgzDnqwxhFyjYkgMq3SRVuLhQB+xDAxxtpasA9ABe V1O8KNEglQQ0NjHBXjvGKaoV4zgBJdf2me3ZTk4n1y5nH1Y6pHiMqJq+xedw6CSBgDW1ICWFnTr 0RB21KYpOpqRyu74mBuBkeKaDjzm/40YedEOTxze0= X-Received: by 2002:a05:600c:3b1b:b0:495:443b:1bbb with SMTP id 5b1f17b1804b1-4954a50c473mr146050565e9.25.1784555094606; Mon, 20 Jul 2026 06:44:54 -0700 (PDT) Received: from osama.. ([2a02:908:185:7e40:177b:1470:c99b:b6d9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a3f07esm272678615e9.6.2026.07.20.06.44.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jul 2026 06:44:53 -0700 (PDT) From: Osama Abdelkader To: Boris Brezillon , Steven Price , Liviu Dudau , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Heiko Stuebner , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Cc: Osama Abdelkader , stable@vger.kernel.org Subject: [PATCH] drm/panthor: fix firmware control interface bounds checks Date: Mon, 20 Jul 2026 15:44:35 +0200 Message-ID: <20260720134435.13377-1-osama.abdelkader@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" panthor_init_cs_iface() and panthor_init_csg_iface() validate firmware control interface offsets with 32-bit arithmetic and the size of the host wrapper structures. The offsets are derived from firmware-provided strides, so the arithmetic can wrap before the bounds check, and the host wrapper size is not the size of the firmware control interface being mapped. Use 64-bit arithmetic for the computed offsets and validate against the actual firmware control interface structure sizes with subtraction-based bounds checks. Also validate that the shared section is large enough for the global control interface before using it. Fixes: 2718d91816ee ("drm/panthor: Add the FW logical block") Cc: stable@vger.kernel.org Signed-off-by: Osama Abdelkader --- drivers/gpu/drm/panthor/panthor_fw.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/panthor/panthor_fw.c b/drivers/gpu/drm/panthor= /panthor_fw.c index eee2bc7e8541..e2fcbd639c3c 100644 --- a/drivers/gpu/drm/panthor/panthor_fw.c +++ b/drivers/gpu/drm/panthor/panthor_fw.c @@ -897,15 +897,16 @@ static int panthor_init_cs_iface(struct panthor_devic= e *ptdev, struct panthor_fw_csg_iface *csg_iface =3D panthor_fw_get_csg_iface(ptdev= , csg_idx); struct panthor_fw_cs_iface *cs_iface =3D &ptdev->fw->iface.streams[csg_id= x][cs_idx]; u64 shared_section_sz =3D panthor_kernel_bo_size(ptdev->fw->shared_sectio= n->mem); - u32 iface_offset =3D CSF_GROUP_CONTROL_OFFSET + - (csg_idx * glb_iface->control->group_stride) + + u64 iface_offset =3D CSF_GROUP_CONTROL_OFFSET + + ((u64)csg_idx * glb_iface->control->group_stride) + CSF_STREAM_CONTROL_OFFSET + - (cs_idx * csg_iface->control->stream_stride); + ((u64)cs_idx * csg_iface->control->stream_stride); struct panthor_fw_cs_iface *first_cs_iface =3D panthor_fw_get_cs_iface(ptdev, 0, 0); =20 - if (iface_offset + sizeof(*cs_iface) >=3D shared_section_sz) + if (iface_offset > shared_section_sz || + sizeof(*cs_iface->control) > shared_section_sz - iface_offset) return -EINVAL; =20 spin_lock_init(&cs_iface->lock); cs_iface->control =3D ptdev->fw->shared_section->mem->kmap + iface_offset; @@ -955,11 +956,13 @@ static int panthor_init_csg_iface(struct panthor_devi= ce *ptdev, struct panthor_fw_global_iface *glb_iface =3D panthor_fw_get_glb_iface(pt= dev); struct panthor_fw_csg_iface *csg_iface =3D &ptdev->fw->iface.groups[csg_i= dx]; u64 shared_section_sz =3D panthor_kernel_bo_size(ptdev->fw->shared_sectio= n->mem); - u32 iface_offset =3D CSF_GROUP_CONTROL_OFFSET + (csg_idx * glb_iface->con= trol->group_stride); + u64 iface_offset =3D CSF_GROUP_CONTROL_OFFSET + + ((u64)csg_idx * glb_iface->control->group_stride); unsigned int i; =20 - if (iface_offset + sizeof(*csg_iface) >=3D shared_section_sz) + if (iface_offset > shared_section_sz || + sizeof(*csg_iface->control) > shared_section_sz - iface_offset) return -EINVAL; =20 spin_lock_init(&csg_iface->lock); csg_iface->control =3D ptdev->fw->shared_section->mem->kmap + iface_offse= t; @@ -1011,12 +1014,16 @@ static u32 panthor_get_instr_features(struct pantho= r_device *ptdev) static int panthor_fw_init_ifaces(struct panthor_device *ptdev) { struct panthor_fw_global_iface *glb_iface =3D &ptdev->fw->iface.global; + u64 shared_section_sz =3D panthor_kernel_bo_size(ptdev->fw->shared_sectio= n->mem); unsigned int i; =20 if (!ptdev->fw->shared_section->mem->kmap) return -EINVAL; =20 + if (sizeof(*glb_iface->control) > shared_section_sz) + return -EINVAL; + spin_lock_init(&glb_iface->lock); glb_iface->control =3D ptdev->fw->shared_section->mem->kmap; =20 if (!glb_iface->control->version) { --=20 2.43.0