Page MenuHomeFreeBSD

hid: avoid 32-bit overflow when computing report size
Needs ReviewPublic

Authored by ojanerif_amd.com on Sun, Oct 18, 11:12 PM.
Tags
None
Referenced Files
Unknown Object (File)
Tue, Oct 20, 7:29 PM
Unknown Object (File)
Tue, Oct 20, 6:12 PM
Unknown Object (File)
Tue, Oct 20, 6:11 PM
Unknown Object (File)
Tue, Oct 20, 6:10 PM
Unknown Object (File)
Mon, Oct 19, 7:23 AM
Unknown Object (File)
Mon, Oct 19, 4:48 AM
Unknown Object (File)
Mon, Oct 19, 4:39 AM
Unknown Object (File)
Mon, Oct 19, 4:02 AM
Subscribers

Details

Reviewers
wulf
Summary

hid_report_size() and hid_report_size_max() compute a field's end bit position as loc.pos + loc.size * loc.count, and hid_get_item() accumulates the same product into loc.pos. loc.size and loc.count are uint32_t taken from the report descriptor with no bound, so a crafted descriptor wraps the 32-bit multiply and the functions return a wrong, usually too small, report size.

It is not exploitable now: hid_get_data() clamps reads to the caller buffer and the input drivers reject reports larger than the endpoint. The size is still wrong, so do the math in 64-bit and saturate at UINT32_MAX. Well-formed descriptors produce the same result.

Test Plan

Build tested on amd64; hid.ko links clean with -Werror. No change for descriptors whose pos + size * count fits in 32 bits.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Tests Skipped