Closed Bug 2052502 Opened 3 months ago Closed 3 months ago

Out-of-bounds read in LinuxGamepadService::OnGamepadData from KEY_MAX vs KEY_CNT array sizing

Categories

(Core :: DOM: Device Interfaces, defect)

defect

Tracking

()

RESOLVED FIXED
154 Branch
Tracking Status
firefox-esr115 --- unaffected
firefox-esr140 --- fixed
firefox-esr153 --- fixed
firefox152 --- wontfix
firefox153 --- wontfix
firefox154 --- fixed

People

(Reporter: Sylvestre, Assigned: Sylvestre)

References

(Blocks 1 open bug, Regression)

Details

(Keywords: regression)

Attachments

(3 external files)

Found via Coverity (CID 1585304, "Untrusted array index read").

In dom/gamepad/linux/LinuxGamepad.cpp, struct Gamepad declares uint8_t key_map[KEY_MAX] and uint8_t abs_map[ABS_MAX] (767 and 63 elements). But the kernel evdev layer admits EV_KEY codes up to KEY_MAX inclusive (is_event_supported uses code <= KEY_MAX), so in OnGamepadData an event with event.code == KEY_MAX (767) reads key_map[767] -- one element past the end of the array. The population loop (for (uint16_t key = 0; key < KEY_MAX; key++)) has the same exclusive-bound issue. Note that keyBits/absBits in AddDevice are already correctly sized with KEY_CNT/ABS_CNT, so a device bit can be set at an index key_map cannot store.

Additionally, the EV_KEY path indexes key_map with the untrusted device-supplied event.code without any bounds check, unlike the EV_ABS path which is guarded by abs_info.count(event.code).

Impact is low: the one-past-the-end byte lands on the adjacent in-struct member abs_map[0] (valid allocated memory), so there is no crash or information leak -- worst case a spurious button index. It is not web-reachable: web content cannot control event.code; triggering code == 767 requires a local uinput virtual joystick device (needs /dev/uinput privilege).

Fix: size the arrays with KEY_CNT/ABS_CNT, match the population-loop bounds, and add an explicit event.code >= KEY_CNT guard in the EV_KEY branch

key_map/abs_map were sized [KEY_MAX]/[ABS_MAX], but evdev admits EV_KEY codes up to KEY_MAX inclusive, so event.code == KEY_MAX read one past the end. Size the arrays and population loops with KEY_CNT/ABS_CNT (matching keyBits/absBits), and bound the untrusted event.code before indexing key_map.

Assignee: nobody → sledru
Status: NEW → ASSIGNED
Pushed by sledru@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/b514f97e4d1f https://hg.mozilla.org/integration/autoland/rev/1b13f2188b20 Fix out-of-bounds read in LinuxGamepad by sizing key_map/abs_map with KEY_CNT/ABS_CNT (Coverity CID 1585304) r=cmartin
Status: ASSIGNED → RESOLVED
Closed: 3 months ago
Resolution: --- → FIXED
Target Milestone: --- → 154 Branch
Keywords: regression
Regressed by: 1680982
Duplicate of this bug: 2053585

Set release status flags based on info from the regressing bug 1680982

The patch landed in nightly and beta is affected.
:Sylvestre, is this bug important enough to require an uplift?

For more information, please visit BugBot documentation.

Flags: needinfo?(sledru)

Set release status flags based on info from the regressing bug 1680982

QA Whiteboard: [qa-triage-done-c155/b154]

firefox-esr140 Uplift Approval Request

  • User impact if declined/Reason for urgency: potential crashes
  • Code covered by automated testing?: unknown
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: just a check
  • String changes made/needed?: no
  • Is Android affected?: no
Attachment #9626258 - Flags: approval-mozilla-esr140?

key_map/abs_map were sized [KEY_MAX]/[ABS_MAX], but evdev admits EV_KEY codes up to KEY_MAX inclusive, so event.code == KEY_MAX read one past the end. Size the arrays and population loops with KEY_CNT/ABS_CNT (matching keyBits/absBits), and bound the untrusted event.code before indexing key_map.

Original Revision: https://phabricator.services.mozilla.com/D310336

firefox-esr153 Uplift Approval Request

  • User impact if declined/Reason for urgency: potential crashes
  • Code covered by automated testing?: unknown
  • Fix verified in Nightly?: yes
  • Needs manual QE testing?: no
  • Steps to reproduce for manual QE testing:
  • Risk associated with taking this patch: low
  • Explanation of risk level: just a check
  • String changes made/needed?: no
  • Is Android affected?: no
Attachment #9626259 - Flags: approval-mozilla-esr153?

key_map/abs_map were sized [KEY_MAX]/[ABS_MAX], but evdev admits EV_KEY codes up to KEY_MAX inclusive, so event.code == KEY_MAX read one past the end. Size the arrays and population loops with KEY_CNT/ABS_CNT (matching keyBits/absBits), and bound the untrusted event.code before indexing key_map.

Original Revision: https://phabricator.services.mozilla.com/D310336

Flags: needinfo?(sledru)
Attachment #9626259 - Flags: approval-mozilla-esr153? → approval-mozilla-esr153+
Attachment #9626258 - Flags: approval-mozilla-esr140? → approval-mozilla-esr140+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: