Re: general protection fault in sisusb_probe

2019-05-12 Thread syzbot

syzbot has found a reproducer for the following crash on:

HEAD commit:43151d6c usb-fuzzer: main usb gadget fuzzer driver
git tree:   https://github.com/google/kasan.git usb-fuzzer
console output: https://syzkaller.appspot.com/x/log.txt?x=1222d274a0
kernel config:  https://syzkaller.appspot.com/x/.config?x=4183eeef650d1234
dashboard link: https://syzkaller.appspot.com/bug?extid=a0cbdbd6d169020c8959
compiler:   gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:  https://syzkaller.appspot.com/x/repro.syz?x=1382e600a0
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=174783f0a0

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

 process_one_work+0x90f/0x1580 kernel/workqueue.c:2269
 worker_thread+0x9b/0xe20 kernel/workqueue.c:2415
 kthread+0x313/0x420 kernel/kthread.c:253
 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
kasan: CONFIG_KASAN_INLINE enabled
kasan: GPF could be caused by NULL-ptr deref or user memory access
general protection fault:  [#1] SMP KASAN PTI
CPU: 1 PID: 17 Comm: kworker/1:0 Not tainted 5.1.0-rc3-319004-g43151d6 #6
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS  
Google 01/01/2011

Workqueue: usb_hub_wq hub_event
RIP: 0010:dev_name include/linux/device.h:1087 [inline]
RIP: 0010:__dev_printk+0x3f/0x215 drivers/base/core.c:3208
Code: 89 f5 53 e8 8e 53 1c fc 48 85 ed 0f 84 c9 01 00 00 e8 80 53 1c fc 48  
8d 7d 50 b8 ff ff 37 00 48 89 fa 48 c1 e0 2a 48 c1 ea 03 <80> 3c 02 00 74  
05 e8 41 68 53 fc 4c 8b 7d 50 4d 85 ff 75 28 e8 53

RSP: 0018:8880a84ff1c8 EFLAGS: 00010206
RAX: dc00 RBX: ed101509fe40 RCX: 8980f1cb
RDX: 001e RSI: 855576f0 RDI: 00f0
RBP: 00a0 R08: 8880a84db100 R09: 0006
R10: 8880a84dba08 R11: 8880a84db100 R12: 8f031080
R13: 8880a84ff220 R14: 888090615500 R15: 88808c86
FS:  () GS:8880ad10() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 7faa07b9 CR3: a0896000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400
Call Trace:
 _dev_err+0xdc/0x10e drivers/base/core.c:3251
 sisusb_probe+0x1c8/0xbd6 drivers/usb/misc/sisusbvga/sisusb.c:3035
 usb_probe_interface+0x31d/0x820 drivers/usb/core/driver.c:361
 really_probe+0x2da/0xb10 drivers/base/dd.c:509
 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671
 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778
 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454
 __device_attach+0x223/0x3a0 drivers/base/dd.c:844
 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514
 device_add+0xad2/0x16e0 drivers/base/core.c:2106
 usb_set_configuration+0xdf7/0x1740 drivers/usb/core/message.c:2023
 generic_probe+0xa2/0xda drivers/usb/core/generic.c:210
 usb_probe_device+0xc0/0x150 drivers/usb/core/driver.c:266
 really_probe+0x2da/0xb10 drivers/base/dd.c:509
 driver_probe_device+0x21d/0x350 drivers/base/dd.c:671
 __device_attach_driver+0x1d8/0x290 drivers/base/dd.c:778
 bus_for_each_drv+0x163/0x1e0 drivers/base/bus.c:454
 __device_attach+0x223/0x3a0 drivers/base/dd.c:844
 bus_probe_device+0x1f1/0x2a0 drivers/base/bus.c:514
 device_add+0xad2/0x16e0 drivers/base/core.c:2106
 usb_new_device.cold+0x537/0xccf drivers/usb/core/hub.c:2534
 hub_port_connect drivers/usb/core/hub.c:5089 [inline]
 hub_port_connect_change drivers/usb/core/hub.c:5204 [inline]
 port_event drivers/usb/core/hub.c:5350 [inline]
 hub_event+0x138e/0x3b00 drivers/usb/core/hub.c:5432
 process_one_work+0x90f/0x1580 kernel/workqueue.c:2269
 worker_thread+0x9b/0xe20 kernel/workqueue.c:2415
 kthread+0x313/0x420 kernel/kthread.c:253
 ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352
Modules linked in:
---[ end trace 3af8db6f82d76f53 ]---
RIP: 0010:dev_name include/linux/device.h:1087 [inline]
RIP: 0010:__dev_printk+0x3f/0x215 drivers/base/core.c:3208
Code: 89 f5 53 e8 8e 53 1c fc 48 85 ed 0f 84 c9 01 00 00 e8 80 53 1c fc 48  
8d 7d 50 b8 ff ff 37 00 48 89 fa 48 c1 e0 2a 48 c1 ea 03 <80> 3c 02 00 74  
05 e8 41 68 53 fc 4c 8b 7d 50 4d 85 ff 75 28 e8 53

RSP: 0018:8880a84ff1c8 EFLAGS: 00010206
RAX: dc00 RBX: ed101509fe40 RCX: 8980f1cb
RDX: 001e RSI: 855576f0 RDI: 00f0
RBP: 00a0 R08: 8880a84db100 R09: 0006
R10: 8880a84dba08 R11: 8880a84db100 R12: 8f031080
R13: 8880a84ff220 R14: 888090615500 R15: 88808c86
FS:  () GS:8880ad10() knlGS:
CS:  0010 DS:  ES:  CR0: 80050033
CR2: 7faa07b9 CR3: a0896000 CR4: 001406e0
DR0:  DR1:  DR2: 
DR3:  DR6: fffe0ff0 DR7: 0400

[PATCH v2] usb: renesas_usbhs: Use specific struct instead of USBHS_TYPE_* enums

2019-05-12 Thread Yoshihiro Shimoda
This patch adds a specific struct "usbhs_of_data" to add a new SoC
data easily instead of code basis in the future.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 Changes from v1 [1]:
 - Use sizeof(variable) instead of sizeof(type).
 - Add Geert-san's reviewed-by (thanks!).

[1]
https://patchwork.kernel.org/patch/10938575/

 drivers/usb/renesas_usbhs/common.c | 112 +
 drivers/usb/renesas_usbhs/common.h |   5 ++
 2 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 249fbee..0ca89de 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -535,53 +535,92 @@ static int usbhsc_drvcllbck_notify_hotplug(struct 
platform_device *pdev)
return 0;
 }
 
