Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2097758rwp; Fri, 14 Jul 2023 00:11:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlHMvdfNVCNfPWYR1/r7+IlZJ96y1RdXVmH1RJrIXae1QqvvYYMQxwHSFWeKPa7DvwRZEiAo X-Received: by 2002:a2e:8606:0:b0:2b7:4078:13e0 with SMTP id a6-20020a2e8606000000b002b7407813e0mr3301288lji.43.1689318686793; Fri, 14 Jul 2023 00:11:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689318686; cv=none; d=google.com; s=arc-20160816; b=Tk4+FpkU4qEk0zkwE9Luid7L0AWRon14evVUwpNw7GGBc8N8TdFs6oW/HCWl/tKLvI IQ5MB9xti9GueLe5bGF3MhbSyZhq+wlVMi2CcvWAATG6tn9jSaIqB+iTg9E+/YLC9FOv kifBOC3a/P5MKIVNIg8rU9aODHT0XSLPDBbR6sIqbkFfIPMCZE2e0BwttWz/7WVqzMdl G1+OltRNMljLlVTM0kmQQLsJWnQFrZC6jmgTtUt9Dt8YlyrzvotUHtDy2FU6b7rD4jXG sPTKibDtv5OdP7EfViHLpvTHGKlqJhw9vQc9BhlGCO5/2z/Gjn4+xnt9WwdMVxGZ2iia NVog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=BIhrGEokJq7ybUIUIoHKrH340ulRUxP9jNOyqClNyGA=; fh=qIMrpZrY5xHHiykPTU/zR1JJB4lbzuu/WznLpHkGKG8=; b=cNnPySpY+w/ks34/xHnwEA/epCJ9BApThcpPR1RgWfj9vjqDLQxnvH4scIx8QCdSOW zyiYbtPy2E3K1KgiqvAd/oFmO8gbXfAShhhcQTQRYDM5rV7/VL6lCl3l0AIcoFkpq59T dTkA/Tf7c7rZUdEku5MOKwN+ULRZA2VA4/fBU+C+Uh/lTLRouBvimWZsQmWz5kVUfVIm aJ2WPBf/4j9CT3oLj7ow9+aNmeZaUrieFGIhZ//hpcWE5UKD3z4LNnQY5MuzMaOZ5KCP npWOd6R5dBW8/7waxPw/i4ZV14b5g34Q5nwVaXi/8Q8FfFdHUHjbLBZOPCKkUhUKbZiV fIfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Bfww+udQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ov2-20020a170906fc0200b00992aa293b8csi8320933ejb.332.2023.07.14.00.11.02; Fri, 14 Jul 2023 00:11:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=Bfww+udQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231235AbjGNGgM (ORCPT + 99 others); Fri, 14 Jul 2023 02:36:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234131AbjGNGfl (ORCPT ); Fri, 14 Jul 2023 02:35:41 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157C130C6; Thu, 13 Jul 2023 23:35:23 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id 98e67ed59e1d1-262d9e75438so995469a91.2; Thu, 13 Jul 2023 23:35:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689316522; x=1691908522; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=BIhrGEokJq7ybUIUIoHKrH340ulRUxP9jNOyqClNyGA=; b=Bfww+udQrORUUMm3Ca2lcIG7nym6aRYZSdMCBMg5g4zyoYM/huNRSNXggbtA/N6BpV gBizLg/iVS0d9QvWEyvvLq4A3O+GHhM7zST78/eyWXVFATX64vb1zbc36Rk/SMrCQWog eOsilaTv0mxZNSDjI/4xfdEdhiSwyeKhotlOv3V8BQ9272rGdVexA1s6OJa5JE9u5TB0 dZtKpcxHyuGYx0L6u3giVsHCjWc+8EWND0PLrM/izGxBZfH21fUPIyvnSRso6WH36noS ANdc618Mf9j0f/DTaXkpQOnVx1CH4nfMN6BVN8US3P30bIKjjQWYBsmpb7yj9uysO/zH bZOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689316522; x=1691908522; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=BIhrGEokJq7ybUIUIoHKrH340ulRUxP9jNOyqClNyGA=; b=eZFYVrHDLyoTlLV31GFWRCwQ7s9armnTjemlZiGMB0ogeEDJyheMUNzxTMZp+N6sW2 bByvZeJD7uBZZN5ZbMQmWlQxt6IxDr4LpxfCjf+S/1FTnak2xVgph/UKU5NPt6OZWtyo T9I+LOPnK0dYGIV4yzV4gI5+j7wrhdgzPHz6YgeSyO7zOvo+z+6Fvdef1m+uhYHtS3KI N6hp9UoKeP0jNGulIIZtcxlGX3+jYFItGWKM7/nreBPuGXIySbcndwy6AxsvvlOJonG+ m4ZzXb/7mPLI7jCnwGbXpevK28pzhJ9L+yuV4m1JnojfEC67rG0b7UUZ0ivba5UInsOy +5sg== X-Gm-Message-State: ABy/qLYt+4+5P+T0fKDt3yvISRwjF3islrxgC1/tjkUPI6gWTCImHbpj eGZvSVFDdN8VfzIQpRTS/eanwZjjCxwORvVClwE= X-Received: by 2002:a17:90a:ab11:b0:263:f72f:491 with SMTP id m17-20020a17090aab1100b00263f72f0491mr3332196pjq.43.1689316522404; Thu, 13 Jul 2023 23:35:22 -0700 (PDT) MIME-Version: 1.0 References: <0000000000009db51a06005b64e9@google.com> In-Reply-To: From: Z qiang Date: Fri, 14 Jul 2023 14:35:10 +0800 Message-ID: Subject: Re: [syzbot] [usb?] memory leak in raw_open To: syzbot Cc: andreyknvl@gmail.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 14, 2023 at 2:21=E2=80=AFPM Z qiang = wrote: > > > > > Hello, > > > > syzbot found the following issue on: > > > > HEAD commit: 1c7873e33645 mm: lock newly mapped VMA with corrected o= rde.. > > git tree: upstream > > console output: https://syzkaller.appspot.com/x/log.txt?x=3D1517663ca80= 000 > > kernel config: https://syzkaller.appspot.com/x/.config?x=3D832b404e095= b70c0 > > dashboard link: https://syzkaller.appspot.com/bug?extid=3Dfeb045d335c1f= dde5bf7 > > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binu= tils for Debian) 2.35.2 > > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=3D1776519ca= 80000 > > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=3D117f9778a80= 000 > > > > Downloadable assets: > > disk image: https://storage.googleapis.com/syzbot-assets/43b42bd2cf70/d= isk-1c7873e3.raw.xz > > vmlinux: https://storage.googleapis.com/syzbot-assets/011ba1b9e8c1/vmli= nux-1c7873e3.xz > > kernel image: https://storage.googleapis.com/syzbot-assets/18b349342595= /bzImage-1c7873e3.xz > > > > IMPORTANT: if you fix the issue, please add the following tag to the co= mmit: > > Reported-by: syzbot+feb045d335c1fdde5bf7@syzkaller.appspotmail.com > > > > BUG: memory leak > > unreferenced object 0xffff88810b172000 (size 4096): > > comm "syz-executor103", pid 5067, jiffies 4294964128 (age 13.070s) > > hex dump (first 32 bytes): > > 01 00 00 00 00 00 00 00 00 bc 96 0e 81 88 ff ff ................ > > 5d b6 9e 85 ff ff ff ff 03 00 00 00 00 00 00 00 ]............... > > backtrace: > > [] kmalloc_trace+0x24/0x90 mm/slab_common.c:1076 > > [] kmalloc include/linux/slab.h:582 [inline] > > [] kzalloc include/linux/slab.h:703 [inline] > > [] dev_new drivers/usb/gadget/legacy/raw_gadget.c= :191 [inline] > > [] raw_open+0x45/0x110 drivers/usb/gadget/legacy/= raw_gadget.c:385 > > [] misc_open+0x1a9/0x1f0 drivers/char/misc.c:165 > > [] chrdev_open+0x11b/0x340 fs/char_dev.c:414 > > [] do_dentry_open+0x30f/0x990 fs/open.c:914 > > [] do_open fs/namei.c:3636 [inline] > > [] path_openat+0x178b/0x1b20 fs/namei.c:3793 > > [] do_filp_open+0xc5/0x1b0 fs/namei.c:3820 > > [] do_sys_openat2+0xe3/0x140 fs/open.c:1407 > > [] do_sys_open fs/open.c:1422 [inline] > > [] __do_sys_openat fs/open.c:1438 [inline] > > [] __se_sys_openat fs/open.c:1433 [inline] > > [] __x64_sys_openat+0x83/0xe0 fs/open.c:1433 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x39/0xb0 arch/x86/entry/common.= c:80 > > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > BUG: memory leak > > unreferenced object 0xffff88810ad20d60 (size 32): > > comm "syz-executor103", pid 5067, jiffies 4294964128 (age 13.070s) > > hex dump (first 32 bytes): > > 72 61 77 2d 67 61 64 67 65 74 2e 30 00 00 00 00 raw-gadget.0.... > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [] kmalloc_trace+0x24/0x90 mm/slab_common.c:1076 > > [] kmalloc include/linux/slab.h:582 [inline] > > [] raw_ioctl_init+0xdf/0x410 drivers/usb/gadget/l= egacy/raw_gadget.c:460 > > [] raw_ioctl+0x5f9/0x1120 drivers/usb/gadget/lega= cy/raw_gadget.c:1250 > > [] vfs_ioctl fs/ioctl.c:51 [inline] > > [] __do_sys_ioctl fs/ioctl.c:870 [inline] > > [] __se_sys_ioctl fs/ioctl.c:856 [inline] > > [] __x64_sys_ioctl+0x103/0x140 fs/ioctl.c:856 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x39/0xb0 arch/x86/entry/common.= c:80 > > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > BUG: memory leak > > unreferenced object 0xffff88810e96bc00 (size 128): > > comm "syz-executor103", pid 5067, jiffies 4294964128 (age 13.070s) > > hex dump (first 32 bytes): > > 64 75 6d 6d 79 5f 75 64 63 00 00 00 00 00 00 00 dummy_udc....... > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [] kmalloc_trace+0x24/0x90 mm/slab_common.c:1076 > > [] kmalloc include/linux/slab.h:582 [inline] > > [] raw_ioctl_init+0x11d/0x410 drivers/usb/gadget/= legacy/raw_gadget.c:468 > > [] raw_ioctl+0x5f9/0x1120 drivers/usb/gadget/lega= cy/raw_gadget.c:1250 > > [] vfs_ioctl fs/ioctl.c:51 [inline] > > [] __do_sys_ioctl fs/ioctl.c:870 [inline] > > [] __se_sys_ioctl fs/ioctl.c:856 [inline] > > [] __x64_sys_ioctl+0x103/0x140 fs/ioctl.c:856 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x39/0xb0 arch/x86/entry/common.= c:80 > > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > BUG: memory leak > > unreferenced object 0xffff88810e96ba80 (size 128): > > comm "syz-executor103", pid 5067, jiffies 4294964128 (age 13.070s) > > hex dump (first 32 bytes): > > 64 75 6d 6d 79 5f 75 64 63 2e 30 00 00 00 00 00 dummy_udc.0..... > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [] kmalloc_trace+0x24/0x90 mm/slab_common.c:1076 > > [] kmalloc include/linux/slab.h:582 [inline] > > [] raw_ioctl_init+0x1ac/0x410 drivers/usb/gadget/= legacy/raw_gadget.c:479 > > [] raw_ioctl+0x5f9/0x1120 drivers/usb/gadget/lega= cy/raw_gadget.c:1250 > > [] vfs_ioctl fs/ioctl.c:51 [inline] > > [] __do_sys_ioctl fs/ioctl.c:870 [inline] > > [] __se_sys_ioctl fs/ioctl.c:856 [inline] > > [] __x64_sys_ioctl+0x103/0x140 fs/ioctl.c:856 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x39/0xb0 arch/x86/entry/common.= c:80 > > [] entry_SYSCALL_64_after_hwframe+0x63/0xcd > > > > BUG: memory leak > > unreferenced object 0xffff88810e96bd00 (size 128): > > comm "syz-executor103", pid 5067, jiffies 4294964128 (age 13.070s) > > hex dump (first 32 bytes): > > 00 bd 96 0e 81 88 ff ff 00 bd 96 0e 81 88 ff ff ................ > > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > backtrace: > > [] kmalloc_trace+0x24/0x90 mm/slab_common.c:1076 > > [] kmalloc include/linux/slab.h:582 [inline] > > [] kzalloc include/linux/slab.h:703 [inline] > > [] dummy_alloc_request+0x5a/0xe0 drivers/usb/gadg= et/udc/dummy_hcd.c:665 > > [] usb_ep_alloc_request+0x22/0xd0 drivers/usb/gad= get/udc/core.c:196 > > [] gadget_bind+0x6d/0x370 drivers/usb/gadget/lega= cy/raw_gadget.c:292 > > [] gadget_bind_driver+0xe3/0x2e0 drivers/usb/gadg= et/udc/core.c:1591 > > [] call_driver_probe drivers/base/dd.c:579 [inlin= e] > > [] really_probe+0x12d/0x430 drivers/base/dd.c:658 > > [] __driver_probe_device+0xc1/0x1a0 drivers/base/= dd.c:798 > > [] driver_probe_device+0x2a/0x120 drivers/base/dd= .c:828 > > [] __driver_attach drivers/base/dd.c:1214 [inline= ] > > [] __driver_attach+0xfe/0x1f0 drivers/base/dd.c:1= 154 > > [] bus_for_each_dev+0xa5/0x110 drivers/base/bus.c= :368 > > [] bus_add_driver+0x126/0x2a0 drivers/base/bus.c:= 673 > > [] driver_register+0x8a/0x190 drivers/base/driver= .c:246 > > [] usb_gadget_register_driver_owner+0x64/0x160 dr= ivers/usb/gadget/udc/core.c:1665 > > [] raw_ioctl_run drivers/usb/gadget/legacy/raw_ga= dget.c:546 [inline] > > [] raw_ioctl+0x6f6/0x1120 drivers/usb/gadget/lega= cy/raw_gadget.c:1253 > > [] vfs_ioctl fs/ioctl.c:51 [inline] > > [] __do_sys_ioctl fs/ioctl.c:870 [inline] > > [] __se_sys_ioctl fs/ioctl.c:856 [inline] > > [] __x64_sys_ioctl+0x103/0x140 fs/ioctl.c:856 > > [] do_syscall_x64 arch/x86/entry/common.c:50 [inl= ine] > > [] do_syscall_64+0x39/0xb0 arch/x86/entry/common.= c:80 > > > > #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.= git > master #syz test: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.gi= t master --- a/drivers/usb/gadget/legacy/raw_gadget.c +++ b/drivers/usb/gadget/legacy/raw_gadget.c @@ -310,13 +310,14 @@ static int gadget_bind(struct usb_gadget *gadget, dev->eps_num =3D i; spin_unlock_irqrestore(&dev->lock, flags); - /* Matches kref_put() in gadget_unbind(). */ - kref_get(&dev->count); - ret =3D raw_queue_event(dev, USB_RAW_EVENT_CONNECT, 0, NULL); - if (ret < 0) + if (ret < 0) { dev_err(&gadget->dev, "failed to queue event\n"); + return ret; + } + /* Matches kref_put() in gadget_unbind(). */ + kref_get(&dev->count); return ret; } > > diff --git a/drivers/usb/gadget/legacy/raw_gadget.c > b/drivers/usb/gadget/legacy/raw_gadget.c > index 2acece16b890..c00f93b630ad 100644 > --- a/drivers/usb/gadget/legacy/raw_gadget.c > +++ b/drivers/usb/gadget/legacy/raw_gadget.c > @@ -310,13 +310,12 @@ static int gadget_bind(struct usb_gadget *gadget, > dev->eps_num =3D i; > spin_unlock_irqrestore(&dev->lock, flags); > > - /* Matches kref_put() in gadget_unbind(). */ > - kref_get(&dev->count); > - > ret =3D raw_queue_event(dev, USB_RAW_EVENT_CONNECT, 0, NULL); > if (ret < 0) > dev_err(&gadget->dev, "failed to queue event\n"); > > + /* Matches kref_put() in gadget_unbind(). */ > + kref_get(&dev->count); > return ret; > } > > > > > > > > > --- > > 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. > > > > If the bug is already fixed, let syzbot know by replying with: > > #syz fix: exact-commit-title > > > > If you want syzbot to run the reproducer, reply with: > > #syz test: git://repo/address.git branch-or-commit-hash > > If you attach or paste a git patch, syzbot will apply it before testing= . > > > > If you want to change bug's subsystems, reply with: > > #syz set subsystems: new-subsystem > > (See the list of subsystem names on the web dashboard) > > > > If the bug is a duplicate of another bug, reply with: > > #syz dup: exact-subject-of-another-report > > > > If you want to undo deduplication, reply with: > > #syz undup