Skip to contentSkip to conversation

ff-memless: fix signed to unsigned bit overflow in ml_combile_effects()

PATCH Applied Jussi Kivilinna 3 participants 3 messages May 7, 2009 – May 8, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ff-memless: fix signed to unsigned bit overflow in ml_combile_effects()

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.

---

 drivers/input/ff-memless.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/input/ff-memless.c +1 -1
index bc4e40f..2d1415e 100644
@@ -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;
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Jussi Kivilinna

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.

Quoted 3 lines

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

Quoted 19 lines

---

 drivers/input/ff-memless.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/input/ff-memless.c +1 -1
index bc4e40f..2d1415e 100644
@@ -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;
Signature · 1 line
Anssi Hannula
maintainer Applied
#2 lore raw

Re: [PATCH] ff-memless: fix signed to unsigned bit overflow in?ml_combile_effects()

Quoted 11 lines · On Thursday 07 May 2009 16:53:50 Anssi Hannula wrote:
Quoted 10 lines · Jussi Kivilinna

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.

Quoted 6 lines
Quoted 3 lines

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

Applied, thank you.

Signature · 1 line
Dmitry