Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3693207pxv; Mon, 26 Jul 2021 09:32:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxltnrcKHPrSYy07W1zvr8OZW+SpqMWtJGqAxIPAx/A2wVJO7rCfo5X+6ZGMlprVYq9vINE X-Received: by 2002:a5d:9ccb:: with SMTP id w11mr15504823iow.174.1627317125723; Mon, 26 Jul 2021 09:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627317125; cv=none; d=google.com; s=arc-20160816; b=YIQOk/LZ/78cmOkd7LAsSw8zaoCMQ8zo24+LLyQR0NCTBppM4Gd56uimxMO5a0TM7Q 0PjGOwTkN0TaC51MLcFAtXIucj1JTlay3f4cM3PkelgF21T7sLI7AaatTZYtLGM4/L1b pnNpe+w6cgIeW5eoFyDcUJvRfZ8Fowu4P7o84nGzcOrs9DO2iZ3bEa0PdhIJ8XIpN2Ok w8y1MvDRR/OSt2NR/cHzkj3zFAF6wBP+wskn+uGVDpzI7k8h/fqKNt7N6zONA3JF7Eio Vwbn/m+ukw9IySojG7X/Ragdeph6AD2rn2DZCWdY79OQXq3rpAx+0TKhdlw7JtGkKvSd loNQ== 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=4ytDLv7X6D/A08+TLYaAYY2r1obcVcoAUiCIMVcCl7I=; b=EUI81lF3PZBdUqmLjH5pjCdSJJQA2F9oFHZSTqsserLsgr3RnN8S5+z151jhnxPiOO oY92AlM9CFsXP3SAAtxTeAN+9ctiC+narKXBbo7mHfl9X7wAB7b+hnomtCwe1Lxnw/dQ RjTxlhXm/WFkIukggIsA3cGSlJnYKMLoJ+4S/Ma8YXNxY08fNom9z9TqpiJxTun5r3lc GepE7/gOPb1B6+ahtZa/OAFP8X1wUjOlxImIBG6Jy2Lf388GnQ8yyjbyPJY8ljn7bQaM yV1r5xSA2hnfCqsG2xugd/MCGTE6bnCWXXrHDkRlfktoCQcmK3s2x/7MkkQ6nkkrYTkp uaeQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Fpx/5qVW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i42si343808jav.32.2021.07.26.09.31.53; Mon, 26 Jul 2021 09:32:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="Fpx/5qVW"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239075AbhGZPtL (ORCPT + 99 others); Mon, 26 Jul 2021 11:49:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:45538 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231811AbhGZPaO (ORCPT ); Mon, 26 Jul 2021 11:30:14 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C1C8A60C40; Mon, 26 Jul 2021 16:10:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1627315842; bh=C55M08hb4T9Y5JA+6f8NydJG2ZAk9SusCZMs5oiRpnU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fpx/5qVWEL4Q+zPF8KqTJObVx4I7xHQdsdkQfw7xzStyz0B0PioEeRbiy1pkcT6lB SkausMnRPJbeEdHdB01VSitiQHPU9CgcgCUH1mMGdP/W1y+MTFbPz2PgekrT9omHwL aYNTiSQ6VY51d0gcQoy6LfT2BpH7KIGNXDjwmNAk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com, Dongliang Mu , "David S. Miller" , Sasha Levin Subject: [PATCH 5.13 088/223] usb: hso: fix error handling code of hso_create_net_device Date: Mon, 26 Jul 2021 17:38:00 +0200 Message-Id: <20210726153849.125351945@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210726153846.245305071@linuxfoundation.org> References: <20210726153846.245305071@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit a6ecfb39ba9d7316057cea823b196b734f6b18ca ] The current error handling code of hso_create_net_device is hso_free_net_device, no matter which errors lead to. For example, WARNING in hso_free_net_device [1]. Fix this by refactoring the error handling code of hso_create_net_device by handling different errors by different code. [1] https://syzkaller.appspot.com/bug?id=66eff8d49af1b28370ad342787413e35bbe76efe Reported-by: syzbot+44d53c7255bb1aea22d2@syzkaller.appspotmail.com Fixes: 5fcfb6d0bfcd ("hso: fix bailout in error case of probe") Signed-off-by: Dongliang Mu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/hso.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c index 5c779cc0ea11..28ebf4955b83 100644 --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2496,7 +2496,7 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, hso_net_init); if (!net) { dev_err(&interface->dev, "Unable to create ethernet device\n"); - goto exit; + goto err_hso_dev; } hso_net = netdev_priv(net); @@ -2509,13 +2509,13 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, USB_DIR_IN); if (!hso_net->in_endp) { dev_err(&interface->dev, "Can't find BULK IN endpoint\n"); - goto exit; + goto err_net; } hso_net->out_endp = hso_get_ep(interface, USB_ENDPOINT_XFER_BULK, USB_DIR_OUT); if (!hso_net->out_endp) { dev_err(&interface->dev, "Can't find BULK OUT endpoint\n"); - goto exit; + goto err_net; } SET_NETDEV_DEV(net, &interface->dev); SET_NETDEV_DEVTYPE(net, &hso_type); @@ -2524,18 +2524,18 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { hso_net->mux_bulk_rx_urb_pool[i] = usb_alloc_urb(0, GFP_KERNEL); if (!hso_net->mux_bulk_rx_urb_pool[i]) - goto exit; + goto err_mux_bulk_rx; hso_net->mux_bulk_rx_buf_pool[i] = kzalloc(MUX_BULK_RX_BUF_SIZE, GFP_KERNEL); if (!hso_net->mux_bulk_rx_buf_pool[i]) - goto exit; + goto err_mux_bulk_rx; } hso_net->mux_bulk_tx_urb = usb_alloc_urb(0, GFP_KERNEL); if (!hso_net->mux_bulk_tx_urb) - goto exit; + goto err_mux_bulk_rx; hso_net->mux_bulk_tx_buf = kzalloc(MUX_BULK_TX_BUF_SIZE, GFP_KERNEL); if (!hso_net->mux_bulk_tx_buf) - goto exit; + goto err_free_tx_urb; add_net_device(hso_dev); @@ -2543,7 +2543,7 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, result = register_netdev(net); if (result) { dev_err(&interface->dev, "Failed to register device\n"); - goto exit; + goto err_free_tx_buf; } hso_log_port(hso_dev); @@ -2551,8 +2551,21 @@ static struct hso_device *hso_create_net_device(struct usb_interface *interface, hso_create_rfkill(hso_dev, interface); return hso_dev; -exit: - hso_free_net_device(hso_dev, true); + +err_free_tx_buf: + remove_net_device(hso_dev); + kfree(hso_net->mux_bulk_tx_buf); +err_free_tx_urb: + usb_free_urb(hso_net->mux_bulk_tx_urb); +err_mux_bulk_rx: + for (i = 0; i < MUX_BULK_RX_BUF_COUNT; i++) { + usb_free_urb(hso_net->mux_bulk_rx_urb_pool[i]); + kfree(hso_net->mux_bulk_rx_buf_pool[i]); + } +err_net: + free_netdev(net); +err_hso_dev: + kfree(hso_dev); return NULL; } -- 2.30.2