Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp3777490pxv; Mon, 28 Jun 2021 12:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJybYJA/5Dv0+CkKKxWNznpgT22uLByCgFQZd7fdf8MdAHW/tv5b9cY1lgXfAh+SxsZFaUpM X-Received: by 2002:a5d:83ce:: with SMTP id u14mr841722ior.45.1624908995160; Mon, 28 Jun 2021 12:36:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624908995; cv=none; d=google.com; s=arc-20160816; b=DXIw1vcrFwmeEneQsidHld9wzNyPXUz0iWf4LavKkGZSavCMvA66ve3i5XZOK079/V p1qJY0BtCzbjZ+iTSLmLTpqxXlsAGSVYYhTj7+iEfNciRsPP5M5+e4iK7GDBbd1ITzAl /uBCdx3IVGa10yPJXdvuBAAfC5T8AhWeACjT2UYqk/+PJ0WcpxPyxji90Jd5wgPi4yfs VyWTcgwFkDuD8CZcSSvDAqRDH2CgXSRpj89OPRUnZBaawph7wICWMYI9RZ40kkqT36NT h9gueQssK1LknVeDWmTnKImzwLopIHWjCYFipPn+/EOsTacqkAoU830Ip+0aoq5+hrkj aPLQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cr7UQW1iGqnO3Pp5cAbFSNVitXjQK/RpEbG9g7tC85s=; b=IBl6R7LXO8E9ZAW5WHT+F8oad5k2bn/NssyyhLfvvmf487GWMOwdKWVtM5Bet26BGn UXfC7eNmK36TYBHpu86FnT4/q3kBurnokBExtlTIpmSFPEG13V/wbuccUkfI2Dxqoi52 /0YzEdBMKrbYQbQS9DA09G6xHleljiQEcklZ948LI8xEKfkJLXONgc/n8ayXUj3Qh9U0 Cz3cBhIL9BC4BrMkcQGtc84X+bhGplG6y2d+kzcWrmwUFAViJrP/c9bfqCFwel3/rU9E gRR1DqRikIgD/7JD5NoRXnDpZKHaCctqHUJ9jfFxfc9Mj70tVO/s0P9OdwNH2Uu/sf40 U2bQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BxjC0AO6; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w125si17384475jaa.80.2021.06.28.12.36.23; Mon, 28 Jun 2021 12:36:35 -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=@kernel.org header.s=k20201202 header.b=BxjC0AO6; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234162AbhF1O6F (ORCPT + 99 others); Mon, 28 Jun 2021 10:58:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:51478 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234979AbhF1Onm (ORCPT ); Mon, 28 Jun 2021 10:43:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4A48261CEC; Mon, 28 Jun 2021 14:33:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1624890827; bh=tw3njbl5kYSuuAEPN4CkEILmi76E+5XQNw5vC1dpNVk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BxjC0AO6l5KOYLAXKS+k9Iuhex6TzR3/M2VD+qe+50GbVea3n/hSlm1EYV+NFBq89 peHFB3biSzHRfLv6XU6iP1yaOv4Wbk5yufn+mS8nCIvo0JJkjYcK/y0sOuqK0LJLxR C3QxLkvTQ1BF8wby/ED0mp8l5FHhyOQBjCedAmnSW2l1SV4WLwEFtQjUJwVN0+0y4D 8CLDzR/GiOTbbLCjUeGSQLzD2NNeTlSApEZWcjb8YlwTJuOZog/E3gkSd8wR/zar2d WJqdJsKmfu2aDiDJvWlVUCOSGMZQoHvIEM+7DJ+mUzUxL6h99WXZXRlV0WJKmr/st8 M9dxYEmn4r9HA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongliang Mu , "David S . Miller" , Sasha Levin Subject: [PATCH 4.19 045/109] net: usb: fix possible use-after-free in smsc75xx_bind Date: Mon, 28 Jun 2021 10:32:01 -0400 Message-Id: <20210628143305.32978-46-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210628143305.32978-1-sashal@kernel.org> References: <20210628143305.32978-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v4.x/stable-review/patch-4.19.196-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-4.19.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 4.19.196-rc1 X-KernelTest-Deadline: 2021-06-30T14:32+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongliang Mu [ Upstream commit 56b786d86694e079d8aad9b314e015cd4ac02a3d ] The commit 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") fails to clean up the work scheduled in smsc75xx_reset-> smsc75xx_set_multicast, which leads to use-after-free if the work is scheduled to start after the deallocation. In addition, this patch also removes a dangling pointer - dev->data[0]. This patch calls cancel_work_sync to cancel the scheduled work and set the dangling pointer to NULL. Fixes: 46a8b29c6306 ("net: usb: fix memory leak in smsc75xx_bind") Signed-off-by: Dongliang Mu Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- drivers/net/usb/smsc75xx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/net/usb/smsc75xx.c b/drivers/net/usb/smsc75xx.c index 62f2862c9775..8b9fd4e071f3 100644 --- a/drivers/net/usb/smsc75xx.c +++ b/drivers/net/usb/smsc75xx.c @@ -1495,7 +1495,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_wait_ready(dev, 0); if (ret < 0) { netdev_warn(dev->net, "device not ready in smsc75xx_bind\n"); - goto err; + goto free_pdata; } smsc75xx_init_mac_address(dev); @@ -1504,7 +1504,7 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) ret = smsc75xx_reset(dev); if (ret < 0) { netdev_warn(dev->net, "smsc75xx_reset error %d\n", ret); - goto err; + goto cancel_work; } dev->net->netdev_ops = &smsc75xx_netdev_ops; @@ -1515,8 +1515,11 @@ static int smsc75xx_bind(struct usbnet *dev, struct usb_interface *intf) dev->net->max_mtu = MAX_SINGLE_PACKET_SIZE; return 0; -err: +cancel_work: + cancel_work_sync(&pdata->set_multicast); +free_pdata: kfree(pdata); + dev->data[0] = 0; return ret; } @@ -1527,7 +1530,6 @@ static void smsc75xx_unbind(struct usbnet *dev, struct usb_interface *intf) cancel_work_sync(&pdata->set_multicast); netif_dbg(dev, ifdown, dev->net, "free pdata\n"); kfree(pdata); - pdata = NULL; dev->data[0] = 0; } } -- 2.30.2