From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA4A3C4332F for ; Mon, 14 Feb 2022 14:41:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237294AbiBNOlm (ORCPT ); Mon, 14 Feb 2022 09:41:42 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:47696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231236AbiBNOll (ORCPT ); Mon, 14 Feb 2022 09:41:41 -0500 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 9AD3649277 for ; Mon, 14 Feb 2022 06:41:33 -0800 (PST) Received: (qmail 717174 invoked by uid 1000); 14 Feb 2022 09:41:32 -0500 Date: Mon, 14 Feb 2022 09:41:32 -0500 From: Alan Stern To: Dongliang Mu , Salah Triki Cc: benjamin.tissoires@redhat.com, jikos@kernel.org, linux-input@vger.kernel.org, linux-usb@vger.kernel.org, noralf@tronnes.org, syzkaller-bugs , tzimmermann@suse.de Subject: Re: [PATCH] HID: elo: Fix refcount leak in elo_probe() Message-ID: References: <000000000000d31cac05d7c4da7e@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org On Mon, Feb 14, 2022 at 03:34:42PM +0800, Dongliang Mu wrote: > On Sat, Feb 12, 2022 at 9:50 AM Alan Stern wrote: > > > > Syzbot identified a refcount leak in the hid-elo driver: > > > > BUG: memory leak > > unreferenced object 0xffff88810d49e800 (size 2048): > > comm "kworker/1:1", pid 25, jiffies 4294954629 (age 16.460s) > > hex dump (first 32 bytes): > > ff ff ff ff 31 00 00 00 00 00 00 00 00 00 00 00 ....1........... > > 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 ................ > > backtrace: > > [] kmalloc include/linux/slab.h:581 [inline] > > [] kzalloc include/linux/slab.h:715 [inline] > > [] usb_alloc_dev+0x32/0x450 drivers/usb/core/usb.c:582 > > [] hub_port_connect drivers/usb/core/hub.c:5260 [inline] > > [] hub_port_connect_change drivers/usb/core/hub.c:5502 [inline] > > [] port_event drivers/usb/core/hub.c:5660 [inline] > > [] hub_event+0x1097/0x21a0 drivers/usb/core/hub.c:5742 > > [] process_one_work+0x2bf/0x600 kernel/workqueue.c:2307 > > [] worker_thread+0x59/0x5b0 kernel/workqueue.c:2454 > > [] kthread+0x125/0x160 kernel/kthread.c:377 > > [] ret_from_fork+0x1f/0x30 arch/x86/entry/entry_64.S:295 > > > > Not shown in the bug report but present in the console log: > > > > [ 182.014764][ T3257] elo 0003:04E7:0030.0006: item fetching failed at offset 0/1 > > [ 182.022255][ T3257] elo 0003:04E7:0030.0006: parse failed > > [ 182.027904][ T3257] elo: probe of 0003:04E7:0030.0006 failed with error -22 > > [ 182.214767][ T3257] usb 1-1: USB disconnect, device number 7 > > [ 188.090199][ T3604] kmemleak: 3 new suspected memory leaks (see /sys/kernel/debug/kmemleak) > > BUG: memory leak > > > > which points to hid-elo as the buggy driver. > > > > The leak is caused by elo_probe() failing to release the reference it > > holds to the struct usb_device in its failure pathway. In the end the > > driver doesn't need to take this reference at all, because the > > Hi Alan, > > My patch "[PATCH] hid: elo: fix memory leak in elo_probe" is merged > several weeks ago. Really? It still isn't in Linus's tree as of 5.17-rc4. I would expect a bug fix to go upstream as soon as possible. > However, I fix this bug by modifying the error handling code in > elo_probe. If you think the refcount is not necessary, maybe a new > patch to remove the refcount is better. The refcount was added less than a year ago by Salah Triki in commit fbf42729d0e9 ("HID: elo: update the reference count of the usb device structure"), but the commit message doesn't explain why it is necessary. There certainly isn't any obvious reason for it; the driver doesn't release any references after elo_remove() returns and we know that the usb_device structure won't be deallocated before the driver gets unbound. Alan Stern