aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorDan Carpenter <dan.carpenter@oracle.com>2011-10-13 00:05:53 -0400
committerDmitry Torokhov <dmitry.torokhov@gmail.com>2011-10-13 00:13:11 -0400
commit05be8b81aafd4f95106a91ff3fd8581fa984fad9 (patch)
treed34da61ab5fa18f5fb57b0342a1e3871aedb36bc /drivers
parent341deefe8f4584b09564193cb46d8cf386f491a5 (diff)
Input: force feedback - potential integer wrap in input_ff_create()
The problem here is that max_effects can wrap on 32 bits systems. We'd allocate a smaller amount of data than sizeof(struct ff_device). The call to kcalloc() on the next line would fail but it would write the NULL return outside of the memory we just allocated causing data corruption. The call path is that uinput_setup_device() get ->ff_effects_max from the user and sets the value in the ->private_data struct. From there it is: -> uinput_ioctl_handler() -> uinput_create_device() -> input_ff_create(dev, udev->ff_effects_max); I've also changed ff_effects_max so it's an unsigned int instead of a signed int as a cleanup. Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/ff-core.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c
index 3367f760d75a..480eb9d9876a 100644
--- a/drivers/input/ff-core.c
+++ b/drivers/input/ff-core.c
@@ -309,9 +309,10 @@ EXPORT_SYMBOL_GPL(input_ff_event);
309 * Once ff device is created you need to setup its upload, erase, 309 * Once ff device is created you need to setup its upload, erase,
310 * playback and other handlers before registering input device 310 * playback and other handlers before registering input device
311 */ 311 */
312int input_ff_create(struct input_dev *dev, int max_effects) 312int input_ff_create(struct input_dev *dev, unsigned int max_effects)
313{ 313{
314 struct ff_device *ff; 314 struct ff_device *ff;
315 size_t ff_dev_size;
315 int i; 316 int i;
316 317
317 if (!max_effects) { 318 if (!max_effects) {
@@ -319,8 +320,12 @@ int input_ff_create(struct input_dev *dev, int max_effects)
319 return -EINVAL; 320 return -EINVAL;
320 } 321 }
321 322
322 ff = kzalloc(sizeof(struct ff_device) + 323 ff_dev_size = sizeof(struct ff_device) +
323 max_effects * sizeof(struct file *), GFP_KERNEL); 324 max_effects * sizeof(struct file *);
325 if (ff_dev_size < max_effects) /* overflow */
326 return -EINVAL;
327
328 ff = kzalloc(ff_dev_size, GFP_KERNEL);
324 if (!ff) 329 if (!ff)
325 return -ENOMEM; 330 return -ENOMEM;
326 331