+static const struct usbhs_of_data rcar_gen2_data = {
+   .platform_callback = &usbhs_rcar2_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN2,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rcar_gen3_data = {
+   .platform_callback = &usbhs_rcar3_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN3,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rcar_gen3_with_pll_data = {
+   .platform_callback = &usbhs_rcar3_with_pll_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rza1_data = {
+   .platform_callback = &usbhs_rza1_ops,
+   .param = {
+   .type = USBHS_TYPE_RZA1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
 /*
  * platform functions
  */
 static const struct of_device_id usbhs_of_match[] = {
{
.compatible = "renesas,usbhs-r8a774c0",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,usbhs-r8a7790",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7791",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7794",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7795",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,usbhs-r8a7796",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,usbhs-r8a77990",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,usbhs-r8a77995",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,rcar-gen2-usbhs",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,rcar-gen3-usbhs",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,rza1-usbhs",
-   .data = (void *)USBHS_TYPE_RZA1,
+   .data = &rza1_data,
},
{ },
 };
@@ -591,6 +630,7 @@ static struct renesas_usbhs_platform_info 
*usbhs_parse_dt(struct device *dev)
 {
struct renesas_usbhs_platform_info *info;
struct renesas_usbhs_driver_param *dparam;
+   const struct usbhs_of_data *data;
u32 tmp;
int gpio;
 
@@ -598,8 +638,15 @@ static struct renesas_usbhs_platform_info 
*usbhs_parse_dt(struct device *dev)
if (!info)
return NULL;
 
+   data = of_device_get_match_data(dev);
+   if (!data)
+   return NULL;
+
dparam = &info->driver_param;
-   dparam->type = (uintptr_t)of_device_get_match_data(dev);
+   memcpy(dparam, &data->param, sizeof(data->param));
+   memcpy(&info->platform_callback, data->platform_callback,
+  sizeof(*data->platform_callback));
+
if (!of_proper