Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3733541pxb; Mon, 4 Oct 2021 08:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyJouNLGHgys6VmwGvHA75i9Xp7FYyxyKml6qL7M52CW08larOWL/SbzHVAn2kNyY/r1cmn X-Received: by 2002:a65:6aa8:: with SMTP id x8mr11315126pgu.136.1633361324961; Mon, 04 Oct 2021 08:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633361324; cv=none; d=google.com; s=arc-20160816; b=JGelm4ryQUEKdP9Z4F1gHPVFJaeg9y4URGnTOu9NH/1P2zhZ/8MJZvWmht8G7qioif 5fXdS0dM7FR91fLVk0OnE+IBkKgf/Dzs4AbfqrlNN2smPO6arMCmUrHQl7NTZ3mt72oD 3MNWhaLhGesr3dOjXSfaiweTxAyNT5WjIXB0Qt+UMKIuCle7baSD32yneQPajOo7FPAO RmGRvGGXK4t9mgrrC8mUO6P0t96PCyIO3hNEQtu8tiPmjnh+N8g8Hmu0+GD+9mqg+Zi/ /ksBWkuRKPHW0kKtWUSRXvL2CoB0L07vBqV4QqDAgFFGRDVc/1Bc5jZlkRcE+hu8MDb1 IF9Q== 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=IERYDT5feljIQ3JxthXEXcJk6qXhFmeLO4qDQ453VHo=; b=WFDeqoZb2DYG/QIk14pgJfoCQVQVFPWn8tFFSTgUXMwJJS+qe6ts7JyfJrfxkbhWf4 Llvu4h5ZG2VZdahZQtvcAJBuy4WuO2VDwBwanhoM82ulVbSuTDzwO8CiwKIsAeNGKA41 0xIWC9bJ2vC4oaSTVYHkpSU4gFyMPQbuZkajEBNo8DHEFMo8TqZqJUc44vTw7B9XDgQg wmEqm8qs0Q/d0xG9X/ojUR/jFtd8+O6p1T7DKdedHakcQ2+7PSiVD468Eaq5GUjcBMeG wFpFM3cORGxtMVOEp0exl/mMAt72w+aFbEsV+6W6y5MBL8j9c+Jnz5i1YHqnDKljErKX xFfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=ycEWZo4C; 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 mw5si25115259pjb.132.2021.10.04.08.28.20; Mon, 04 Oct 2021 08:28:44 -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=ycEWZo4C; 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 S235449AbhJDNPU (ORCPT + 99 others); Mon, 4 Oct 2021 09:15:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:46768 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236106AbhJDNNL (ORCPT ); Mon, 4 Oct 2021 09:13:11 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4B01F613AD; Mon, 4 Oct 2021 13:05:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352709; bh=37JB5mJq/88yxp7APQHDIJjZmrQ7C57EiZ4jhmsTl98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ycEWZo4C6bvZtMFk/tMvBz5bTGml69AcdbD+310jxMutBMEwoGUeFWtl4rWZ9R0yA gXfyxeYcwjllBVo88qqIHWUOKnoIqfl/qX6Y8vJgAQG9AAocwqgKbraqlKFGNDCfV7 VFllqjsK6TnmpuKl7JpNViHK81GOQv9K2JyCRK/E= 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" , Ovidiu Panait Subject: [PATCH 4.19 89/95] usb: hso: fix error handling code of hso_create_net_device Date: Mon, 4 Oct 2021 14:52:59 +0200 Message-Id: <20211004125036.486316319@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125033.572932188@linuxfoundation.org> References: <20211004125033.572932188@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 commit a6ecfb39ba9d7316057cea823b196b734f6b18ca upstream. 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: Ovidiu Panait Signed-off-by: Greg Kroah-Hartman --- drivers/net/usb/hso.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) --- a/drivers/net/usb/hso.c +++ b/drivers/net/usb/hso.c @@ -2511,7 +2511,7 @@ static struct hso_device *hso_create_net 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); @@ -2524,13 +2524,13 @@ static struct hso_device *hso_create_net 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); @@ -2539,18 +2539,18 @@ static struct hso_device *hso_create_net 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); @@ -2558,7 +2558,7 @@ static struct hso_device *hso_create_net 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); @@ -2566,8 +2566,21 @@ static struct hso_device *hso_create_net 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; }