Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp3922872pxb; Mon, 4 Oct 2021 12:44:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn52mS013s9TR+LkJlxjSrjkjYvv3Dx7nwkHWMZQiub3UuLRVsd8yb7W17RSU+T7e+UcLA X-Received: by 2002:a17:906:5855:: with SMTP id h21mr18924880ejs.230.1633376650355; Mon, 04 Oct 2021 12:44:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633376650; cv=none; d=google.com; s=arc-20160816; b=t6ahvj1XLQTiwaU63mtxX4ilRTKRjzoWqkYebbEfYAGpFqoXHEB2twQyD12hkTArWe z9ngaxP3VgvD4tC9HPltBVe0J+zwf9vkGcKkZ606a0qiHb1APFxFFFUlmff28tHxa+6N hzMKR/Pks9CdvWHRwnm/VXfMnmpYONBmhbTXNvF4iTHD9n/tgHYwDOslP2WThIj0qagO QXvoweeVTpEFOMdAx0wxfoaNRD8NXrhJPnScpPFgPxwiC6ckDu0F/tDDdNgpc6yrU3vu P9qpYmdmaQO2g6aWX0UjUQHWAAB25IGhur2Wxs1LFBjQ4SgMNxMheWsv/kz467vTlP7G /ciQ== 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=pguFO8qA6dMBuYoTBeMYsF6fi82MhN7zqNnbNmI27f4=; b=V941fR7G5qkCVwTLUJAT/e00k/8w96A9muvN6o3Zr8DtK9MSrueI4ttRTuTsAKyLET zgIF55HAAZtcTE4lHo7qSy0R9ei+JuJC4q/anpg7oFZm//nByWXHZbXvsF9GDnc0bDnN +amLJ9O3aEgItiZrxg1VOYzIkE8nVcIh4JEWKr/gJqSyd6EHaDYRxPm+hBSXyKNZ6hIb hgc385UgK4a7GbF63uapFWXDTwFyCcz3lldKYC4N4rI1PM+oflbICuXyJh+2eeyOsskg LqO1SAOPUOw2ceNY5iQGeDcOG5CqdtUPGHSzGtDSZjPLLDdNmE4zVjQg77x9PatETgnD cKjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0WzgAexr; 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 ca9si1395581ejb.681.2021.10.04.12.43.46; Mon, 04 Oct 2021 12:44:10 -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=0WzgAexr; 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 S235163AbhJDNHq (ORCPT + 99 others); Mon, 4 Oct 2021 09:07:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:39512 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235192AbhJDNFs (ORCPT ); Mon, 4 Oct 2021 09:05:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B593D61528; Mon, 4 Oct 2021 13:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1633352458; bh=aFPEiudTYDgimi1dqfBtkcSyKA4h3eJiLwQ8jRuSAF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0WzgAexremSSX2EY9/PZ/M71N62iBCNg/epocVaXCDkxor2yLlNlHCfkxyYIeYlnt Rsyg38NLG8F3JsmNorW4mYiYZ48cI8JJh9O+Ikkw2Wjp0Rcjwvm3cxUF6xjVAc/JKl bDHng/NgIv2T3u1ycIDH/tiagIinQEtcZfQGl4VI= 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.14 69/75] usb: hso: fix error handling code of hso_create_net_device Date: Mon, 4 Oct 2021 14:52:44 +0200 Message-Id: <20211004125033.857394443@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004125031.530773667@linuxfoundation.org> References: <20211004125031.530773667@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 @@ -2510,7 +2510,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); @@ -2523,13 +2523,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); @@ -2538,18 +2538,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); @@ -2557,7 +2557,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); @@ -2565,8 +2565,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; }