提交 55a9d836 编写于 作者: M Marc Zyngier 提交者: Yang Yingliang

HID: core: Correctly handle ReportSize being zero

stable inclusion
from linux-4.19.144
commit abae259fdccc5e41ff302dd80a2b944ce385c970
CVE: CVE-2020-0465

--------------------------------

commit bce1305c upstream.

It appears that a ReportSize value of zero is legal, even if a bit
non-sensical. Most of the HID code seems to handle that gracefully,
except when computing the total size in bytes. When fed as input to
memset, this leads to some funky outcomes.

Detect the corner case and correctly compute the size.

Cc: stable@vger.kernel.org
Signed-off-by: NMarc Zyngier <maz@kernel.org>
Signed-off-by: NBenjamin Tissoires <benjamin.tissoires@gmail.com>
Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 2b10b54c
...@@ -1425,6 +1425,17 @@ static void hid_output_field(const struct hid_device *hid, ...@@ -1425,6 +1425,17 @@ static void hid_output_field(const struct hid_device *hid,
} }
} }
/*
* Compute the size of a report.
*/
static size_t hid_compute_report_size(struct hid_report *report)
{
if (report->size)
return ((report->size - 1) >> 3) + 1;
return 0;
}
/* /*
* Create a report. 'data' has to be allocated using * Create a report. 'data' has to be allocated using
* hid_alloc_report_buf() so that it has proper size. * hid_alloc_report_buf() so that it has proper size.
...@@ -1437,7 +1448,7 @@ void hid_output_report(struct hid_report *report, __u8 *data) ...@@ -1437,7 +1448,7 @@ void hid_output_report(struct hid_report *report, __u8 *data)
if (report->id > 0) if (report->id > 0)
*data++ = report->id; *data++ = report->id;
memset(data, 0, ((report->size - 1) >> 3) + 1); memset(data, 0, hid_compute_report_size(report));
for (n = 0; n < report->maxfield; n++) for (n = 0; n < report->maxfield; n++)
hid_output_field(report->device, report->field[n], data); hid_output_field(report->device, report->field[n], data);
} }
...@@ -1564,7 +1575,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size, ...@@ -1564,7 +1575,7 @@ int hid_report_raw_event(struct hid_device *hid, int type, u8 *data, u32 size,
csize--; csize--;
} }
rsize = ((report->size - 1) >> 3) + 1; rsize = hid_compute_report_size(report);
if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE) if (report_enum->numbered && rsize >= HID_MAX_BUFFER_SIZE)
rsize = HID_MAX_BUFFER_SIZE - 1; rsize = HID_MAX_BUFFER_SIZE - 1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册