@@ -40,13 +40,18 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,{structinput_mt*mt=dev->mt;inti;+size_tmt_size=0;if(!num_slots)return0;if(mt)returnmt->num_slots!=num_slots?-EINVAL:0;-mt=kzalloc(struct_size(mt,slots,num_slots),GFP_KERNEL);+mt_size=struct_size(mt,slots,num_slots);+if(mt_size>KMALLOC_MAX_SIZE)+return-ENOMEM;++mt=kzalloc(mt_size,GFP_KERNEL);if(!mt)gotoerr_mem;
--
Following-up. I've also just found out that in this function, there is another
allocation with num_slots length:
int input_mt_init_slots(..)
{
..
if (flags & INPUT_MT_TRACK) {
unsigned int n2 = num_slots * num_slots;
mt->red = kcalloc(n2, sizeof(*mt->red), GFP_KERNEL);
..
I've checked HID vendors' xrefs for input_mt_init_slots(), most of them
pass >= 5 value to num_slots parameter. So either we should choose some
optimal limit of num_slots or just restrict it with big KMALLOC_MAX_SIZE.
Comments?