Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp3562444rwe; Sun, 16 Apr 2023 23:15:24 -0700 (PDT) X-Google-Smtp-Source: AKy350ba66MESNtJJoWjdxSvT2MyXQew9XSjupaUsjvekUVDLkTAmLmwjMI+gsAGG+O/1ccfY0Te X-Received: by 2002:a17:902:8487:b0:1a1:b11d:6af5 with SMTP id c7-20020a170902848700b001a1b11d6af5mr10409707plo.52.1681712124319; Sun, 16 Apr 2023 23:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681712124; cv=none; d=google.com; s=arc-20160816; b=gPDfk1b6G3X+k10KcExyH2DEeK7sKTvmh2EZEFu+BCk14GHQVxXKMZkTPYaf2QaB3/ Vr8QTgbk4niriUjMMkty+Y71SdYH7ODI3XZSIrcE848LuDQlZJXoz3YOqwDpmHowQo96 N3X9Xc0t83F7dYRscW7lPdUYgOInl1fvZ3hXLRa2BCfs9Duwl6rhXLw/+aAaVtIDv7ZO UqHiYy22PslmCC/ue3doAz6Tn8RcbWo/4YIToXDTnPHxmOgghbSQIc00GSgl5D4eupNn sPkbuU4keWpZ9KBEzgL4zHl/mMbbJLI1UIN9s3SNdH7lizzczsDfP4/eHay17RVh+g5s grFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:authenticated-by; bh=pZNQWe5GiinzXS/ycbeUBPaCgfnKRc/QtCNVdJhCPJc=; b=txsWRT00iq57pQT/4EJPHweB3eDfpZ2P9KEq5ETlUmwChBZaYdRSW/jDbZkRJ38mt7 oT4ZsY4b3IplK4WNzDHfhC+UU9/19AUHv0uaLFw4BORoXwrhKEVyFe+tuuho5+/Ug4/f MGvjgMKrwaNfW1Jv0H52CEeJVQMKFo1N0WUKnbQ7mD7S3Xh084ZHCO4Dk2rVzymiVxQh 8kXwlHmYSFBuyr4OrbsL+vX10qDt2LgjhkVOW1zmqAGloVnvhuxbagDTINlVfoJoB57c w+eyv9c45w9tjbZ18NpTUZXAZvcii1TpuT59VFkigU7E4l2BMoY2mqA613YiAGnBScbX AdeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b3-20020a170902d88300b0019f2cd99ddfsi10739722plz.380.2023.04.16.23.15.09; Sun, 16 Apr 2023 23:15:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-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; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjDQGIq convert rfc822-to-8bit (ORCPT + 63 others); Mon, 17 Apr 2023 02:08:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230070AbjDQGIo (ORCPT ); Mon, 17 Apr 2023 02:08:44 -0400 Received: from rtits2.realtek.com.tw (rtits2.realtek.com [211.75.126.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1842A1FE1 for ; Sun, 16 Apr 2023 23:08:42 -0700 (PDT) Authenticated-By: X-SpamFilter-By: ArmorX SpamTrap 5.77 with qID 33H67nz86001805, This message is accepted by code: ctloc85258 Received: from mail.realtek.com (rtexh36505.realtek.com.tw[172.21.6.25]) by rtits2.realtek.com.tw (8.15.2/2.81/5.90) with ESMTPS id 33H67nz86001805 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=OK); Mon, 17 Apr 2023 14:07:49 +0800 Received: from RTEXMBS01.realtek.com.tw (172.21.6.94) by RTEXH36505.realtek.com.tw (172.21.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.32; Mon, 17 Apr 2023 14:08:12 +0800 Received: from RTEXMBS04.realtek.com.tw (172.21.6.97) by RTEXMBS01.realtek.com.tw (172.21.6.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 17 Apr 2023 14:08:12 +0800 Received: from RTEXMBS04.realtek.com.tw ([fe80::e138:e7f1:4709:ff4d]) by RTEXMBS04.realtek.com.tw ([fe80::e138:e7f1:4709:ff4d%5]) with mapi id 15.01.2375.007; Mon, 17 Apr 2023 14:08:12 +0800 From: Ping-Ke Shih To: Larry Finger , Kalle Valo CC: Johannes Berg , "linux-wireless@vger.kernel.org" , "Sascha Hauer" Subject: RE: [PATCH] wifi: rtw88: Fix memory leak in rtw88_usb Thread-Topic: [PATCH] wifi: rtw88: Fix memory leak in rtw88_usb Thread-Index: AQHZbzesjaETNjjjhUGpyEIsOiNIha8vBpzw Date: Mon, 17 Apr 2023 06:08:12 +0000 Message-ID: <085f8fe9ec9749689e9f3fc51bfe1cce@realtek.com> References: <20230415011422.11162-1-Larry.Finger@lwfinger.net> In-Reply-To: <20230415011422.11162-1-Larry.Finger@lwfinger.net> Accept-Language: en-US, zh-TW Content-Language: zh-TW X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.21.69.188] x-kse-serverinfo: RTEXMBS01.realtek.com.tw, 9 x-kse-antispam-interceptor-info: fallback x-kse-antivirus-interceptor-info: fallback Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-ServerInfo: RTEXH36505.realtek.com.tw, 9 X-KSE-AntiSpam-Interceptor-Info: fallback X-KSE-Antivirus-Interceptor-Info: fallback X-KSE-AntiSpam-Interceptor-Info: fallback X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-wireless@vger.kernel.org > -----Original Message----- > From: Larry Finger On Behalf Of Larry Finger > Sent: Saturday, April 15, 2023 9:14 AM > To: Kalle Valo > Cc: Johannes Berg ; linux-wireless@vger.kernel.org; Larry Finger > ; Sascha Hauer ; Ping-Ke Shih > Subject: [PATCH] wifi: rtw88: Fix memory leak in rtw88_usb > > Kmemleak shows the following leak arising from routine in the usb > probe routine: > > unreferenced object 0xffff895cb29bba00 (size 512): > comm "(udev-worker)", pid 534, jiffies 4294903932 (age 102751.088s) > hex dump (first 32 bytes): > 77 30 30 30 00 00 00 00 02 2f 2d 2b 30 00 00 00 w000...../-+0... > 02 00 2a 28 00 00 00 00 ff 55 ff ff ff 00 00 00 ..*(.....U...... > backtrace: > [] kmalloc_trace+0x26/0x90 > [] rtw_usb_probe+0x2f1/0x680 [rtw_usb] > [] usb_probe_interface+0xdd/0x2e0 [usbcore] > [] really_probe+0x18e/0x3d0 > [] __driver_probe_device+0x78/0x160 > [] driver_probe_device+0x1f/0x90 > [] __driver_attach+0xbf/0x1b0 > [] bus_for_each_dev+0x70/0xc0 > [] bus_add_driver+0x10e/0x210 > [] driver_register+0x55/0xf0 > [] usb_register_driver+0x88/0x140 [usbcore] > [] do_one_initcall+0x43/0x210 > [] do_init_module+0x4a/0x200 > [] __do_sys_finit_module+0xac/0x120 > [] do_syscall_64+0x56/0x80 > [] entry_SYSCALL_64_after_hwframe+0x46/0xb0 > > The leak was verified to be real by unloading the driver, which resulted > in a dangling pointer to the allocation. > > The allocated memory is freed in rtw_usb_disconnect(). > > Signed-off-by: Larry Finger > Cc: Sascha Hauer > Cc: Ping-Ke Shih > --- > drivers/net/wireless/realtek/rtw88/usb.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/drivers/net/wireless/realtek/rtw88/usb.c b/drivers/net/wireless/realtek/rtw88/usb.c > index 68e1b782d199..d28493a8f16c 100644 > --- a/drivers/net/wireless/realtek/rtw88/usb.c > +++ b/drivers/net/wireless/realtek/rtw88/usb.c > @@ -882,6 +882,7 @@ void rtw_usb_disconnect(struct usb_interface *intf) > rtw_unregister_hw(rtwdev, hw); > rtw_usb_deinit_tx(rtwdev); > rtw_usb_deinit_rx(rtwdev); > + kfree(rtwusb->usb_data); I suggest to do this in rtw_usb_intf_deinit() instead, because rtwusb->usb_data is allocated by rtw_usb_intf_init(). Not only make the code symmetric also can handle error cases properly of rtw_usb_probe(). Ping-Ke