Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp2104756rwp; Fri, 14 Jul 2023 00:20:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlHwzOR6NYFSli9ydWeqsWRovxBB9xoBuXqa0WkKLn0Vr26BOHil39COwuiTLRmr2CCK+ApP X-Received: by 2002:a17:90a:bc83:b0:263:f4cc:a988 with SMTP id x3-20020a17090abc8300b00263f4cca988mr2555004pjr.5.1689319225043; Fri, 14 Jul 2023 00:20:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689319225; cv=none; d=google.com; s=arc-20160816; b=S4UEpX/x7vW70wY7uOGn5t5ws4ny+BOlsm4HfVzhaxkoC9twfBF4bSh+K6P8Ct46kD KTR8uHTgU8RQshO/cVo0PDgxGSiAjRnuFzVUOb8GnT+/7i8ubyKeMJcmFVLJOyxGmMpM xppD4Xa29itTQ5jVvr4U3tzoO/n4s5QQ5WRUVCI/R9pQHwwzzz4y35VZnbHdj9kOAsPV tummExIGY5VKsBqLiauycHqiQj8iZ32MKn4IF+Z6p4kU3byBT7EAO8wtQjcrc7qcOiD4 JjV60QRBzbWWLsWnaWnGY3sKE/2LCiQDpCgNFrKBcWp6nwPvFNvEPzTgWJ9DN7Y8mkZt KEPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=/tGvLNLCyMOtWr+ysz5thUq15EAXHgxFHlXO6MNNxEY=; fh=qIMrpZrY5xHHiykPTU/zR1JJB4lbzuu/WznLpHkGKG8=; b=n+ZfYj03KpD2K4PE/36RQYg0TQ6hLKTXPFDn9pJTfIoXQeh0u4KfkVGqb7A9XKi8ZL xCfuqsCBsxrBnOzYptutsuf/FlsDguJDH93eINVadq2EGoNAehx5pSo+8tuD9Hfnmgog W4JU72iZS5t/9iiUT9fwcxsxwgCpduaog6DCOwhKebL6XrDx3v46r0v/PLmvFta9pamk d3ANIndSNL2HXs+Q0EulsN9/zpK2MQGFeJXyB1s6nPenjfXpGUvpUu9hn8c2aZLSJQuz 46NYh6C7uh/Izpx7dyJZXMQy/J2PHB1fnw1i8orWy0LMkKzT7Lw1OXyhxrYh7S8djPGr h3ig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=XfzKYJbL; 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 cq19-20020a17090af99300b002563c39f342si801194pjb.110.2023.07.14.00.20.13; Fri, 14 Jul 2023 00:20:25 -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=XfzKYJbL; 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 S235251AbjGNHML (ORCPT + 99 others); Fri, 14 Jul 2023 03:12:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235238AbjGNHMG (ORCPT ); Fri, 14 Jul 2023 03:12:06 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C10C730EB; Fri, 14 Jul 2023 00:12:02 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id 98e67ed59e1d1-263374f2f17so785557a91.0; Fri, 14 Jul 2023 00:12:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689318722; x=1691910722; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/tGvLNLCyMOtWr+ysz5thUq15EAXHgxFHlXO6MNNxEY=; b=XfzKYJbLTg4H8KKy8LXYC9oBCTS0ylC6t3amOQ0tOc7Bg7NsnB4jtdkYWRvSHNHZTQ 4ZHR85XjbTF9t99ZvMbsZmRJFtlVrXcIAvohE/H1L3H2/WD/cLSiPM+1/q7DCrcZczBN pwtX4TS5eD5hFRM2OqzCVGpFGZzligekZXgQbW+e1F/fNsGaACyErirAhMJr8FpPqkon oJC1oowEgUAwrII7DE/21vrlJv5pQFON3tHW/tU+EsQnBZ/NcGUIQRinj0qM9VU6N+BK Q7CVjXRwb6y6R5RdMnPYKv0ofvQa3oBKFMOMoTiF3W5lZZnR6jCzJ54h8dmom7uVQcYM uyzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689318722; x=1691910722; h=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=/tGvLNLCyMOtWr+ysz5thUq15EAXHgxFHlXO6MNNxEY=; b=Cz/Sy/+xLb9ixJtWvT1mjxEeCvoPJzdNJuNgGBrObshJQZXqoyDjus0nEL4px+yrw6 ATif7tAv3cehDiVy9Q/vuID7mTnc1QdTA1fonasJYJZUxOLVdFjXaZRB5cpGsM4iq9am CsxHitOUPQNGYai+CC4ZgsIy/iKEnTbuzxuhksIRVuR+O45ZMotGEkusg52p5tipRwMs 4oVSuFWI/crzSEOMGqDy0qlqyOAldXkcEXaviDugFzqzL7bAv78jxarhfWWP81NkLcxe PtjUIJymBEy8RYVZUawEqMra3KKSgv1Eu/xv0VzeVef2bpdETrgGJvQoLsFJagSbQPqQ TPXQ== X-Gm-Message-State: ABy/qLYeD32r+0Q8HDIsfLsXVX3RduV09zADb7nJo5F16LVMuixDiFcz ir4oYGViTzB1Q+zzGjcWtE121f+bYclzxYkkAx/vrRRcw8A= X-Received: by 2002:a17:90b:11c2:b0:263:2335:5946 with SMTP id gv2-20020a17090b11c200b0026323355946mr2325746pjb.40.1689318721886; Fri, 14 Jul 2023 00:12:01 -0700 (PDT) MIME-Version: 1.0 References: <0000000000009db51a06005b64e9@google.com> In-Reply-To: <0000000000009db51a06005b64e9@google.com> From: Z qiang Date: Fri, 14 Jul 2023 15:11:50 +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" 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_NONE,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 > > Hello, > > syzbot found the following issue on: > > HEAD commit: 1c7873e33645 mm: lock newly mapped VMA with corrected orde.. > git tree: upstream > console output: https://syzkaller.appspot.com/x/log.txt?x=1517663ca80000 > kernel config: https://syzkaller.appspot.com/x/.config?x=832b404e095b70c0 > dashboard link: https://syzkaller.appspot.com/bug?extid=feb045d335c1fdde5bf7 > compiler: gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2 > syz repro: https://syzkaller.appspot.com/x/repro.syz?x=1776519ca80000 > C reproducer: https://syzkaller.appspot.com/x/repro.c?x=117f9778a80000 > > Downloadable assets: > disk image: https://storage.googleapis.com/syzbot-assets/43b42bd2cf70/disk-1c7873e3.raw.xz > vmlinux: https://storage.googleapis.com/syzbot-assets/011ba1b9e8c1/vmlinux-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 commit: > 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 [inline] > [] 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/legacy/raw_gadget.c:460 > [] raw_ioctl+0x5f9/0x1120 drivers/usb/gadget/legacy/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 [inline] > [] 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/legacy/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 [inline] > [] 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/legacy/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 [inline] > [] 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/gadget/udc/dummy_hcd.c:665 > [] usb_ep_alloc_request+0x22/0xd0 drivers/usb/gadget/udc/core.c:196 > [] gadget_bind+0x6d/0x370 drivers/usb/gadget/legacy/raw_gadget.c:292 > [] gadget_bind_driver+0xe3/0x2e0 drivers/usb/gadget/udc/core.c:1591 > [] call_driver_probe drivers/base/dd.c:579 [inline] > [] 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:1154 > [] 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 drivers/usb/gadget/udc/core.c:1665 > [] raw_ioctl_run drivers/usb/gadget/legacy/raw_gadget.c:546 [inline] > [] raw_ioctl+0x6f6/0x1120 drivers/usb/gadget/legacy/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 [inline] > [] 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 --- a/drivers/usb/gadget/legacy/raw_gadget.c +++ b/drivers/usb/gadget/legacy/raw_gadget.c @@ -310,12 +310,15 @@ static int gadget_bind(struct usb_gadget *gadget, dev->eps_num = i; spin_unlock_irqrestore(&dev->lock, flags); - /* Matches kref_put() in gadget_unbind(). */ - kref_get(&dev->count); - ret = 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"); + set_gadget_data(gadget, NULL); + return ret; + } + + /* Matches kref_put() in gadget_unbind(). */ + kref_get(&dev->count); return ret; }