From nobody Sat Feb 7 15:11:52 2026 Received: from mail-qv1-f47.google.com (mail-qv1-f47.google.com [209.85.219.47]) (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 9F5ED1E2834 for ; Sat, 20 Dec 2025 00:27:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766190471; cv=none; b=DRLQQjJZ70K+D6jZDIkxH5yMpbmbpgX3Mwi2CMpmlbpcXOK/dbuWXmPxJoXKnLdZREHbBWdnFaOtJTYb33vpoH+Flrz9gRUT7KGFEd2IgW2zkIwwKZghNUcCzfTfEQAvRuxhxgJHlvLbGZ0YNQddO9HnR5oZb59E+7eAV8TnOGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766190471; c=relaxed/simple; bh=lwzVY2cnFM1PAApqOOveZhkpTAE9aDh9DnkFErVtPvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZhVd2IJEu446HQH0fE/nRr99mzevvu+E5W82PpLMrosvoehOnO+CI5QoKW+I0j/03svfhW8Yk6WJL3uNklg3eiwEVkllmwHC71CCEQvC/L85xzr1Ik617z7gcnPeIDs5ev/TRPTyNA5IIoNC70fQFtL85bQLJHihodx5XkkWU9M= 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=GMqd3EUS; arc=none smtp.client-ip=209.85.219.47 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="GMqd3EUS" Received: by mail-qv1-f47.google.com with SMTP id 6a1803df08f44-88a2e3bd3cdso27654666d6.0 for ; Fri, 19 Dec 2025 16:27:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766190466; x=1766795266; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=IbY5vEoYtQrMPHWgFdyvVbg+PpcYg8w5v5NETAuJ6hQ=; b=GMqd3EUSmU2xD3hOii3hgzvs/RHYvCiTrGYN/EJiULSIQ1YH01LdkMzL9nh6ylqCG7 EHugRWTsDvYCPjGJERysyfw4KSMi9UUJiSPoTuP1MOM230i8uVr6XiMuWHRban235kkW K4fzQJ/sFAbdNoxMYE0LJ5/x4RRyp1DJf/7yghTE2vLXciFFFYA8uRfVCOSK0AW26+qA clPmYb0dNCjKdwPhD70ieBIhp16Fnx1hI5a719QuBexTrKoY4i9iZvlYwZTPvxiLjLdm tEhozhTeDDgexPd3yWuISAMQEMOzlMXRA2ZxETJ8LI0dZ3xd3XcJlSDwJf2TQlmec7B1 a2uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766190466; x=1766795266; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=IbY5vEoYtQrMPHWgFdyvVbg+PpcYg8w5v5NETAuJ6hQ=; b=Mwz/El0mghaoyc+s+02hyrgZzGqC7n/pFVsVLHk4wFFstChlpCMgJfXJMF7BTO5li6 gv702HhD/P7Q/uQtIKHXjBTIENfDb2vrMjzXt79ZbqbKRMWA7FZZTGw5SCFPbJePvUUp mcC1mNE/hidd3r9HMb4EDle0duORefCJEZZpqliGrBFssc/tGrr3q++QpdkSwqRS/6ve fNoXmVsXDzNItbroXZcXaxJX+ku0L/cL4XctR4y7Rw2WjQSHbkf5vYihXH7Gbd3c02xo wDrkH75HDIZ51y2gvBoLo55A+5CC81SAXEHZ+SW7LDFCnWstAqpvJGBcT2/3aKu6b/Rz T2uw== X-Forwarded-Encrypted: i=1; AJvYcCWCHUgYvhHRSn2P5aEwryxK9XS4prBSvDuK6IpijUURaaKTCbqNL6gPElOYlXxXrAIeAto7P/LcjEH1F14=@vger.kernel.org X-Gm-Message-State: AOJu0Yw81rYcQXGRcb2dFnFLS4EpvOemzJuF03EDzuSdzFNm9mMWFboN KyRI8wneJUM1vbJ+QDRFoeMPHe5Sp/79OLb/lsaRtpH9dP3xuOkEFhP1 X-Gm-Gg: AY/fxX733/2nsSFUhZXw2Zy1joW5igy8no3iFh939o8PuFa+hyFppqJviIhvtqLpz1E e/M8QcMjrtvzxPvYzJoh/f1P9f01CgGe+z/VGfXdOLO4VOyVN8Pj/UiFQxEJvLeC0n6xTdYFS+c EV43rfgbv8y65xVO/Y3HwIDSeIcKhyqsAsEhrYQ3SA07yubVxdrpUJieY9w411Ly05zu2HeVgFH 6geZvut2y2s0zxD0OBOEWw79xDNS+bgrDXF9UhvG2V1wTVK5YdS00iCUDNz9NI5w9LIE/Hd6Isr 1qiVo5IBRuQdJwkVlttnvQQB/7DaMiCTmYI1Ec9j2kJe0sJ1jsM07i46EukHAEYcxbjTKNDa3Nb +GcptSZip6ynpbOakBdEBdBNImRfzh77ZkCUcWNQVTbiijBMGPxFLfC1kyMVO5DmbcOP12VjEpO 88TOrrmNAWH1pg19lH6JpWCnGv/tUH4F2KDX9DEvTfQE4/nz2uOAIuLspdR6y0T2nxQZNbMX4by CDKOjnhr/M3NoZqsxl1psLj+Y+oy+i6rChnPjZYOw== X-Google-Smtp-Source: AGHT+IFDW7pRBGodzyLXGOJhutGjPfsRbeaZDuFM64LhrDnGGKHHeiRhrkY9X6I2+cAznbBDp2hvhg== X-Received: by 2002:a05:6214:3bc2:b0:87f:fffb:b7af with SMTP id 6a1803df08f44-88d81465ebdmr77561826d6.1.1766190466569; Fri, 19 Dec 2025 16:27:46 -0800 (PST) Received: from seungjin-HP-ENVY-Desktop-TE02-0xxx.dartmouth.edu ([129.170.197.82]) by smtp.gmail.com with ESMTPSA id af79cd13be357-8c096891558sm294631985a.15.2025.12.19.16.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Dec 2025 16:27:46 -0800 (PST) From: pip-izony To: Dmitry Torokhov Cc: Seungjin Bae , Kyungtae Kim , Sanghoon Choi , Dan Carpenter , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] Input: ims-pcu - fix heap-buffer-overflow in ims_pcu_process_data() Date: Fri, 19 Dec 2025 19:24:50 -0500 Message-ID: <20251220002447.392843-4-eeodqql09@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: 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" From: Seungjin Bae The `ims_pcu_process_data()` processes incoming URB data byte by byte. However, it fails to check if the `read_pos` index exceeds IMS_PCU_BUF_SIZE. If a malicious USB device sends a packet larger than IMS_PCU_BUF_SIZE, `read_pos` will increment indefinitely. Moreover, since `read_pos` is located immediately after `read_buf`, the attacker can overwrite `read_pos` itself to arbitrarily control the index. This manipulated `read_pos` is subsequently used in `ims_pcu_handle_response()` to copy data into `cmd_buf`, leading to a heap buffer overflow. Specifically, an attacker can overwrite the `cmd_done.wait.head` located at offset 136 relative to `cmd_buf` in the `ims_pcu_handle_response()`. Consequently, when the driver calls `complete(&pcu->cmd_done)`, it triggers a control flow hijack by using the manipulated pointer. Fix this by adding a bounds check for `read_pos` before writing to `read_buf`. If the packet is too long, discard it, log a warining, and reset the parser state. Fixes: 628329d524743 ("Input: add IMS Passenger Control Unit driver") Signed-off-by: Seungjin Bae --- v1 -> v2: Add warning and reset the state of the parser for bad packet drivers/input/misc/ims-pcu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c index 4581f1c53644..c98ef71c841e 100644 --- a/drivers/input/misc/ims-pcu.c +++ b/drivers/input/misc/ims-pcu.c @@ -450,6 +450,16 @@ static void ims_pcu_process_data(struct ims_pcu *pcu, = struct urb *urb) continue; =20 if (pcu->have_dle) { + if (pcu->read_pos >=3D IMS_PCU_BUF_SIZE) { + dev_warn(pcu->dev, + "Packet too long (%d bytes), discarding\n", + pcu->read_pos); + pcu->have_stx =3D false; + pcu->have_dle =3D false; + pcu->read_pos =3D 0; + continue; + } + pcu->have_dle =3D false; pcu->read_buf[pcu->read_pos++] =3D data; pcu->check_sum +=3D data; @@ -491,6 +501,16 @@ static void ims_pcu_process_data(struct ims_pcu *pcu, = struct urb *urb) break; =20 default: + if (pcu->read_pos >=3D IMS_PCU_BUF_SIZE) { + dev_warn(pcu->dev, + "Packet too long (%d bytes), discarding\n", + pcu->read_pos); + pcu->have_stx =3D false; + pcu->have_dle =3D false; + pcu->read_pos =3D 0; + continue; + } + pcu->read_buf[pcu->read_pos++] =3D data; pcu->check_sum +=3D data; break; --=20 2.43.0