diff mbox

[1/2] HID: magicmouse: sanity check report size in raw_event() callback

Message ID alpine.LNX.2.00.1408270911130.2992@pobox.suse.cz (mailing list archive)
State New, archived
Delegated to: Jiri Kosina
Headers show

Commit Message

Jiri Kosina Aug. 27, 2014, 7:12 a.m. UTC
The report passed to us from transport driver could potentially be 
arbitrarily large, therefore we better sanity-check it so that 
magicmouse_emit_touch() gets only valid values of raw_id.

Cc: stable@vger.kernel.org
Reported-by: Steven Vittitoe <scvitti@google.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
---
 drivers/hid/hid-magicmouse.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

Comments

Benjamin Tissoires Aug. 27, 2014, 1:54 p.m. UTC | #1
On Wed, Aug 27, 2014 at 3:12 AM, Jiri Kosina <jkosina@suse.cz> wrote:
> The report passed to us from transport driver could potentially be
> arbitrarily large, therefore we better sanity-check it so that
> magicmouse_emit_touch() gets only valid values of raw_id.
>
> Cc: stable@vger.kernel.org
> Reported-by: Steven Vittitoe <scvitti@google.com>
> Signed-off-by: Jiri Kosina <jkosina@suse.cz>

Fair enough.
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>

Cheers,
Benjamin

> ---
>  drivers/hid/hid-magicmouse.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
>
> diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
> index ecc2cbf..29a74c1 100644
> --- a/drivers/hid/hid-magicmouse.c
> +++ b/drivers/hid/hid-magicmouse.c
> @@ -290,6 +290,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>                 if (size < 4 || ((size - 4) % 9) != 0)
>                         return 0;
>                 npoints = (size - 4) / 9;
> +               if (npoints > 15) {
> +                       hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
> +                                       size);
> +                       return 0;
> +               }
>                 msc->ntouches = 0;
>                 for (ii = 0; ii < npoints; ii++)
>                         magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
> @@ -307,6 +312,11 @@ static int magicmouse_raw_event(struct hid_device *hdev,
>                 if (size < 6 || ((size - 6) % 8) != 0)
>                         return 0;
>                 npoints = (size - 6) / 8;
> +               if (npoints > 15) {
> +                       hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
> +                                       size);
> +                       return 0;
> +               }
>                 msc->ntouches = 0;
>                 for (ii = 0; ii < npoints; ii++)
>                         magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);
> --
> 1.9.2
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c
index ecc2cbf..29a74c1 100644
--- a/drivers/hid/hid-magicmouse.c
+++ b/drivers/hid/hid-magicmouse.c
@@ -290,6 +290,11 @@  static int magicmouse_raw_event(struct hid_device *hdev,
 		if (size < 4 || ((size - 4) % 9) != 0)
 			return 0;
 		npoints = (size - 4) / 9;
+		if (npoints > 15) {
+			hid_warn(hdev, "invalid size value (%d) for TRACKPAD_REPORT_ID\n",
+					size);
+			return 0;
+		}
 		msc->ntouches = 0;
 		for (ii = 0; ii < npoints; ii++)
 			magicmouse_emit_touch(msc, ii, data + ii * 9 + 4);
@@ -307,6 +312,11 @@  static int magicmouse_raw_event(struct hid_device *hdev,
 		if (size < 6 || ((size - 6) % 8) != 0)
 			return 0;
 		npoints = (size - 6) / 8;
+		if (npoints > 15) {
+			hid_warn(hdev, "invalid size value (%d) for MOUSE_REPORT_ID\n",
+					size);
+			return 0;
+		}
 		msc->ntouches = 0;
 		for (ii = 0; ii < npoints; ii++)
 			magicmouse_emit_touch(msc, ii, data + ii * 8 + 6);