From patchwork Mon Oct 24 11:28:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp433960wru; Mon, 24 Oct 2022 05:51:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4P0Eqtza0365M3ALUJpT9/TQ0Jjk/qegzWT0C4whmdC+KFywX7i34BtFZFtLe80nLTMw64 X-Received: by 2002:a17:906:5a5b:b0:7a6:cbc7:4ca1 with SMTP id my27-20020a1709065a5b00b007a6cbc74ca1mr5365075ejc.544.1666615860340; Mon, 24 Oct 2022 05:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615860; cv=none; d=google.com; s=arc-20160816; b=jf8oC69OK0er2589exbqdKxCU2+jQI7NQI2yeUxgt/Q51LDddNdBFAma8D4BIKPXzN OzD0XaqG8TH5MO2PsWoob1oIBde0/Twv5BfyLbDeJktDexH1ymc/NRc3c81X9E3txlY4 5OzQekwuVfJf9941hzObfOW47gCg+hBfTIDo0eZL/HjyfnGI2daace2QpeBfhT3qpCxJ Z2LHMGfRkJzDL9SD/2gFPwhQYOPaty5C0ahf/LS4Bz30Cb8h1lMJ7755ymNTb9RaxKPm ZpVuUEVgzvh8+EpqVtqblag5F5/chBm9b+XbCV9bCDmRtsyANa/UjUW4Ka/dAus18Kym nLlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3vFOkGmUbFh+wjE2aJMnui6YA0VnbtpNliiUQjIAS+0=; b=VmTu+hWFU09Bra4K+EweNRake7//RxFNAk4sSSF/EC+9fAHd87iQg3Xi76ccx4ETXn xevtSpCh4chJnhGz5JJ6x2u0OI6igeY7ev4gWCA3dI7a3IMVWfeLmO8VFa0HigRuGljh nsgfYAsTGjdVop8WPfKGeU/Aev3vNw5RtuBveUrwtnPcpCWuJ1euLGGKkYNJJyZVRaz3 dSYb9DIKS/H7s1THSYNT/6Y+WQvtNOKXHJ1mXgVKv039dHBBeCFwfkkiYq6bnpwcpGaK 413xAdUq7lVTmIfcWJfqKZvvfKnXyZDp7zHkgPj+PwqlmfXecuW5VDc3njpqastLrX5I ptPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fo5yRuJZ; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hd15-20020a170907968f00b007a7d37e4681si3281007ejc.845.2022.10.24.05.50.33; Mon, 24 Oct 2022 05:51:00 -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=@linuxfoundation.org header.s=korg header.b=Fo5yRuJZ; 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=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234791AbiJXMt2 (ORCPT + 99 others); Mon, 24 Oct 2022 08:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234462AbiJXMox (ORCPT ); Mon, 24 Oct 2022 08:44:53 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EA848D0F8; Mon, 24 Oct 2022 05:09:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3489D612B7; Mon, 24 Oct 2022 11:45:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4994AC433C1; Mon, 24 Oct 2022 11:45:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611951; bh=Pn7N0lDbqubT2jqOC+Riwc4YjEZ/kjT5mCm8lUm7QKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fo5yRuJZHWAGbrfDmRTtu7chlxQx86upJ4bfEt0YIvvZNnSZ6Ft07R5U5Yv9fcU15 CllOm85aTVxSskXPyCfYCsy5BIb5Qsz4AMuAfqp+rXbd5m4KcXmPXAa2Q4vHsW8l2A OKqCRog0ukusQFUoCrtaUeTT1WpLOexx1pJCjk1w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peilin Ye , Jakub Kicinski , Sasha Levin , syzbot+dcd3e13cf4472f2e0ba1@syzkaller.appspotmail.com Subject: [PATCH 4.14 014/210] usbnet: Fix memory leak in usbnet_disconnect() Date: Mon, 24 Oct 2022 13:28:51 +0200 Message-Id: <20221024112957.386708469@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747573392624795350?= X-GMAIL-MSGID: =?utf-8?q?1747573392624795350?= From: Peilin Ye [ Upstream commit a43206156263fbaf1f2b7f96257441f331e91bb7 ] Currently usbnet_disconnect() unanchors and frees all deferred URBs using usb_scuttle_anchored_urbs(), which does not free urb->context, causing a memory leak as reported by syzbot. Use a usb_get_from_anchor() while loop instead, similar to what we did in commit 19cfe912c37b ("Bluetooth: btusb: Fix memory leak in play_deferred"). Also free urb->sg. Reported-and-tested-by: syzbot+dcd3e13cf4472f2e0ba1@syzkaller.appspotmail.com Fixes: 69ee472f2706 ("usbnet & cdc-ether: Autosuspend for online devices") Fixes: 638c5115a794 ("USBNET: support DMA SG") Signed-off-by: Peilin Ye Link: https://lore.kernel.org/r/20220923042551.2745-1-yepeilin.cs@gmail.com Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/usb/usbnet.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/net/usb/usbnet.c b/drivers/net/usb/usbnet.c index 69be3593bc0e..71b026277b30 100644 --- a/drivers/net/usb/usbnet.c +++ b/drivers/net/usb/usbnet.c @@ -1598,6 +1598,7 @@ void usbnet_disconnect (struct usb_interface *intf) struct usbnet *dev; struct usb_device *xdev; struct net_device *net; + struct urb *urb; dev = usb_get_intfdata(intf); usb_set_intfdata(intf, NULL); @@ -1614,7 +1615,11 @@ void usbnet_disconnect (struct usb_interface *intf) net = dev->net; unregister_netdev (net); - usb_scuttle_anchored_urbs(&dev->deferred); + while ((urb = usb_get_from_anchor(&dev->deferred))) { + dev_kfree_skb(urb->context); + kfree(urb->sg); + usb_free_urb(urb); + } if (dev->driver_info->unbind) dev->driver_info->unbind (dev, intf);