linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ff-memless: fix signed to unsigned bit overflow in ml_combile_effects()
@ 2009-05-07 19:32 Jussi Kivilinna
  2009-05-07 23:53 ` Anssi Hannula
  0 siblings, 1 reply; 3+ messages in thread
From: Jussi Kivilinna @ 2009-05-07 19:32 UTC (permalink / raw)
  To: linux-input; +Cc: Dmitry Torokhov, Anssi Hannula

When userspace sets effect->u.rumble.strong_magnitude to 0x8001 or larger,
ml_combine_effects() would always return strong_magnitude 0xffff.

Problem is that 'gain' is passed in as signed integer. Multiplying magnitude
(__u16) with gain (int) causes magnitude read as signed and results negative
value (with magnitude > 0x8000). This signed integer is then divided and
value, still negative, converted to 32bit unsigned integer. Finally checking
combine overflow min(new+old, 0xffff) gives out 0xffff.

Fix is to simply change 'gain' to unsigned int.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
---

 drivers/input/ff-memless.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
index bc4e40f..2d1415e 100644
--- a/drivers/input/ff-memless.c
+++ b/drivers/input/ff-memless.c
@@ -226,7 +226,7 @@ static int get_compatible_type(struct ff_device *ff, int effect_type)
  */
 static void ml_combine_effects(struct ff_effect *effect,
 			       struct ml_effect_state *state,
-			       int gain)
+			       unsigned int gain)
 {
 	struct ff_effect *new = state->effect;
 	unsigned int strong, weak, i;


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

* Re: [PATCH] ff-memless: fix signed to unsigned bit overflow in ml_combile_effects()
  2009-05-07 19:32 [PATCH] ff-memless: fix signed to unsigned bit overflow in ml_combile_effects() Jussi Kivilinna
@ 2009-05-07 23:53 ` Anssi Hannula
  2009-05-08  2:10   ` [PATCH] ff-memless: fix signed to unsigned bit overflow in?ml_combile_effects() Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Anssi Hannula @ 2009-05-07 23:53 UTC (permalink / raw)
  To: linux-input; +Cc: Jussi Kivilinna, Dmitry Torokhov

Jussi Kivilinna wrote:
> When userspace sets effect->u.rumble.strong_magnitude to 0x8001 or larger,
> ml_combine_effects() would always return strong_magnitude 0xffff.
> 
> Problem is that 'gain' is passed in as signed integer. Multiplying magnitude
> (__u16) with gain (int) causes magnitude read as signed and results negative
> value (with magnitude > 0x8000). This signed integer is then divided and
> value, still negative, converted to 32bit unsigned integer. Finally checking
> combine overflow min(new+old, 0xffff) gives out 0xffff.
> 
> Fix is to simply change 'gain' to unsigned int.
> 
> Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>

Acked-by: Anssi Hannula <anssi.hannula@gmail.com>

> ---
> 
>  drivers/input/ff-memless.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/input/ff-memless.c b/drivers/input/ff-memless.c
> index bc4e40f..2d1415e 100644
> --- a/drivers/input/ff-memless.c
> +++ b/drivers/input/ff-memless.c
> @@ -226,7 +226,7 @@ static int get_compatible_type(struct ff_device *ff, int effect_type)
>   */
>  static void ml_combine_effects(struct ff_effect *effect,
>  			       struct ml_effect_state *state,
> -			       int gain)
> +			       unsigned int gain)
>  {
>  	struct ff_effect *new = state->effect;
>  	unsigned int strong, weak, i;
> 


-- 
Anssi Hannula

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

* Re: [PATCH] ff-memless: fix signed to unsigned bit overflow in?ml_combile_effects()
  2009-05-07 23:53 ` Anssi Hannula
@ 2009-05-08  2:10   ` Dmitry Torokhov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2009-05-08  2:10 UTC (permalink / raw)
  To: Anssi Hannula; +Cc: linux-input, Jussi Kivilinna

On Thursday 07 May 2009 16:53:50 Anssi Hannula wrote:
> Jussi Kivilinna wrote:
> > When userspace sets effect->u.rumble.strong_magnitude to 0x8001 or
> > larger, ml_combine_effects() would always return strong_magnitude 0xffff.
> >
> > Problem is that 'gain' is passed in as signed integer. Multiplying
> > magnitude (__u16) with gain (int) causes magnitude read as signed and
> > results negative value (with magnitude > 0x8000). This signed integer is
> > then divided and value, still negative, converted to 32bit unsigned
> > integer. Finally checking combine overflow min(new+old, 0xffff) gives out
> > 0xffff.
> >
> > Fix is to simply change 'gain' to unsigned int.
> >
> > Signed-off-by: Jussi Kivilinna <jussi.kivilinna@mbnet.fi>
>
> Acked-by: Anssi Hannula <anssi.hannula@gmail.com>
>

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2009-05-08  2:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-05-07 19:32 [PATCH] ff-memless: fix signed to unsigned bit overflow in ml_combile_effects() Jussi Kivilinna
2009-05-07 23:53 ` Anssi Hannula
2009-05-08  2:10   ` [PATCH] ff-memless: fix signed to unsigned bit overflow in?ml_combile_effects() Dmitry Torokhov

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).