Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: iforce - invert valid length check when fetching device IDs

syzbot is reporting uninitialized value at iforce_init_device() [1], for
commit 6ac0aec6b0a6 ("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 <syzbot+4dd880c1184280378821@syzkaller.appspotmail.com>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 6ac0aec6b0a6 ("Input: iforce - allow callers supply data buffer when fetching device IDs")
Link: https://lore.kernel.org/r/531fb432-7396-ad37-ecba-3e42e7f56d5c@I-love.SAKURA.ne.jp
Cc: stable@vger.kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Tetsuo Handa and committed by
Dmitry Torokhov
b8ebf250 c7e37cc6

+4 -4
+4 -4
drivers/input/joystick/iforce/iforce-main.c
··· 273 273 * Get device info. 274 274 */ 275 275 276 - if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3) 276 + if (!iforce_get_id_packet(iforce, 'M', buf, &len) && len >= 3) 277 277 input_dev->id.vendor = get_unaligned_le16(buf + 1); 278 278 else 279 279 dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n"); 280 280 281 - if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3) 281 + if (!iforce_get_id_packet(iforce, 'P', buf, &len) && len >= 3) 282 282 input_dev->id.product = get_unaligned_le16(buf + 1); 283 283 else 284 284 dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n"); 285 285 286 - if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3) 286 + if (!iforce_get_id_packet(iforce, 'B', buf, &len) && len >= 3) 287 287 iforce->device_memory.end = get_unaligned_le16(buf + 1); 288 288 else 289 289 dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n"); 290 290 291 - if (!iforce_get_id_packet(iforce, 'N', buf, &len) || len < 2) 291 + if (!iforce_get_id_packet(iforce, 'N', buf, &len) && len >= 2) 292 292 ff_effects = buf[1]; 293 293 else 294 294 dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n");