linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [syzbot] KMSAN: uninit-value in iforce_init_device (2)
@ 2022-11-07  9:43 syzbot
  2022-11-07 10:47 ` [PATCH] Input: iforce - invert valid length check when fetching device IDs Tetsuo Handa
  0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2022-11-07  9:43 UTC (permalink / raw)
  To: dmitry.torokhov, glider, greg.iforce, linux-input, linux-kernel,
	syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    968c2729e576 x86: kmsan: fix comment in kmsan_shadow.c
git tree:       https://github.com/google/kmsan.git master
console output: https://syzkaller.appspot.com/x/log.txt?x=14efb852880000
kernel config:  https://syzkaller.appspot.com/x/.config?x=131312b26465c190
dashboard link: https://syzkaller.appspot.com/bug?extid=4dd880c1184280378821
compiler:       clang version 15.0.0 (https://github.com/llvm/llvm-project.git 610139d2d9ce6746b3c617fb3e2f7886272d26ff), GNU ld (GNU Binutils for Debian) 2.35.2

Unfortunately, I don't have any reproducer for this issue yet.

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/56b19fc61d98/disk-968c2729.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/b048b309a6e5/vmlinux-968c2729.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+4dd880c1184280378821@syzkaller.appspotmail.com

iforce 1-1:0.0: usb_submit_urb failed: -71
iforce 1-1:0.0: usb_submit_urb failed: -71
iforce 1-1:0.0: usb_submit_urb failed: -71
=====================================================
BUG: KMSAN: uninit-value in iforce_init_device+0x1bd5/0x2010 drivers/input/joystick/iforce/iforce-main.c:297
 iforce_init_device+0x1bd5/0x2010 drivers/input/joystick/iforce/iforce-main.c:297
 iforce_usb_probe+0xc86/0x11c0 drivers/input/joystick/iforce/iforce-usb.c:238
 usb_probe_interface+0xc4b/0x11f0 drivers/usb/core/driver.c:396
 really_probe+0x506/0x1000 drivers/base/dd.c:639
 __driver_probe_device+0x2fa/0x3d0 drivers/base/dd.c:778
 driver_probe_device+0x72/0x7a0 drivers/base/dd.c:808
 __device_attach_driver+0x548/0x8e0 drivers/base/dd.c:936
 bus_for_each_drv+0x1fc/0x360 drivers/base/bus.c:427
 __device_attach+0x42a/0x720 drivers/base/dd.c:1008
 device_initial_probe+0x2e/0x40 drivers/base/dd.c:1057
 bus_probe_device+0x13c/0x3b0 drivers/base/bus.c:487
 device_add+0x1d4b/0x26c0 drivers/base/core.c:3517
 usb_set_configuration+0x30f8/0x37e0 drivers/usb/core/message.c:2170
 usb_generic_driver_probe+0x105/0x290 drivers/usb/core/generic.c:238
 usb_probe_device+0x288/0x490 drivers/usb/core/driver.c:293
 really_probe+0x506/0x1000 drivers/base/dd.c:639
 __driver_probe_device+0x2fa/0x3d0 drivers/base/dd.c:778
 driver_probe_device+0x72/0x7a0 drivers/base/dd.c:808
 __device_attach_driver+0x548/0x8e0 drivers/base/dd.c:936
 bus_for_each_drv+0x1fc/0x360 drivers/base/bus.c:427
 __device_attach+0x42a/0x720 drivers/base/dd.c:1008
 device_initial_probe+0x2e/0x40 drivers/base/dd.c:1057
 bus_probe_device+0x13c/0x3b0 drivers/base/bus.c:487
 device_add+0x1d4b/0x26c0 drivers/base/core.c:3517
 usb_new_device+0x17ac/0x2370 drivers/usb/core/hub.c:2573
 hub_port_connect drivers/usb/core/hub.c:5353 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5497 [inline]
 port_event drivers/usb/core/hub.c:5653 [inline]
 hub_event+0x5589/0x8080 drivers/usb/core/hub.c:5735
 process_one_work+0xb27/0x13e0 kernel/workqueue.c:2289
 worker_thread+0x1076/0x1d60 kernel/workqueue.c:2436
 kthread+0x31b/0x430 kernel/kthread.c:376
 ret_from_fork+0x1f/0x30

Local variable buf created at:
 iforce_init_device+0x5a/0x2010 drivers/input/joystick/iforce/iforce-main.c:217
 iforce_usb_probe+0xc86/0x11c0 drivers/input/joystick/iforce/iforce-usb.c:238

CPU: 0 PID: 15409 Comm: kworker/0:2 Not tainted 6.0.0-rc5-syzkaller-48543-g968c2729e576 #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/22/2022
Workqueue: usb_hub_wq hub_event
=====================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

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

* [PATCH] Input: iforce - invert valid length check when fetching device IDs
  2022-11-07  9:43 [syzbot] KMSAN: uninit-value in iforce_init_device (2) syzbot
@ 2022-11-07 10:47 ` Tetsuo Handa
  2022-11-07 18:29   ` Dmitry Torokhov
  0 siblings, 1 reply; 3+ messages in thread
From: Tetsuo Handa @ 2022-11-07 10:47 UTC (permalink / raw)
  To: Dmitry Torokhov, Greg Tulli
  Cc: syzbot, syzkaller-bugs, linux-input, linux-kernel, glider

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.

Link: https://syzkaller.appspot.com/bug?extid=4dd880c1184280378821 [1]
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")
---
 drivers/input/joystick/iforce/iforce-main.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c
index b86de1312512..84b87526b7ba 100644
--- a/drivers/input/joystick/iforce/iforce-main.c
+++ b/drivers/input/joystick/iforce/iforce-main.c
@@ -273,22 +273,22 @@ int iforce_init_device(struct device *parent, u16 bustype,
  * Get device info.
  */
 
-	if (!iforce_get_id_packet(iforce, 'M', buf, &len) || len < 3)
+	if (!iforce_get_id_packet(iforce, 'M', buf, &len) && len >= 3)
 		input_dev->id.vendor = get_unaligned_le16(buf + 1);
 	else
 		dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");
 
-	if (!iforce_get_id_packet(iforce, 'P', buf, &len) || len < 3)
+	if (!iforce_get_id_packet(iforce, 'P', buf, &len) && len >= 3)
 		input_dev->id.product = get_unaligned_le16(buf + 1);
 	else
 		dev_warn(&iforce->dev->dev, "Device does not respond to id packet P\n");
 
-	if (!iforce_get_id_packet(iforce, 'B', buf, &len) || len < 3)
+	if (!iforce_get_id_packet(iforce, 'B', buf, &len) && len >= 3)
 		iforce->device_memory.end = get_unaligned_le16(buf + 1);
 	else
 		dev_warn(&iforce->dev->dev, "Device does not respond to id packet B\n");
 
-	if (!iforce_get_id_packet(iforce, 'N', buf, &len) || len < 2)
+	if (!iforce_get_id_packet(iforce, 'N', buf, &len) && len >= 2)
 		ff_effects = buf[1];
 	else
 		dev_warn(&iforce->dev->dev, "Device does not respond to id packet N\n");
-- 
2.18.4


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

* Re: [PATCH] Input: iforce - invert valid length check when fetching device IDs
  2022-11-07 10:47 ` [PATCH] Input: iforce - invert valid length check when fetching device IDs Tetsuo Handa
@ 2022-11-07 18:29   ` Dmitry Torokhov
  0 siblings, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2022-11-07 18:29 UTC (permalink / raw)
  To: Tetsuo Handa
  Cc: Greg Tulli, syzbot, syzkaller-bugs, linux-input, linux-kernel, glider

On Mon, Nov 07, 2022 at 07:47:15PM +0900, Tetsuo Handa wrote:
> 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.
> 
> Link: https://syzkaller.appspot.com/bug?extid=4dd880c1184280378821 [1]
> 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")

Applied, thank you.

-- 
Dmitry

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

end of thread, other threads:[~2022-11-07 18:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-07  9:43 [syzbot] KMSAN: uninit-value in iforce_init_device (2) syzbot
2022-11-07 10:47 ` [PATCH] Input: iforce - invert valid length check when fetching device IDs Tetsuo Handa
2022-11-07 18:29   ` 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).