Skip to content

drivers/input/st7123: Clamp reported max_touches to ST7123_MAX_TOUCH_AREAS - #21315

Merged
xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:input/st7123-max-touches-bounds
Oct 31, 2026
Merged

xiaoxiang781216 merged 1 commit into
apache:masterfrom
Swatantra-66:input/st7123-max-touches-bounds

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

Summary

Fixes #21245

In drivers/input/st7123.c, the device capability block read over I2C reports max_touches, which was used directly to set lower.maxpoint. On each touch interrupt, st7123_data_worker() computes framelen = ST7123_FRAME_HEADER_SIZE + lower->maxpoint * ST7123_TOUCH_AREA_SIZE and executes a sequential I2C burst read into dev->frame.

While the header comment at lines 78–81 states:

"The value read back from ST7123_TOUCH_MAX_TOUCHES is clamped to this limit so that a bogus register value can never overrun the frame or sample buffers."

st7123_register() only checked that max_touches != 0 and omitted the upper bound check. Since dev->frame.areas, lastx, lasty, and sample_buf are all sized to ST7123_MAX_TOUCH_AREAS (10), an oversized reported touch count would trigger an out-of-bounds heap write into dev and adjacent heap during the I2C frame read.

This patch:

  1. Implements the promised clamp in st7123_register() to ensure priv->device_caps.max_touches <= ST7123_MAX_TOUCH_AREAS.
  2. Fixes right-brace indentation in st7123_probe_device() for full nxstyle compliance across the file.

Impact

  • Eliminates potential heap out-of-bounds write (CWE-787) when interacting with a malfunctioning or malicious touch controller.
  • No impact on normal devices reporting $\le 10$ touch points.
  • No breaking changes or API modifications.

Testing

  • Verified with NuttX tools/nxstyle (0 errors, 0 warnings).
  • Static analysis against buffer dimensions (struct st7123_frame_t, lastx, lasty, sample_buf).

…AREAS

The driver comment at lines 78-81 states:
"The value read back from ST7123_TOUCH_MAX_TOUCHES is clamped to this
limit so that a bogus register value can never overrun the frame or
sample buffers."

However, st7123_register() only checked that max_touches was non-zero
and assigned lower.maxpoint directly without enforcing the upper bound
against ST7123_MAX_TOUCH_AREAS (10). Because dev->frame.areas, lastx,
lasty, and sample_buf are sized to ST7123_MAX_TOUCH_AREAS, an oversized
reported touch count would cause an out-of-bounds heap write during
the sequential I2C frame read in st7123_data_worker().

Implement the promised clamp in st7123_register() and fix right brace
alignment in st7123_probe_device().

Fixes apache#21245.

Signed-off-by: Swatantra Yadav <[email protected]>
Assisted-by: Google Gemini
@github-actions github-actions Bot added Area: Drivers Drivers issues Size: S The size of the change in this PR is small labels Oct 31, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

@xiaoxiang781216
xiaoxiang781216 merged commit c7bde63 into apache:master Oct 31, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Drivers Drivers issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

drivers/input/st7123.c: device-reported max_touches drives an unclamped I2C burst read into the fixed 74-byte frame buffer (heap OOB write)

3 participants