Skip to content

Commit b8ebf25

Browse files
Tetsuo Handadtor
authored andcommitted
Input: iforce - invert valid length check when fetching device IDs
syzbot is reporting uninitialized value at iforce_init_device() [1], for commit 6ac0aec ("Input: iforce - allow callers supply data buffer when fetching device IDs") is checking that valid length is shorter than bytes to read. Since iforce_get_id_packet() stores valid length when returning 0, the caller needs to check that valid length is longer than or equals to bytes to read. Reported-by: syzbot <[email protected]> Signed-off-by: Tetsuo Handa <[email protected]> Fixes: 6ac0aec ("Input: iforce - allow callers supply data buffer when fetching device IDs") Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent c7e37cc commit b8ebf25

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

drivers/input/joystick/iforce/iforce-main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,22 +273,22 @@ int iforce_init_device(struct device *parent, u16 bustype,
273273
* Get device info.
274274
*/
275275

276-
if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3)
276+
if (!iforce_get_id_packet(iforce, 'M', buf, &len) && len >= 3)
277277
input_dev->id.vendor = get_unaligned_le16(buf + 1);
278278
else
279279
dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");
280280

281-
if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3)
281+
if (!iforce_get_id_packet(iforce, 'P', buf, &len) && len >= 3)
282282
input_dev->id.product = get_unaligned_le16(buf + 1);
283283
else
284284
dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n");
285285

286-
if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3)
286+
if (!iforce_get_id_packet(iforce, 'B', buf, &len) && len >= 3)
287287
iforce->device_memory.end = get_unaligned_le16(buf + 1);
288288
else
289289
dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n");
290290

291-
if (!iforce_get_id_packet(iforce, 'N', buf, &len) || len < 2)
291+
if (!iforce_get_id_packet(iforce, 'N', buf, &len) && len >= 2)
292292
ff_effects = buf[1];
293293
else
294294
dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n");

0 commit comments

Comments
 (0)