linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] Input: force feedback - potential integer wrap in input_ff_create()
@ 2011-10-09 16:25 Dan Carpenter
  2011-10-10  5:08 ` Dmitry Torokhov
  0 siblings, 1 reply; 6+ messages in thread
From: Dan Carpenter @ 2011-10-09 16:25 UTC (permalink / raw)
  To: Dmitry Torokhov; +Cc: linux-input, kernel-janitors

Smatch complains about max_effects because it's an int and we cap the
maximum size, but we don't check for negative.  A negative value here
could make "ff" smaller than sizeof(struct ff_device) and lead to
memory corruption.

I think max_effects can come from ->ff_effects_max in
uinput_setup_device() and that comes from the user so potentially
it could be negative.  The call path is that uinput_setup_device()
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);

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

diff --git a/drivers/input/ff-core.c b/drivers/input/ff-core.c
index 3367f76..12422ed 100644
--- a/drivers/input/ff-core.c
+++ b/drivers/input/ff-core.c
@@ -319,6 +319,12 @@ int input_ff_create(struct input_dev *dev, int max_effects)
 		return -EINVAL;
 	}
 
+	if (max_effects < 0)
+		return -EINVAL;
+	if (sizeof(struct ff_device) + max_effects * sizeof(struct file *) <
+			max_effects)
+		return -EINVAL;
+
 	ff = kzalloc(sizeof(struct ff_device) +
 		     max_effects * sizeof(struct file *), GFP_KERNEL);
 	if (!ff)

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-10-15 14:34 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-09 16:25 [patch] Input: force feedback - potential integer wrap in input_ff_create() Dan Carpenter
2011-10-10  5:08 ` Dmitry Torokhov
2011-10-10 20:48   ` Dan Carpenter
2011-10-11 21:19     ` [patch v2] " Dan Carpenter
2011-10-13  4:36       ` Dmitry Torokhov
2011-10-15 14:24       ` walter harms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).