Skip to content

Check ev_code range in EVIOCGABS and EVIOCSABS - #264

Open
argusSecurityBot wants to merge 1 commit into
gvalkov:mainfrom
argusSecurityBot:check-abs-code-range
Open

argusSecurityBot wants to merge 1 commit into
gvalkov:mainfrom
argusSecurityBot:check-abs-code-range

Conversation

@argusSecurityBot

Copy link
Copy Markdown

InputDevice.absinfo(axis_num) and set_absinfo(axis_num, ...) pass the axis code through ioctl_EVIOCGABS / ioctl_EVIOCSABS in src/evdev/input.c, which parse it as a plain int (input.c:261, input.c:288).
It then reaches ioctl(fd, EVIOCGABS(ev_code), &absinfo) (input.c:265) and ioctl(fd, EVIOCSABS(ev_code), &absinfo) (input.c:300) with no range check.
EVIOCGABS(abs) is _IOR('E', 0x40 + (abs), struct input_absinfo), so any code above ABS_MAX (0x3f) names a request outside the absinfo range, and from 192 on 0x40 + ev_code no longer fits the 8-bit number field and _IOC ORs its high bits into the type/size/direction bits, issuing a different ioctl with a 24-byte input_absinfo as its argument.
At INT_MAX the 0x40 + ev_code addition is also signed integer overflow.
Fix: reject ev_code < 0 or ev_code > ABS_MAX with ValueError in both functions before calling ioctl.

from evdev import _input
_input.ioctl_EVIOCGABS(0, 2**31 - 1)

With a UBSan build at 9508e52: src/evdev/input.c:265:21: runtime error: signed integer overflow: 64 + 2147483647 cannot be represented in type 'int'.

This patch was generated with Claude and reviewed by a human on our team. It passes the project's existing tests (11 passed before and after; the 6 tests in tests/test_uinput.py need /dev/uinput and fail the same way without this patch). The vulnerability itself was verified by a human; if you'd prefer not to take LLM-generated code, feel free to close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant