From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 3A46E283FFB for ; Sun, 10 May 2026 20:18:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778444307; cv=none; b=RcQMxMFFqt+gBTtKJd4/VtYj+WjNzZLl95caGtncL0ACDnDmBpIghUQNFUc5k3sIeN7AOGra6vsxLv/u6lLzsH+jMccC/RhKrWCPLtLQpl14XQywCpxf1rjt7PAzdrguo/LB8QMsYSuHQY0QcL0hEin5RtK0nwf3Tf+xCsdOy1g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778444307; c=relaxed/simple; bh=no/1qeHJkclP/vqyRMHVtp/AFnakt9WfqICbC12BM5g=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=B3CoqFATfT7tcU1cBtl5TqCHjSkoJE+7Lj62RruW9/kvTE8Dd0XSgSRpWZfDIo1g2XzPvdSa96QlPOtmXMGiD2+NmZgY4iumtFqdbkGXbQ35UoqJ90TvA52/HyKkcjYIPgi/rTvXFy+Hx0En5wekGQacpsjZevoWBx3RSEOX964= 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=KNsOcX9m; arc=none smtp.client-ip=209.85.219.42 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="KNsOcX9m" Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-8b59772d441so37481286d6.0 for ; Sun, 10 May 2026 13:18:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778444304; x=1779049104; 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; bh=K67pIs/nY03A+3XziFzgPYzBlsoSwWL+5glnFKhN0Ic=; b=KNsOcX9mOEDPDam2QjjM6c90iLxrqDMQNOgN7akxUD9yRAZh9safcSjsHBnT9ZGJCw Q8R9Qz9SYgYXnNJ0/5Ru6t9mJw9Ntw7OQ4BzMrxGqr448iFPZ/nU8RoIxnA/VLshftlW wLwxn86VNyXGQt7rKvKNytqRIoCptrjjHFPW4C8gffX5qikodHm0nb3HoPdOOtrzFllz R9tzeajnVb/3rZMj4eWL8gPqUhv94vvOLv27VEguO4onR8qwyGesm1oZ49gcZaaNLULN nj9VzQYtBiz5vAtlvuaWMd5fIv6Tr0VsxfIHSctWn4BCBA4uORgxSiOtKYsaONuRJr8H WfhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778444304; x=1779049104; 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; bh=K67pIs/nY03A+3XziFzgPYzBlsoSwWL+5glnFKhN0Ic=; b=DzT0z7ORpwtD6PrCgVwnO08sSPPuAqFAdnlh4BpxWUSyYebPxANl1pvzjekYVVQjW2 M7q5O+LGW2fnruT8y9HmYkVYMMkcc/aOKJzZQmhPUZRZJw50vnxt/WSGPErqfrD2mqwF lh0U3CsMXCZmhoCZSS4pCWLIP+g2yRJMIrgbZTw7uDb6lAEFB3Y7+LPrNGw6mdTrIeCH Dm5hFuN9nSKG8Fya1RZr7wwgyks9AA6PwkJS5pMIQrW7nrU9VXQ+yavkaTxhqgAIhmRS wXxI44Y/xCeaAjWBCxLtxLRIWx0kE4eC+428hH+lPydMoEepgtuDxzxc9VIvk03g5QL+ b/DQ== X-Forwarded-Encrypted: i=1; AFNElJ8u/Xcw2iLZvA5hCBFh6IbRHj/tNiZ5XEDxK5/4GbgTouRyufDw00ZAKECrZSoqXQO69PxnDIZm+EHBbzQ=@vger.kernel.org X-Gm-Message-State: AOJu0YzWkh80lhsYgCqQ/yBG0hgjS6m4jHQuxFHNGDva/lTf0GdQSBg7 TH5ekeaK8/ldSgcwpjafShVndT1z3CfR4gyG8vrd9OxXxs/XxEkm99FQ X-Gm-Gg: Acq92OEB0pRBCR/1vpc/Sz9GpqKHh68Uf70QP1F74gESQxGGP23gVmx+n0mgIX/63y4 A+daArtPLz8/7WpjjyIsnUVFwvJ0pdjLB2FqnCYRp3Yqt2q/yHSHTzucCzxYJwZ7/q4uYWuLu+b g3sguhc8b/jK4mUCheCrop8w6P4Q609XedyjLt3/kX5N45nmu5agsV5KxrSXnkvbBFA3ujN6+Tr hNcwnPbStDI0NavJQfoibdCkVxcD8kHkQNl9DM4fqCfdnaFfsx4G2W7MEpiWIFK9ZLSiiKjnrjg X0IyN3/CAugiGoo9eXsGqFI/+WAvIdHJAF2IqbG4XZIi27lBijs0XWHBqaM9vn/QRh4heGioAUj q52Y01cKvqLZtCC8gWRUncW2718t5Jhk50wIc6X7VnbMpGj22Q9mbWVUytSOWeqNJfORYOfZ/eT dT0megbFXGcnVPLP0hzV+WVUxTADtcl6LxC93mOR1h21CS/gnO0zX/18HmG6UYd+p/J10F7XFzC grBSofcSqcZtmxQ6foz+RFsC72G X-Received: by 2002:a05:6214:5e03:b0:8bd:4bc7:e19 with SMTP id 6a1803df08f44-8bd4bc714d5mr285979606d6.47.1778444304161; Sun, 10 May 2026 13:18:24 -0700 (PDT) Received: from TDC4045031631.e0cglfehwr0e5gttmepj3hi3hf.ux.internal.cloudapp.net ([20.63.37.123]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8bf3a43636fsm76040566d6.21.2026.05.10.13.18.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 May 2026 13:18:23 -0700 (PDT) From: Ashutosh Desai To: dri-devel@lists.freedesktop.org Cc: stable@vger.kernel.org, lyude@redhat.com, airlied@gmail.com, daniel@ffwll.ch, maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, simona@ffwll.ch, linux-kernel@vger.kernel.org, Ashutosh Desai Subject: [PATCH v2] drm/dp/mst: fix OOB reads in remote DPCD/I2C sideband reply parsers Date: Sun, 10 May 2026 20:17:33 +0000 Message-Id: <20260510201733.2882224-1-ashutoshdesai993@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit drm_dp_sideband_parse_remote_dpcd_read() reads num_bytes from the raw message and then unconditionally does: memcpy(bytes, &raw->msg[idx], num_bytes); without checking that idx + num_bytes <= raw->curlen. raw->msg[] is 256 bytes; if a malicious or misbehaving MST hub sets num_bytes larger than the remaining payload, the memcpy reads past the received data into whatever follows in raw->msg[]. drm_dp_sideband_parse_remote_i2c_read_ack() has the same flaw (noted with a /* TODO check */ comment since the code was introduced). Fix both functions by using a single combined check (idx + num_bytes > curlen) before each memcpy. Since num_bytes is u8, it is always >= 0, so this strictly subsumes the simpler idx > curlen form and no separate step is needed. Cc: stable@vger.kernel.org Signed-off-by: Ashutosh Desai --- Changes in v2: - Drop separate idx > curlen check; idx + num_bytes > curlen with u8 num_bytes (always >= 0) strictly subsumes it (Lyude Paul) drivers/gpu/drm/display/drm_dp_mst_topology.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/display/drm_dp_mst_topology.c b/drivers/gpu/drm/display/drm_dp_mst_topology.c index 170113520a43..9416a48804c8 100644 --- a/drivers/gpu/drm/display/drm_dp_mst_topology.c +++ b/drivers/gpu/drm/display/drm_dp_mst_topology.c @@ -871,7 +871,7 @@ static bool drm_dp_sideband_parse_remote_dpcd_read(struct drm_dp_sideband_msg_rx goto fail_len; repmsg->u.remote_dpcd_read_ack.num_bytes = raw->msg[idx]; idx++; - if (idx > raw->curlen) + if (idx + repmsg->u.remote_dpcd_read_ack.num_bytes > raw->curlen) goto fail_len; memcpy(repmsg->u.remote_dpcd_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_dpcd_read_ack.num_bytes); @@ -907,7 +907,9 @@ static bool drm_dp_sideband_parse_remote_i2c_read_ack(struct drm_dp_sideband_msg goto fail_len; repmsg->u.remote_i2c_read_ack.num_bytes = raw->msg[idx]; idx++; - /* TODO check */ + if (idx + repmsg->u.remote_i2c_read_ack.num_bytes > raw->curlen) + goto fail_len; + memcpy(repmsg->u.remote_i2c_read_ack.bytes, &raw->msg[idx], repmsg->u.remote_i2c_read_ack.num_bytes); return true; fail_len: -- 2.34.1